2014-01-08 47 views
1

我正在嘗試自動安裝Java來設置新機器。 我打算將java下載到網絡上的目錄,並讓腳本從那裏安裝。 我希望腳本確定32位和64位安裝程序,而不必每次下載新的安裝程序時更改腳本。Vbscript安裝最新的Java版本

我該如何去用通配符運行文件路徑?

這裏是我迄今爲止

這就決定了建築

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 

回答

2

不支持通配符。您需要枚舉這些文件,例如像這樣:

Set fso = CreateObject("Scripting.FileSystemObject") 

For Each f In fso.GetFolder("\\fs1\IT\Scripts\Java").Files 
    If LCase(Left(f.Name, 4)) = "jre-" Then 
    If InStr(1, GetArch, "64") > 0 Then 
     If LCase(Right(f.Name, 8)) = "-x64.exe" Then runExec f.Path, True 
    ElseIf InStr(1, GetArch, "86") > 0 Then 
     If LCase(Right(f.Name, 9)) = "-i586.exe" Then runExec f.Path, True 
    End If 
    End If 
Next 

不過你可以使用不同的方法。由於您要下載並提供共享文件,因此您可以修改配置以創建/更新具有固定名稱的符號鏈接到各個文件,例如

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

,然後在你的安裝腳本使用這些固定名稱:

If Instr(1, GetArch, "64") > 0 then 
    runExec "\\fs1\IT\Scripts\Java\jre-CURRENT-x64.exe", True 
ElseIf Instr(1, GetArch, "86") > 0 then 
    runExec "\\fs1\IT\Scripts\Java\jre-CURRENT-x86.exe", True 
End If 
相關問題