WMI 脚本 Windows 8 错误
WMI Scripting Windows 8 error
我在装有 Windows 8 Home Edition 的机器上遇到 WMI 问题。我需要按进程捕获 CPU 用法和 ProcessID。我试过很多方法:
- ShellExecute 在 Delphi
- 带有代码
的*.bat
- 一个*.vbs
- *.bat 执行的 *.vbs
- A*.ps1
- A *.ps1 由 *.bat
执行
(也许有些方法真的很蠢,但我还是试过了)
在 User-Click 中它完美地工作,但通过独立的应用程序它不起作用。
我已经在某些文件夹的 WMIMGMT.msi 上打开了 Security 并且执行策略(在 PowerShell 中)现在是 UNRESTRICTED。
这是 *.ps1 文件中的代码:
$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | Out-Null
$ErrorActionPreference = "Continue"
$perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
foreach ($p in $peflist) {
"" + $p.IDProcess + ";" + $p.PercentProcessTime
}
这是*.bat上的代码
powershell -ExcetutionPolicy Unrestricted -File "C:\Somefolder\PP.ps1" > C:\SomeFolder\output.txt
我得到的只是这个输出:
get-wmiobject : Invalid query "select * from Win32_Win32_PerfFormattedData_PerfProc_Process"
In C:\Somefolder\PP.ps1:4 character: 14
+ $perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErroID : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Edit1: 按要求复制的代码:
*.ps1:
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
$perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
foreach ($p in $perflist) {
"" + $p.IDProcess + ";" + $p.PercentProcessorTime
}
*.bat
powershell -executionPolicy unrestricted -file "C:\MonitorPerformance\test.ps1" > C:\MonitorPerformance\output1.txt
输出:(Consulta inválida = 无效查询;No = in;caractere = character)
get-wmiobject : Consulta inv lida "select * from Win32_PerfFormattedData_PerfProc_Process"
No C:\MonitorPerformance\test.ps1:4 caractere:14
+ $perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
替换为:
$perflist = (get-wmiobject Win32_Win32_PerfFormattedData_PerfProc_Process)
有了这个:
$perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
Windows 8 在您使用 x32 应用程序时不能完美地执行 WMI 操作,我制作了一个执行 *.bat 的虚拟 x64 应用程序,它终于可以运行了。感谢大家的帮助。
我在装有 Windows 8 Home Edition 的机器上遇到 WMI 问题。我需要按进程捕获 CPU 用法和 ProcessID。我试过很多方法:
- ShellExecute 在 Delphi
- 带有代码 的*.bat
- 一个*.vbs
- *.bat 执行的 *.vbs
- A*.ps1
- A *.ps1 由 *.bat 执行
(也许有些方法真的很蠢,但我还是试过了)
在 User-Click 中它完美地工作,但通过独立的应用程序它不起作用。 我已经在某些文件夹的 WMIMGMT.msi 上打开了 Security 并且执行策略(在 PowerShell 中)现在是 UNRESTRICTED。
这是 *.ps1 文件中的代码:
$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | Out-Null
$ErrorActionPreference = "Continue"
$perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
foreach ($p in $peflist) {
"" + $p.IDProcess + ";" + $p.PercentProcessTime
}
这是*.bat上的代码
powershell -ExcetutionPolicy Unrestricted -File "C:\Somefolder\PP.ps1" > C:\SomeFolder\output.txt
我得到的只是这个输出:
get-wmiobject : Invalid query "select * from Win32_Win32_PerfFormattedData_PerfProc_Process" In C:\Somefolder\PP.ps1:4 character: 14 + $perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException + FullyQualifiedErroID : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Edit1: 按要求复制的代码:
*.ps1:
$ErrorActionPreference="SilentlyContinue" Stop-Transcript | out-null $ErrorActionPreference = "Continue" $perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process) foreach ($p in $perflist) { "" + $p.IDProcess + ";" + $p.PercentProcessorTime }
*.bat
powershell -executionPolicy unrestricted -file "C:\MonitorPerformance\test.ps1" > C:\MonitorPerformance\output1.txt
输出:(Consulta inválida = 无效查询;No = in;caractere = character)
get-wmiobject : Consulta inv lida "select * from Win32_PerfFormattedData_PerfProc_Process" No C:\MonitorPerformance\test.ps1:4 caractere:14 + $perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
替换为:
$perflist = (get-wmiobject Win32_Win32_PerfFormattedData_PerfProc_Process)
有了这个:
$perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
Windows 8 在您使用 x32 应用程序时不能完美地执行 WMI 操作,我制作了一个执行 *.bat 的虚拟 x64 应用程序,它终于可以运行了。感谢大家的帮助。