
考慮以下 powershell 腳本:
[System.IntPtr]::Size
[Environment]::Is64BitProcess
如果我直接在 64 位元機器上的 powershell 中運行它,那麼我會正確地得到
8
True
但是當我使用 Inno Setup(在 32 位元機器上建造)將其包裝在自解壓縮安裝程式中時,我總是得到:
4
False
如何確保 powershell 在 64 位元電腦上以 64 位元模式運作(32 位元電腦則以 32 位元模式運作)?
我還嘗試執行一個調用 powershell 腳本的批次文件,假設系統將以預設模式啟動 powershell,但這也不起作用。
我也嘗試過 iexpress 來包裝程序,同樣的問題。
答案1
如果您的安裝程式是 32 位元應用程序,它將始終啟動 32 位元 PowerShell。即使使用完整路徑:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
因為 Windows 檔案系統重新導向器會將其變更為C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
若要從 32 位元進程啟動 64 位元 PowerShell,請使用:
C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe
在 32 位元電腦上,相同的命令仍應執行 32 位元 PowerShell,但我無法再對其進行測試。