如何在Powershell中检测是否为嵌套的shell?
如果我打开一个Powershell或cmd.exe窗口,然后在其中输入powershell
<enter>,是否有一个神奇的$host.somevariable变量可以查询,以查找它是否为“内部”shell?
如何在Powershell中检测是否为嵌套的shell?
如果我打开一个Powershell或cmd.exe窗口,然后在其中输入powershell
<enter>,是否有一个神奇的$host.somevariable变量可以查询,以查找它是否为“内部”shell?
可能并没有所谓的“魔法变量”,但是可以通过以下方式获取这些信息:
$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'
}