我有下面的vbs脚本,它应该接受一个进程名(例如Notepad.exe),然后报告与该名称匹配的所有进程的相关详细信息。
它在我的电脑上工作正常(赢7),但在我的服务器上(Windows 2000)我收到错误说"Object doesn't support this property or method: objProcess.commandLine"
(第30行)
我假设它与Windows 2000有关,因为我在Windows 2008上运行它确定。我需要安装/更改以使其工作吗?
Option Explicit
dim strComputer
dim objWMIService
dim colProcessList
dim objProcess
dim PName
dim PCommandLine
dim PCLSplit
dim input
dim counter
input = InputBox("Please Enter the Process Name, as shown in Task Manager", "Enter Process Name", , 100, 200)
If input = "" Then
WScript.Echo "Canceled"
Else
WScript.Echo "You Entered: " & input
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & input & "'")
counter = 1
For Each objProcess in colProcessList
Wscript.echo counter & ")"
PName = objProcess.Name
PCommandLine = objProcess.CommandLine
PCLSplit = SPLIT(PCommandLine,chr(34))
Wscript.Echo "Application Name: " & PName & VbCrLf &_
"Command Line: " & PCLSplit(1) & VbCrLf &_
"Instance Name: " & PCLSplit(2) & VbCrLf
counter = 1+1
Next
wscript.echo "COMPLETE"
End If
wscript.quit
答案 0 :(得分:2)
来自MSDN
的CommandLine
数据类型:字符串
访问类型:只读
用于启动特定进程的命令行(如果适用)。 此属性是Windows XP的新功能。
答案 1 :(得分:1)
CommandLine数据类型不适用于OS的PRE Win XP ...但是,您可以简单地使用一些错误处理来避免来自Win2000系统的任何错误
添加“On Error Resume Next” 并检查变量中是否存在Chr(34),如果未找到,则可以根据需要进行处理或输入自己的值... 另外,我修改了计数器的语法...如果Counter = 1 + 1那么它总是等于2 ...你想将1添加到它自己的值,所以它变成Counter = Counter + 1
Option Explicit
dim strComputer
dim objWMIService
dim colProcessList
dim objProcess
dim PName
dim PCommandLine
dim PCLSplit
dim input
dim counter
input = InputBox("Please Enter the Process Name, as shown in Task Manager", "Enter Process Name", , 100, 200)
If input = "" Then
WScript.Echo "Canceled"
Else
WScript.Echo "You Entered: " & input
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & input & "'")
counter = 1
For Each objProcess in colProcessList
Wscript.echo counter & ")"
PName = objProcess.Name
PCommandLine = objProcess.CommandLine
If InStr(1, PCommandLine, Chr(34),1) > 0 Then
PCLSplit = SPLIT(PCommandLine,chr(34))
Else
PCLSplit = Array(vbNullString, "Not Found", "Unknown")
End If
Wscript.Echo "Application Name: " & PName & VbCrLf &_
"Command Line: " & PCLSplit(1) & VbCrLf &_
"Instance Name: " & PCLSplit(2) & VbCrLf
counter = counter + 1
Next
wscript.echo "COMPLETE"
End If
wscript.quit