【发布时间】:2020-04-28 14:14:00
【问题描述】:
我正在编写一个 Powershell 脚本,它将集成到为 32 位 Windows 机器设计的产品中。因此,在调用时,即使在 64 位机器上,它也会默认在 x86 Powershell 上运行。 其中一条线需要在 64 位 shell 上运行才能获得准确的结果。尝试这样做:
#Above this is the ongoing script in 32bit session
if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
#write-warning "Excecuting the script under 64 bit powershell"
if ($myInvocation.Line) {
[System.IntPtr]::Size
&"$env:systemroot\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile
#Statement block
}else{
&"$env:systemroot\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile $args
#Statement block
}
}
#Below this is the remaining Script in 32 bit session
我无法将控制流传递给新会话并将其取回。它所做的只是在已经运行的 32 位 shell 中启动 64 位 shell。有什么方法可以做到这一点并返回新外壳打印的值?
【问题讨论】:
-
那么,在 32 位目标机器上会发生什么?他们都输出不准确的结果?
-
这是凯斯吗?您可以只以 64 位运行脚本或命令,还是以 64 位运行整个程序?
-
@MathiasR.Jessen 我要获取的数据是系统上所有已安装的应用程序。这可以从注册表路径
Get-Childitem "HKLM://SOFTWARE//Microsoft//Windows//CurrentVersion//Uninstall//*"中获取,但是在 64 位机器上,如果上面是在 32 位 shell 上运行的,由于某种原因它不包含所有已安装的应用程序。 -
@vercetti 啊,明白了。也许query the 64-bit registry view explicitly 在 64 位上?
-
@js2010 脚本的另一部分需要在 32 位 shell 上运行。 这是 Kace 吗?您是在谈论特定的脚本吗?
标签: windows powershell