强制vbscript以64位而不是32位打开命令提示符

Arv*_*wen 3 vbscript ffmpeg windows-server-2008-r2

我一直试图让这个脚本全天工作!

以下是关于我的情况的一些事实......

  • 我的"C:\ Windows\System32 \"文件夹中有一个名为"ffmpeg.exe"的程序.
  • 我在"C:\ Windows\SysWOW64 \"文件夹中没有该程序.

目前这是我的剧本......

Option Explicit

Dim oFSO, oShell, sCommand
Dim sFilePath, sTempFilePath

Set oFSO = CreateObject("Scripting.FileSystemObject")

sFilePath = "C:\test\in_video.mkv"
sTempFilePath = "C:\test\out_video.mp4"

sCommand = "%comspec% /k ffmpeg -n -i """ + sFilePath + """ -c:v copy -c:a copy """ + sTempFilePath + """"
WScript.Echo sCommand
Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run sCommand, 1, True
Set oShell = Nothing

Set oFSO = Nothing
Run Code Online (Sandbox Code Playgroud)

如果我在命令提示符下手动运行此脚本,那么它似乎工作正常.但是,如果我让另一个应用程序运行它(例如在这种情况下为uTorrent),它会按预期运行脚本,但是当它尝试处理oShell.Run命令时,它会在32位环境中运行它!然后我明白了...... 不存在

如果我尝试打开一个新的命令提示符(没什么特别的)我似乎默认为64位环境,然后我可以输入"ffmpeg",它会按预期显示帮助内容.

因此,由于某种原因,我无法让脚本在64位环境中运行应用程序(特别是CMD).谁知道我怎么能做到这一点?


更新

似乎我的脚本实际上是在32位模式下运行!即使脚本标题栏显示"C:\ Windows\System32\cscript.exe",这是一个64位环境!!

我使用以下脚本来确定它是在32位环境中运行的...

Dim WshShell
Dim WshProcEnv
Dim system_architecture
Dim process_architecture

Set WshShell =  CreateObject("WScript.Shell")
Set WshProcEnv = WshShell.Environment("Process")

process_architecture= WshProcEnv("PROCESSOR_ARCHITECTURE") 

If process_architecture = "x86" Then    
    system_architecture= WshProcEnv("PROCESSOR_ARCHITEW6432")

    If system_architecture = ""  Then    
        system_architecture = "x86"
    End if    
Else    
    system_architecture = process_architecture    
End If

WScript.Echo "Running as a " & process_architecture & " process on a " _ 
    & system_architecture & " system."
Run Code Online (Sandbox Code Playgroud)

Syb*_*oor 5

如果它仅适用于cmd或System32中的某个文件,则可以使用注释建议的sysnative.它甚至可以从32Bit可执行文件导致64Bit System32.只需将"system32"替换为"sysnative"即可.(遗憾的是,这在32位窗口中不存在,因此您需要检查是否在具有这两种体系结构的系统上使用脚本...)

如果你有很多访问或使用com对象,我发现它更容易使用相同的方法重新启动你的脚本.以下代码:

If fso.FileExists("C:\Windows\SysWOW64\wscript.exe") Then ' very basic check for 64bit Windows, you can replace it with a more complicated wmi check if you find it not reliable enough
    If InStr(1, WScript.FullName, "SysWOW64", vbTextCompare) <> 0 Then ' = case insensitive check
        newFullName = Replace(WScript.FullName, "SysWOW64", "Sysnative", 1, -1, vbTextCompare) ' System32 is replaced by Sysnative to deactivate WoW64, cscript or wscript stay the same
        newArguments = "" ' in case of command line arguments they are passed on
        For Each arg In WScript.Arguments
            newArguments = newArguments & arg & " "
        Next
        wso.Run newFullName & " """ & WScript.ScriptFullName & """ " & newArguments, , False
        WScript.Quit '32 Bit Scripting Host is closed
    End If
End If
Run Code Online (Sandbox Code Playgroud)

使用32Bit Scripting主机调用脚本时,基本上会关闭脚本,然后使用64位脚本重新启动它,这样就可以找到所有内容.