2017-06-13 72 views
1

當我試圖得到一個可執行的命令行參數,我想檢查由Get-Process返回ProcessStartInfo結構,但參數字段爲空不管是什麼:爲什麼ProcessStartInfo的參數是空的?

PS C:\> ps notepad 

Handles NPM(K) PM(K)  WS(K)  CPU(s)  Id SI ProcessName 
------- ------ -----  -----  ------  -- -- ----------- 
    272  15  3484  19888  0.39 33696 1 notepad 

PS C:\> $(ps notepad).StartInfo 

Verb     : 
Arguments    : 
CreateNoWindow   : False 
EnvironmentVariables : {ConEmuBaseDir, ConEmuConfig, ConEmuArgs, PROCESSOR_REVISION...} 
Environment    : {[ConEmuBaseDir, C:\Users\fluter\Tools\ConEmu.Core.17.1.18.0\Tools\ConEmu], [ConEmuConfig, ], [ConEmuArgs, ], [PROCESSOR_REVISION, 4501]...} 
RedirectStandardInput : False 
RedirectStandardOutput : False 
RedirectStandardError : False 
StandardErrorEncoding : 
StandardOutputEncoding : 
UseShellExecute   : True 
Verbs     : {} 
UserName    : 
Password    : 
PasswordInClearText  : 
Domain     : 
LoadUserProfile   : False 
FileName    : 
WorkingDirectory  : 
ErrorDialog    : False 
ErrorDialogParentHandle : 0 
WindowStyle    : Normal 

但正如所料,procexp實用的Sysinternals套件可以得到完整的命令行:

enter image description here

此外,作爲評論中指出,使用Win32 WMI對象接口可以得到它。但是,爲什麼PowerShell缺少這個功能?

+0

可能的[如何獲取PowerShell或C#中的進程的命令行信息]的副本(https://stackoverflow.com/questions/17563411/how-to-get-command-line-info-for-a- process-in-powershell-or-c-sharp) – LotPings

+0

你知道爲什麼參數或startinfo是空的嗎? – fluter

+0

對不起,沒有。必須有一個原因,爲什麼MicroSoft推出Sysinternals。任務管理器增長更好,但我仍然使用ProcExp。 – LotPings

回答

1

不知道理解,但@LotPing點了答案:

$proc = Get-Process notepad 
$pInfos = Get-WmiObject Win32_Process -Filter "name = '$($proc.MainModule.ModuleName)'" 
$pInfos.CommandLine 

CommandLine爲您提供了相同的信息ProcessXP


當這個對象用於你會發現在startinfo東西啓動過程:

$startInfo = New-Object Diagnostics.ProcessStartInfo 
$startInfo.Filename = "notepad" 
$startInfo.Arguments = "toto.txt" 
$startInfo.UseShellExecute = $false 
$Proc = [Diagnostics.Process]::Start($startInfo) 

它ex ists許多方式來啓動一個進程這一個使用對象Process封裝Win32 CreateProcess。據我瞭解,當使用命令行的時候,你不會在startinfo中找到數據,當這個進程開始編程時它可以追加。

+0

我的問題更像是爲什麼這些信息不在'ProcessStartupInfo'中?使用WMI只是最後的手段。 – fluter

+0

我在我的答案中解釋它。 – JPBlanc