VBS Invalid Query in Windows 10

核能气质少年 提交于 2020-06-17 02:01:31

问题


Why does the following VBS code work in Windows 7 but gives error on 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

The error I'm getting in Windows 10 is:

test_2.vbs(4,1) SWbemObjectSet: Invalid query

What am I doing wrong here?


回答1:


Try and use the below code. This should work

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


来源:https://stackoverflow.com/questions/44963115/vbs-invalid-query-in-windows-10

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!