如何从 Wow64 下运行的 vb 脚本启动以 64 位模式运行的 Vb 脚本

发布于 2024-10-01 07:51:57 字数 127 浏览 5 评论 0原文

我有一个 VB 脚本被迫在 Wow64 模式下运行。我想让它以本机 64 位模式启动另一个脚本或自身。有办法做到这一点吗?

初始脚本是通过显式调用 cscript.exe 来调用的(不确定这是否有影响)

谢谢

I have a VB script that's being forced to run in Wow64 mode. I'd like to have it start either another script, or itself, in native 64 bit mode. Is there anyway to do that?

The initial script is being called by an explicit call to cscript.exe (not sure if this makes a difference or not)

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一世旳自豪 2024-10-08 07:51:58

显然它非常简单。

在 Windows Vista 及更高版本中,C:\Windows\Sysnative 中有一个别名文件夹。如果您调用它,它不会重定向到 c:\windows\SysWow64 32 位文件夹,但会强制调用本机 64 位可执行文件

http://msdn.microsoft.com/en-us/library/aa384187(VS.85).aspx

因此,您可以运行通过调用 %windir%\Sysnative\cscript.exe,然后提供脚本名称作为参数,从以 wow64 模式运行的 vbscript 获取 64 位模式的 vbscript。

但是,这仅适用于 Windows Vista 或更高版本。有一个修补程序可以在 Windows XP/2003 中启用此 Sysnative 文件夹

http://support.microsoft.com/ KB/942589

Apparently its pretty simple.

In Windows Vista and newer there is an alias folder at C:\Windows\Sysnative. If you call it it will not redirect to the c:\windows\SysWow64 32 bit folder but will force the native 64 bit executables to be called

http://msdn.microsoft.com/en-us/library/aa384187(VS.85).aspx

Therefore, you can run a vbscript in 64 bit mode from a vbscript running in wow64 mode by calling %windir%\Sysnative\cscript.exe and then providing the name of your script as a parameter.

However, this only works in Windows Vista or newer. There is a hotfix which can enable this Sysnative folder in Windows XP/2003

http://support.microsoft.com/kb/942589

请帮我爱他 2024-10-08 07:51:58

将以下代码放在脚本顶部以检测操作系统是否为 64 位,然后以 32 位模式重新运行

