code

PowerShell 또는 C #에서 프로세스에 대한 명령 줄 정보를 가져 오는 방법

codestyles 2020. 12. 11. 08:14
반응형

PowerShell 또는 C #에서 프로세스에 대한 명령 줄 정보를 가져 오는 방법


예 : 실행 notepad.exe c:\autoexec.bat하면,

어떻게 얻을 수 c:\autoexec.bat있는 Get-Process notepadPowerShell에서?

또는 어떻게 얻을 수 c:\autoexec.bat있는 Process.GetProcessesByName("notepad");C #으로?


PowerShell에서 WMI를 통해 프로세스의 명령 줄을 가져올 수 있습니다.

$process = "notepad.exe"
Get-WmiObject Win32_Process -Filter "name = '$process'" | Select-Object CommandLine

다른 사용자의 컨텍스트에서 실행중인 프로세스에 대한 정보에 액세스하려면 관리자 권한이 필요합니다. 일반 사용자는 자신의 컨텍스트에서 실행되는 프로세스에 대해서만 볼 수 있습니다.


이 답변은 훌륭하지만 미래를 보장하고 미래에 유리하게 사용할 수 있습니다. 꽤 오래된 powershell을 사용하지 않는 한 (이 경우 업데이트를 권장합니다!) Get-WMIObject가 Get-CimInstance Hey Scripting Guy 참조 로 대체되었습니다.

이 시도

$process = "notepad.exe"
Get-CimInstance Win32_Process -Filter "name = '$process'" | select CommandLine 

참고 URL : https://stackoverflow.com/questions/17563411/how-to-get-command-line-info-for-a-process-in-powershell-or-c-sharp

반응형