Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 不带WMI的进程命令行_Powershell - Fatal编程技术网

Powershell 不带WMI的进程命令行

Powershell 不带WMI的进程命令行,powershell,Powershell,我无法使用PowerShell直接从PEB读取指定进程的命令行。我正在使用NtQueryInformationProcess获取过程基本信息数据 # $proc - process handle if ($NtQueryInformationProcess( $proc, 0, $PROCESS_BASIC_INFORMATION, [Runtime.InteropServices.Marshal]::SizeOf( $PROCESS_BASIC_INFORMATION ), [

我无法使用PowerShell直接从PEB读取指定进程的命令行。我正在使用NtQueryInformationProcess获取过程基本信息数据

# $proc - process handle
if ($NtQueryInformationProcess(
  $proc, 0, $PROCESS_BASIC_INFORMATION, [Runtime.InteropServices.Marshal]::SizeOf(
    $PROCESS_BASIC_INFORMATION
  ), [IntPtr]::Zero
))) -eq 0) {
  # pointer to RTL_USER_PROCESS_PARAMETERS
  $ptr = [Runtime.InteropServices.Marshal]::ReadIntPtr($PROCESS_BASIC_INFORMATION.PebBaseAddress, 0x10)
  # pointer to CommandLine field of structure above
  $ptr = [Runtime.InteropServices.Marshal]::ReadIntPtr($ptr, 0x40)
  # how to get CommandLine field (UNICODE_STRING structure)?
}

所有指针都是正确的,但我不知道如何读取封送类型的命令行字段。有什么想法吗?

尽管标题上写着“没有WMI”,但我还是建议使用WMI,因为它更容易使用。例如,通过使用
Win32\u进程
WMI类

Get-WmiObject -Class Win32_Process -Filter "ProcessID = '10708'" | Format-List ProcessID, Name, Path, Commandline

ProcessID   : 10708
Name        : powershell.exe
Path        : C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Commandline : "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -version 2

此示例感觉不完整。什么是
$NtQuerInformationProcess
$
代表变量,
()
代表方法?请阅读,如果您还没有回答问题,请不要发表。这是一条评论,这是他们的目的。你的样品还不完整,还没有取款机。这个问题应该关闭(代码不可复制)。你应该让StackOverflow用户更容易帮助你。忘记吧。我将自己解决这个问题。标题中有:无WMI。我知道如何用WMI找到进程的命令行,但我想用WinAPI得到同样的结果。对不起,我没有注意到。我不明白为什么你会想要WinAPI,而WMI可以为你简化它。WMI也可在本地和远程使用(如果需要)。如果您不希望WMI的开销,那么您也应该避免使用PowerShell,并使用编译语言。首先,我看不出使用哪种语言有根本区别。如果ms中的性能很重要(我会根据您对复杂的WinAPI和easy WMI的选择来猜测),然后,您将在.NET framework加载和编译命令+++的执行时间上浪费大量时间,而PowerShell是这样做的,但如果您真的这么认为,您就是个差劲的专家。