You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
6.3 KiB
Plaintext

Option Explicit
Dim wshshell,fso,i,Fnct
Dim strPath,strSystemFolder,strWinFolder,strTempFolder
'----------------------------- Objekte erzeugen --------------------------------
i = 0
On Error Resume Next
Do
err.Clear
i = i+1
Set wshshell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set Fnct = CreateObject("Install.Functions")
WScript.Sleep 1000
Loop Until Err.Number = 0 OR i > 30
If Err.Number <> 0 Then
WScript.Quit
End If
On Error Goto 0
'--------------------------- Standardpfade -------------------------------------
strPath = GetCurrentPath()
strSystemFolder = fso.GetSpecialFolder(1) & "\"
strWinFolder = fso.GetSpecialFolder(0) & "\"
strTempFolder = fso.GetSpecialFolder(2) & "\"
'------------------------------ Main -------------------------------------------
WriteToLog("Start")
Dim strSarDir
strSarDir = ExpandPath("%SAR_DIR%","c:\SaveAndRestore")
On Error Resume Next
If fso.FolderExists("d:\Backup\Drivers") And Not fso.FolderExists("c:\SaveAndRestore") Then
Call fso.DeleteFolder("d:\Backup\Drivers",True)
End If
err.Clear
On Error Goto 0
Dim strEloFolder, strEloBackupFolder
strEloFolder = "d:\Backup\drivers\elo"
strEloBackupFolder= strTempFolder & "ELO"
If fso.FolderExists(strEloFolder) Then
On Error Resume Next
Call fso.CopyFolder(strEloFolder,strEloBackupFolder,True)
Call fso.deleteFolder(strEloFolder,True)
On Error Goto 0
End If
Dim strLogFile
strLogFile = strTempFolder & "SaveAndRestoreInstall.log"
Call InstallMsiFile(strPath & "SaveAndRestore_xp\SaveAndRestore.msi", strLogFile)
wscript.Sleep 3000
On Error Resume Next
Call fso.MoveFile(strLogFile, strTempFolder & "SaveAndRestoreInstall_1st.log")
On Error Goto 0
Call InstallMsiFile(strPath & "SaveAndRestore_xp\SaveAndRestore.msi", strLogFile)
If Not fso.FolderExists(strEloFolder) Then
On Error Resume Next
Call fso.CopyFolder(strEloBackupFolder,strEloFolder,True)
On Error Goto 0
End If
If fso.FolderExists(strEloBackupFolder) Then
On Error Resume Next
Call fso.Deletefolder(strEloBackupFolder,True)
On Error Goto 0
End If
Call wshshell.Run("""" & strSarDir & "\InstallationHelpFiles\DhcpFw.bat""",1,True)
Call wshshell.Run("""" & strSarDir & "\InstallationHelpFiles\FtpFw.bat""",1,True)
Call wshshell.Run("""" & strSarDir & "\InstallationHelpFiles\SaveAndRestoreFw.bat""",1,True)
Call wshshell.Run("""" & strSarDir & "\InstallationHelpFiles\StartDhcp.vbs""",1,True)
Dim scut
Dim strPrograms
strPrograms=wshshell.SpecialFolders(2)
set scut = wshshell.CreateShortcut(strPrograms & "\SaveAndRestore.lnk")
scut.TargetPath = "c:\SaveAndRestore\SaveAndRestore.exe"
scut.Arguments = ""
scut.Save
Set scut = nothing
Dim strDesktop
strDesktop=wshshell.SpecialFolders(0)
set scut = wshshell.CreateShortcut(strDesktop & "\SaveAndRestore.lnk")
scut.TargetPath = "c:\SaveAndRestore\SaveAndRestore.exe"
scut.Arguments = ""
scut.Save
Call ChangeLaserToPrinter01()
WriteToLog("End")
'------------------------------- Funktionen ------------------------------------
Function GetCurrentPath()
Dim l_strScriptName
Dim l_strTemp
l_strScriptName = WScript.ScriptFullName
l_strTemp = WScript.ScriptName
GetCurrentPath = Left(l_strScriptName, Len(l_strScriptName) - Len(l_strTemp))
End Function
Function ExpandPath(p_strEnvironment,p_strDefault)
Dim l_strTemp
l_strTemp = wshshell.ExpandEnvironmentStrings(p_strEnvironment)
If l_strTemp = p_strEnvironment Then
l_strTemp = p_strDefault
End If
ExpandPath = l_strTemp
End Function
'------------------------------ Sub -------------------------------------------
'Installiert eine MSI-datei im Silent Modus und verhindert einen Neustart
Sub InstallMsiFile(p_strMsiFile,p_strLogFile)
Dim i
Dim strFileContent
Dim bResult
Dim LogFile
Dim l_strLogFile
l_strLogFile = Replace(p_strLogFile,"""","")
wshshell.Run("msiexec.exe /qn DISABLEADVTSHORTCUTS=1 MACHINE=1 /l* " & p_strLogFile & " /i " & p_strMsiFile & " REBOOT=ReallySuppress")
i = 0
do
bResult = False
WScript.Sleep 1000
strFileContent = ""
If fso.FileExists(l_strLogFile) Then
On Error Resume Next
Set LogFile = fso.OpenTextFile(l_strLogFile,1,false,-1)
if(err.Number = 0) Then
strFileContent = LogFile.ReadAll
LogFile.Close
Else
strFileContent = ""
End If
bResult = Instr(strFileContent,"=== Logging stopped:") > 0
If Not bResult Then
bResult = Instr(strFileContent,"=== Protokollierung beendet:") > 0
End If
If Not bResult Then
bResult = Instr(strFileContent,"-- Configuration failed.") > 0
End If
err.Clear
On Error Goto 0
End If
err.Clear
i = i+1
loop until (bResult = True) Or (i >300)
WriteToLog("Duration: " & i)
End Sub
Sub WriteToLog(p_strMessage)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim strLineToWrite
strLineToWrite = WScript.ScriptName & " -- " & p_strMessage
Dim strLogFile
strLogFile = ExpandPath("%SERVICEPACK_LOG%","c:\fockeservicepack.log")
' msgbox sLine & LogFile
Dim FileObject
if fso.FileExists(strLogFile) then
set FileObject = fso.OpenTextFile( strLogFile,ForAppending,false,0)
else
set FileObject = fso.OpenTextFile( strLogFile,ForWriting, true,0)
end if
FileObject.WriteLine(strLineToWrite)
FileObject.Close
set FileObject=nothing
End Sub
Sub ReadReplaceWriteFile(p_strFile, p_strSearchText, p_strReplacement)
Dim strCurrentFileContent
Dim CurrentFile
Set CurrentFile = fso.OpenTextFile(p_strFile)
strCurrentFileContent = CurrentFile.ReadAll()
Call CurrentFile.Close()
If Instr(strCurrentFileContent,p_strReplacement) <> 0 Then Exit Sub
strCurrentFileContent = Replace(strCurrentFileContent,p_strSearchText, p_strReplacement, 1, -1, 1)
Set CurrentFile = fso.OpenTextFile(p_strFile,2)
Call CurrentFile.Write(strCurrentFileContent)
Call CurrentFile.Close()
End Sub
Sub ChangeLaserToPrinter01
Dim strMainVolume,strComputerIni
strMainVolume = ExpandPath("%MAIN_VOLUME%","c:\")
strComputerIni = strMainVolume & "Computer.ini"
Call ReadReplaceWriteFile(strComputerIni, "Laser", "Printer01")
Dim strSarIni
strSarIni = strSarDir & "\SaveAndRestore.ini"
Call ReadReplaceWriteFile(strSarIni, "[Laser]", "[Printer01]")
Call ReadReplaceWriteFile(strSarIni, "=Laser", "=Printer01")
Call ReadReplaceWriteFile(strSarIni, "ServerConnections=SatorLaser", "ServerConnections=SatorLaser1(T+DSL)")
End Sub