0

我有下面的 vbs 脚本,它应该接受一个进程名(例如 Notepad.exe),然后报告与该名称匹配的所有进程的相关详细信息。

它在我的电脑(win 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
4

2 回答 2

2

来自 MSDN

命令行

数据类型:字符串

访问类型:只读

用于启动特定进程的命令行(如果适用)。此属性是 Windows XP 的新属性

于 2013-10-08T16:36:16.487 回答
1

命令行数据类型不适用于操作系统的 PRE Win XP... 但是,您可以简单地使用一些错误处理来避免 Win2000 系统的任何错误

添加“On Error Resume Next”并检查变量中是否存在 Chr(34),如果未找到,则可以酌情处理或输入自己的值...此外,我修复了计数器的语法。 . If Counter = 1 + 1 Then it will always equal 2...You want to add 1 to its own value so it then become 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
于 2013-10-09T06:35:45.973 回答