Nick G.
Nick G.

Reputation: 33

WMI Scripting Windows 8 error

I have a problem with WMI in a machine with a Windows 8 Home Edition. I need to catch the CPU usage and the ProcessID by process. I've tried so many ways:

(Maybe some of these ways can be really stupid, but I've tried anyway)

In the User-Click it works perfectally, but by a standalone applicantion it doesn't work. I have opened the Security on WMIMGMT.msi of some folders and the execution policy (in PowerShell) now is UNRESTRICTED.

This is the code on the *.ps1 file:

$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | Out-Null
$ErrorActionPreference = "Continue"
$perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)
foreach ($p in $peflist) {
  "" + $p.IDProcess + ";" + $p.PercentProcessTime
}

This is the code on *.bat

powershell -ExcetutionPolicy Unrestricted -File "C:\Somefolder\PP.ps1" > C:\SomeFolder\output.txt

All I got is this output:

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: The code copied as asked:

Upvotes: 1

Views: 674

Answers (2)

Nick G.
Nick G.

Reputation: 33

Windows 8 does not performs WMI actions perfectly when you use x32 applications, I made a dummy x64 application who executes the *.bat and it finally works. Thanks for all the help.

Upvotes: 0

Anthony Stringer
Anthony Stringer

Reputation: 2001

replace this:

$perflist = (get-wmiobject Win32_Win32_PerfFormattedData_PerfProc_Process)

with this:

$perflist = (get-wmiobject Win32_PerfFormattedData_PerfProc_Process)

Upvotes: 0

Related Questions