Find my own process ID in VBScript

后端 未结 10 1043
小蘑菇
小蘑菇 2020-11-28 14:49

I\'m using the following code snippet to determine what process ID my vbscript is running as:

On Error Resume Next
Dim iMyPID : iMyPID = GetObject(\"winmgmts         


        
10条回答
  •  时光说笑
    2020-11-28 15:20

    This is not my answer, I found this in some google groups discussion forum... See if it helps you.

    Set objSWbemServices = GetObject ("WinMgmts:Root\Cimv2")
    Set colProcess = objSWbemServices.ExecQuery ("Select * From Win32_Process")
    
    For Each objProcess In colProcess
        If InStr (objProcess.CommandLine, WScript.ScriptName) <> 0 Then
          WScript.Echo objProcess.Name, objProcess.ProcessId, objProcess.CommandLine
        End If
    Next
    

    Original Discussion Thread in Google Groups forum

提交回复
热议问题