Search This Blog

Sunday, May 31, 2009

Command line args from Process ID (pid)

Sometime you need more from your task manager , not only the PID , you want to see the full command line , and you don't want to install the process explorer on a production server, so the next script will show you how to get the command line arguments by a process id.
open new text document , rename it to PidToCmd.vbs.
Edit the file.
Copy the next lines into it.



If WScript.Arguments.Count > 0 Then
Set Processes = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("select * from Win32_Process where ProcessID =" & WScript.Arguments.Item(0))
For each Process in Processes
PList = PList & Process.CommandLine & vbLf & vbLf & vbLf
Next
WScript.Echo "command line: " & VBlf & VBlf & UCase(PList)
Else
WScript.Echo "Usage: PidToCmd.vbs [process id]"
End If


Save the file .
run it .

enjoy
Yaniv T

No comments: