2017-06-13 74 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