SWbemServices.ExecQuery -“无效参数”添加 WHERE 子句时
我有以下 JavaScript 在远程 Windows 主机上执行 WMI 查询:
var wmiLocator = WScript.CreateObject("WbemScripting.Swbemlocator");
var wmiService = wmiLocator.ConnectServer(host, "root\\cimv2", user, pass);
var items = wmiService.ExecQuery(query);
for(var e = new Enumerator(items); ! e.atEnd(); e.moveNext())
{
WScript.StdOut.Write(e.item().GetObjectText_());
}
user
和 pass
是远程 host
的登录凭据,< code>query 是要执行的 WQL 查询。
在我向 WQL 查询添加 WHERE 子句之前,这一切都工作正常。例如,
SELECT * FROM Win32_LogicalDisk
产生预期结果,但
SELECT * FROM Win32_LogicalDisk WHERE DriveType=3
会导致“无效参数”错误 (wbemErrInvalidParameter / 0x80041008)。
我发现了许多使用 WHERE 子句的示例,但我找不到任何有关它不受支持的信息。我在这里错过了什么吗?
如果有任何相关的话,执行此脚本的主机是带有 SP2 的 Windows XP Professional。
I have the following JavaScript to execute a WMI query on a remote Windows host:
var wmiLocator = WScript.CreateObject("WbemScripting.Swbemlocator");
var wmiService = wmiLocator.ConnectServer(host, "root\\cimv2", user, pass);
var items = wmiService.ExecQuery(query);
for(var e = new Enumerator(items); ! e.atEnd(); e.moveNext())
{
WScript.StdOut.Write(e.item().GetObjectText_());
}
user
and pass
are the login credentials for the remote host
, query
is the WQL query to be performed.
This all works fine until I add a WHERE clause to the WQL query. For instance,
SELECT * FROM Win32_LogicalDisk
yields the expected result, but
SELECT * FROM Win32_LogicalDisk WHERE DriveType=3
will result in an "Invalid Parameter" error (wbemErrInvalidParameter / 0x80041008).
I've found numerous examples in which WHERE clauses are used, and I cannot find any info about it not being supported. Am I missing something here?
In case it is any relevant, the host executing this script is a Windows XP Professional with SP2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如海伦所暗示的,我自己回答这个问题。
查询字符串被我之前在脚本中所做的一些解析更改了,并且在语法上变得无效,因此出现了无效参数错误。
As hinted by Helen, I am answering this myself.
The query string was changed by some parsing I did earlier in my script and became syntactically invalid, hence the invalid parameter error.