是否可以从 Powershell 中检测它是否是嵌套 shell?
如果我打开 Powershell 或 cmd.exe 窗口,然后输入 powershell
最佳答案
没有这样一个神奇的变量,更有可能。但是有可能得到这个信息:
$me = Get-WmiObject -Query "select * from Win32_Process where Handle=$pid"
$parent = Get-Process -Id $me.ParentProcessId
if ($parent.ProcessName -eq 'powershell') {
'nested, called from powershell'
}
elseif ($parent.ProcessName -eq 'cmd') {
'nested, called from cmd'
}
else {
'not nested'
}
关于powershell - 如何检测 Powershell 中的 Powershell 嵌套?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4380531/