
我正在嘗試在 64 位元下運行 .vbs 腳本。當我手動執行此腳本時,它將正確執行,但是當由其他程式啟動時,它將在 32 位元下運行並且無法正確執行。
這是我的腳本:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run Chr(34) & "C:\Users\Chris Nicol\Documents\SlickRun Scripts\Zune\RunZune.bat" & Chr(34), 0
Set WshShell = Nothing
基本上我想強制使用C:\windows\syswow64\cmd.exe
,以便它能夠正確運行。我似乎無法獲得正確的語法,也無法找到有關此問題的幫助。
這是我嘗試執行的批次文件和註冊表文件:
運行Zune.bat:
@ECHO OFF
regedit /s FeaturesOverride.reg
"C:\Program Files\Zune\Zune.exe"
exit
FeaturesOverride.reg:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Zune\Features]
"Channels"="US,CA"
"MusicVideos"="US,CA"
"Picks"="US,CA"
"Podcasts"="US,CA"
"QuickMixLocal"="US,CA"
答案1
以下程式碼將檢查系統是否為 64 位,在這種情況下,關閉腳本並重新運行它,透過直接使用腳本作為參數呼叫它來強制使用 64 位主機。
If fso.FileExists("C:\Windows\SysWOW64\wscript.exe") Then
If InStr(1, WScript.FullName, "SysWOW64", vbTextCompare) <> 0 Then ' = very basic 64bit check replace if you want a more sophisticated one
newFullName = Replace(WScript.FullName, "SysWOW64", "Sysnative", 1, -1, vbTextCompare) ' System32 will be replaced by Sysnative. calls to sysnative bypass WoW64 emulation, cscript or wscript stays the same as they were
newArguments = "" ' all arguments are given to the new script call
For Each arg In WScript.Arguments
newArguments = newArguments & arg & " "
Next
wso.Run newFullName & " """ & WScript.ScriptFullName & """ " & newArguments, , False
WScript.Quit ' Close 32Bit scripting host
End If
End If
此解決方法可確保腳本以 64 位元運行,無論誰呼叫它。如果您遇到可以控制呼叫的情況(例如,腳本僅透過特定連結呼叫),您可能可以只使用基本原則(即sysnative 檔案系統重新導向器)直接在您的快捷方式中。