Getting Script Name from wscript.exe Process

后端 未结 2 496
花落未央
花落未央 2021-01-15 01:16

I am using this code:

Dim name
name = CreateObject(\"WScript.Shell\").ExpandEnvironmentStrings(\"%computername%\")
Set wmi = GetObject(\"winmgmts:\" _
    &a         


        
相关标签:
2条回答
  • 2021-01-15 01:35

    You have ScriptName and ScriptFullName properties.

    ' in VBScript
    WScript.Echo WScript.ScriptName
    WScript.Echo WScript.ScriptFullName
    
    // in JScript
    WScript.Echo(WScript.ScriptName);
    WScript.Echo(WScript.ScriptFullName);
    

    [EDIT] Here you go (use .CommandLine property):

    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" _
        & "." & "\root\cimv2")
    
    Set colProcesses = objWMIService.ExecQuery( _
        "Select * from Win32_Process " _
        & "Where Name = 'WScript.exe'", , 48)
    
    Dim strReport
    For Each objProcess in colProcesses
        ' skip current script, and display the rest
        If InStr (objProcess.CommandLine, WScript.ScriptName) = 0 Then
            strReport = strReport & vbNewLine & vbNewLine & _
                "ProcessId: " & objProcess.ProcessId & vbNewLine & _
                "ParentProcessId: " & objProcess.ParentProcessId & _
                vbNewLine & "CommandLine: " & objProcess.CommandLine & _
                vbNewLine & "Caption: " & objProcess.Caption & _
                vbNewLine & "ExecutablePath: " & objProcess.ExecutablePath
        End If
    Next
    WScript.Echo strReport
    
    0 讨论(0)
  • 2021-01-15 01:38
    myProcess="wscript.exe"               
    Set Processes = GetObject("winmgmts:").InstancesOf("Win32_Process")
    For Each Process In Processes
     If StrComp(Process.Name, myProcess, vbTextCompare) = 0 Then     'check if process exist      
       CmdLine=process.commandline                  
     End If
    Next
    myArr=split(CmdLine,"\")
    mySN=replace(myArr(ubound(myArr)),"""","")
    Wscript.Echo "Full Pth: " & Cmdline &vbcrlf&"Script Name: "& mySN  
    
    0 讨论(0)
提交回复
热议问题