gpt4 book ai didi

windows - 为什么 ProcessStartInfo 的参数为空?

转载 作者:行者123 更新时间:2023-12-02 23:56:28 25 4
gpt4 key购买 nike

当我尝试获取可执行文件的命令行参数时,我尝试检查 ProcessStartInfo Get-Process 返回的结构,但无论如何参数字段都是空的:

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 对象接口(interface)可以得到它。但是,为什么 powershell 缺少此功能?

最佳答案

不确定是否理解,但@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)

启动进程的方法有很多种,这种方法使用对象 Process封装了 Win32 CreateProcess .据我了解,当使用命令行时,您不会在 startinfo 中找到数据,当进程以编程方式启动时,它可以追加。

关于windows - 为什么 ProcessStartInfo 的参数为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44510652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com