
如何根據進程描述使用循環從電腦記憶體中獲取進程名稱?
例子:
我的程式在記憶體中的名稱是“dev.exe”,其描述是“幫助php開發人員的工具”
即使使用者更改名稱,有沒有辦法透過使用流程描述找到我的流程名稱?
我們可以使用 autoit、cmd 或 wmic 來完成此操作嗎?
答案1
我發現這個連結試圖解決同樣的問題。在現有答案的基礎上,可以添加到現有腳本中的簡單行:
Get-Process | where {$_.Description -like '*note*'} | select Path, Description, ProcessName
輸出範例:
Path Description ProcessName
---- ----------- -----------
C:\Windows\system32\notepad.exe Notepad notepad
C:\Program Files\Microsoft Office\root\Office16\ONENOTE.EXE Microsoft OneNote ONENOTE
C:\Program Files\Microsoft Office\root\Office16\ONENOTEM.EXE Send to OneNote Tool ONENOTEM
答案2
鑑於其“文件描述”屬性值,如何找到正在運行的進程名稱?
改進的解決方案(感謝 @BenN 以下聊天討論):
使用下列 PowerShell 腳本 (Get-ProcessName.ps1)。
$_match=$Args[0].ToLowerInvariant()
Get-Process | where {$_.Description -ne $null -and $_.Description.ToLowerInvariant().Contains($_match)} | select Path, Description, ProcessName
筆記:
- 傳遞給腳本的第一個參數用於在「檔案描述」屬性值中執行不區分大小寫的搜尋。
- 如果「notepad.exe」和「notepad++.exe」都在運行,則傳遞「notepad」將會匹配它們。
輸出範例:
PS F:\test> .\Get-ProcessName notepad
Path Description ProcessName
---- ----------- -----------
C:\Windows\system32\notepad.exe Notepad notepad
E:\LiberKey\Apps\Notepad++\App\Notepad++\notepad++.exe Notepad++ : a free (GNU) source code editor notepad++
E:\LiberKey\Apps\Notepad++\App\Notepad++\notepad++.exe Notepad++ : a free (GNU) source code editor notepad++
PS F:\test>
原解決方案:
使用下列 Powershell 腳本 (Get-ProcessName.ps1)。
$_name=$Args[0]
$_match="*"+$Args[0]+"*"
Get-Process | ForEach {
if ($_.Path) {
$_filedescription=(Get-Item $_.Path).VersionInfo.FileDescription
if ($_filedescription -like $_match) {
Write-Output "File Description: '$_filedescription', Process Path: '$($_.Path)', Process Name: '$($_.ProcessName)'"
}
}
}
筆記:
- 傳遞給腳本的第一個參數用於在「檔案描述」屬性值中執行「通配符」不區分大小寫的搜尋。
- 如果您通過,
string
它將使用搜尋*string*
並將匹配string
“文件描述”屬性中的任何位置 - 如果「notepad.exe」和「notepad++.exe」都在運行,則傳遞「notepad」將會匹配它們。
- 此腳本輸出「檔案描述」、「進程路徑」和「進程名稱」。
輸出範例:
PS F:\test> .\Get-ProcessName notepad
File Description: 'Notepad', Process Path: 'C:\Windows\system32\notepad.exe', Process Name: 'notepad'
File Description: 'Notepad++ : a free (GNU) source code editor', Process Path: 'E:\LiberKey\Apps\Notepad++\App\Notepad++\notepad++.exe', Process Name: 'notepad++'
File Description: 'Notepad++ : a free (GNU) source code editor', Process Path: 'E:\LiberKey\Apps\Notepad++\App\Notepad++\notepad++.exe', Process Name: 'notepad++'
PS F:\test>
筆記:
- 運行便攜式版本時,「notepad++.exe」在記憶體中有兩個進程。