Windows 10 中的 VBS 无效查询 [英] VBS Invalid Query in Windows 10

查看:29
本文介绍了Windows 10 中的 VBS 无效查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以下 VBS 代码可以在 Windows 7 中运行,但在 Windows 10 上却出错:

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

我在 Windows 10 中遇到的错误是:

The error I'm getting in Windows 10 is:

test_2.vbs(4,1) SWbemObjectSet:查询无效

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

我在这里做错了什么?

推荐答案

尝试使用下面的代码.这应该有效

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

这篇关于Windows 10 中的 VBS 无效查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