为什么以下VBS代码在Windows 7中有效,但在Windows 10上出错:
strComputer="."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'notepad.exe'")
Wscript.Echo colProcesses.Count
我在Windows 10中遇到的错误是:
test_2.vbs(4,1)SWbemObjectSet:查询无效
我在这里做错了什么?
答案 0 :(得分:1)
尝试使用以下代码。这应该工作
strQuery = "select * from win32_process where Name = " & """" & "Notepad.exe" & """"
strComputer="."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery(strQuery)
Wscript.Echo colProcesses.Count