用于安装最新Java版本的Vbscript

用于安装最新Java版本的Vbscript,vbscript,Vbscript,我正在尝试自动安装Java以安装新机器。 我计划将java下载到网络上的一个目录中,并让脚本从那里进行安装。 我希望脚本能够在32位和64位安装程序之间进行确定,而不必每次下载新安装程序时都更改脚本 如何使用通配符运行文件路径 这是我到目前为止所拥有的 这决定了体系结构 Function GetArch Dim WshShell Dim WshProcEnv Dim system_architecture Dim process_architecture Set WshShell = Cre

我正在尝试自动安装Java以安装新机器。 我计划将java下载到网络上的一个目录中,并让脚本从那里进行安装。 我希望脚本能够在32位和64位安装程序之间进行确定,而不必每次下载新安装程序时都更改脚本

如何使用通配符运行文件路径

这是我到目前为止所拥有的

这决定了体系结构

Function GetArch
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."
GetArch = system_architecture
End Function
这将运行可执行文件

Function runExec(strExec,blWait)
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell") 
objShell.Run strExec, 1 ,blWait
Set objShell = Nothing
End Function
这将有望安装Java

Function InstallJava
if Instr(1, GetArch, "64") then
    runExec "\\fs1\IT\Scripts\Java\jre-*-x64.exe",true
    InstallJava = "Java 64bit Installed"
ElseIf Instr(1, GetArch, "86") then
    runExec "\\fs1\IT\Scripts\Java\jre-*-i586.exe",true
    InstallJava = "Java 32bit Installed"
End If
End Function

不支持通配符。您需要枚举这些文件,例如:

Set fso=CreateObject(“Scripting.FileSystemObject”)
对于fso.GetFolder(“\\fs1\IT\Scripts\Java”)文件中的每个f
如果LCase(左(f.Name,4))=“jre-”,则
如果InStr(1,GetArch,“64”)>0,则
如果LCase(右(f.Name,8))=“-x64.exe”,则runExec f.Path,True
ElseIf InStr(1,GetArch,“86”)>0然后
如果LCase(Right(f.Name,9))=“-i586.exe”,则runExec f.Path,True
如果结束
如果结束
下一个
不过,您可以使用不同的方法。由于您将下载并提供共享上的文件,因此可以修改设置,以创建/更新具有固定名称的符号链接到相应文件,例如

D:\IT\Scripts\Java>mklink jre-CURRENT-x64.exe jre-7u45-windows-x64.exe
D:\IT\Scripts\Java>mklink jre-CURRENT-x86.exe jre-7u45-windows-i586.exe
然后在安装脚本中使用这些固定名称:

如果Instr(1,GetArch,“64”)>0,则
runExec“\\fs1\IT\Scripts\Java\jre-CURRENT-x64.exe”,真
ElseIf Instr(1,GetArch,“86”)>0然后
runExec“\\fs1\IT\Scripts\Java\jre-CURRENT-x86.exe”,真
如果结束