如何取得一个指定进程所在的路径
如何取得一个指定进程所在的路径???请问下
ProcessList 好像不行
解决了
$list = ProcessList()
for $i = 1 to $list
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $objItem In $colItems
$path = "ExecutablePath: " & $objItem.commandline
$Name = "Name: " & $objItem.Name
$Pid ="ProcessId: " & $objItem.ProcessId
if StringinStr ($Name ,$list[$i],0,1) <> 0 then
$s1=StringTrimLeft ($Path, 16)
$s2=StringStripWS(StringTrimLeft ($Name, 5),8)
$s3=StringStripWS(StringReplace(StringLeft($s1,StringInStr($s1,"exe")+2),'"',""),8)
endif
Next
If $s3 = "" Then
$s3 = "系统进程"
EndIf
GUICtrlCreateListViewItem($list[$i]&" - "&$list[$i]&"|"&$s3&"|级别:安全",$lvwList)
next
[ 本帖最后由 lele9013 于 2008-8-6 02:40 编辑 ] $List=ProcessList ()
for $i = 1 to $list
MsgBox(64,"进程信息(API)","进程路径是:"&Processpath($list[$i]))
MsgBox(64,"进程信息(WMI)","进程路径是:"&Procespath($list[$i]))
next
Func Processpath($iPID)
;通过API获取指定PID的进程路径
;官方牛人制作
Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
If $aProc = 0 Then Return SetError(1, 0, '')
Local $vStruct = DllStructCreate('int')
DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc, 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc, 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
If StringLen($aReturn) = 0 Then Return SetError(2, 0, '')
Return $aReturn
EndFunc
Func Procespath($pid)
;通过WMI获取指定PID的进程路径
;叁恨居士制作
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId = "&$pid)
For $objItem In $colItems
$cmdpath=$objItem.CommandLine
$exepath=$objItem.ExecutablePath
$path=StringSplit($cmdpath,"\")
if $path<=2 Then
Return$exepath
Else
Return$cmdpath
EndIf
Next
EndFunc
试试这个 好东东,收藏了,谢谢LS的. 真的是好东西..不知道二楼的在哪里找到的函数.. 有用!可要慢慢看! 学习了!!! 回复 2# bing614
非常不错,除开wmi,其他方式写的话如果编译的是X86,在X64运行,会获取不到路径。不知道为啥
页:
[1]