' ***************
' *** 64bit check
' ***************
' check to see if we are on 64bit OS -> re-run this script with 32bit cscript
Function RestartWithCScript32(extraargs)
Dim strCMD, iCount
strCMD = r32wShell.ExpandEnvironmentStrings("%SYSTEMROOT%") & "\SysWOW64\cscript.exe"
If NOT r32fso.FileExists(strCMD) Then strCMD = "cscript.exe" ' This probably won't work if we can't find the SysWOW64 Version
strCMD = strCMD & Chr(32) & Wscript.ScriptFullName & Chr(32)
If Wscript.Arguments.Count > 0 Then
 For iCount = 0 To WScript.Arguments.Count - 1
  if Instr(Wscript.Arguments(iCount), " ") = 0 Then ' add unspaced args
   strCMD = strCMD & " " & Wscript.Arguments(iCount) & " "
  Else
   If Instr("/-\", Left(Wscript.Arguments(iCount), 1)) > 0 Then ' quote spaced args
    If InStr(WScript.Arguments(iCount),"=") > 0 Then
     strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") + 1) & """ "
    ElseIf Instr(WScript.Arguments(iCount),":") > 0 Then
     strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") + 1) & """ "
    Else
     strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
    End If
   Else
    strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
   End If
  End If
 Next
End If
r32wShell.Run strCMD & " " & extraargs, 0, False
End Function

Dim r32wShell, r32env1, r32env2, r32iCount
Dim r32fso
SET r32fso = CreateObject("Scripting.FileSystemObject")
Set r32wShell = WScript.CreateObject("WScript.Shell")
r32env1 = r32wShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")
If r32env1 <> "x86" Then
 ' we are not running in x86 mode, so run in that mode; check if we have done this already
 For r32iCount = 0 To WScript.Arguments.Count - 1
  r32env2 = r32env2 & WScript.Arguments(r32iCount) & VbCrLf
 Next
 ' MsgBox "64bit (restarting) " & r32env2
 If InStr(r32env2,"restart32") = 0 Then RestartWithCScript32 "restart32" Else MsgBox "Cannot find 32bit version of cscript.exe or unknown OS type " & r32env1
 Set r32wShell = Nothing
 WScript.Quit
Else
 For r32iCount = 0 To WScript.Arguments.Count - 1
  r32env2 = r32env2 & WScript.Arguments(r32iCount) & VbCrLf
 Next
' MsgBox "32bit! " & r32env2
End If
'MsgBox "OS: " & r32env1 & VbCrLf & "Param: " & r32env2 & VbCrLf & "Script: " & WScript.FullName & VbCrLf & "Fullname: " & " " & Wscript.ScriptFullName
Set r32wShell = Nothing
Set r32fso = Nothing
' WScript.Quit
' *******************
' *** END 64bit check
' *******************

Place the following code at the top of your script to detect if the OS is 64bit then re-run in 32bit mode

' ***************
' *** 64bit check
' ***************
' check to see if we are on 64bit OS -> re-run this script with 32bit cscript
Function RestartWithCScript32(extraargs)
Dim strCMD, iCount
strCMD = r32wShell.ExpandEnvironmentStrings("%SYSTEMROOT%") & "\SysWOW64\cscript.exe"
If NOT r32fso.FileExists(strCMD) Then strCMD = "cscript.exe" ' This probably won't work if we can't find the SysWOW64 Version
strCMD = strCMD & Chr(32) & Wscript.ScriptFullName & Chr(32)
If Wscript.Arguments.Count > 0 Then
 For iCount = 0 To WScript.Arguments.Count - 1
  if Instr(Wscript.Arguments(iCount), " ") = 0 Then ' add unspaced args
   strCMD = strCMD & " " & Wscript.Arguments(iCount) & " "
  Else
   If Instr("/-\", Left(Wscript.Arguments(iCount), 1)) > 0 Then ' quote spaced args
    If InStr(WScript.Arguments(iCount),"=") > 0 Then
     strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") + 1) & """ "
    ElseIf Instr(WScript.Arguments(iCount),":") > 0 Then
     strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") + 1) & """ "
    Else
     strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
    End If
   Else
    strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
   End If
  End If
 Next
End If
r32wShell.Run strCMD & " " & extraargs, 0, False
End Function

Dim r32wShell, r32env1, r32env2, r32iCount
Dim r32fso
SET r32fso = CreateObject("Scripting.FileSystemObject")
Set r32wShell = WScript.CreateObject("WScript.Shell")
r32env1 = r32wShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")
If r32env1 <> "x86" Then
 ' we are not running in x86 mode, so run in that mode; check if we have done this already
 For r32iCount = 0 To WScript.Arguments.Count - 1
  r32env2 = r32env2 & WScript.Arguments(r32iCount) & VbCrLf
 Next
 ' MsgBox "64bit (restarting) " & r32env2
 If InStr(r32env2,"restart32") = 0 Then RestartWithCScript32 "restart32" Else MsgBox "Cannot find 32bit version of cscript.exe or unknown OS type " & r32env1
 Set r32wShell = Nothing
 WScript.Quit
Else
 For r32iCount = 0 To WScript.Arguments.Count - 1
  r32env2 = r32env2 & WScript.Arguments(r32iCount) & VbCrLf
 Next
' MsgBox "32bit! " & r32env2
End If
'MsgBox "OS: " & r32env1 & VbCrLf & "Param: " & r32env2 & VbCrLf & "Script: " & WScript.FullName & VbCrLf & "Fullname: " & " " & Wscript.ScriptFullName
Set r32wShell = Nothing
Set r32fso = Nothing
' WScript.Quit
' *******************
' *** END 64bit check
' *******************
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文