[VB] 無需 OpenProcess 取得進程檔案路徑

在翻以前的部落格的時候找到的...
其實不是很清楚是怎麼達成的,好像是提權之後透過WMI查找進程路徑?

調用方式:
MsgBox GetProPath("Explorer.exe")

函數:
Public Function GetProPath(ProName As String) As String
 Dim objWMIService As Object
 Dim colProcesslist As Object
 Dim objProcess As Object
 Set objWMIService = CreateObject("winmgmts:{impersonationLevel=Impersonate}!root\cimv2")
 Set colProcesslist = objWMIService.ExecQuery("select * from win32_process where name=" & Chr(39) & ProName & Chr(39))
 For Each objProcess In colProcesslist
 GetProPath = objProcess.ExecutablePath
 Next
End Function

留言

本月最夯

偷用電腦,怎知?事件檢視器全記錄!(開機時間、啟動項時間...)