'------------------------------------------------------------------------------- ' (C) Focke & Co ' Date: 9.3.11 ' Author: cbr ' Sortiert die Laufwerksbuchstaben um, weil das USB Medium - je nach ' Vorgehensweise bei der Installation - unterschiedliche Laufwerksbuchstaben ' haben kann. Außerdem taucht mitunter die Boot-Flash aus der Versenkung auf. '------------------------------------------------------------------------------- Option Explicit Dim wshshell,fso,i,Fnct Dim strPath,strSystemFolder,strWinFolder,strTempFolder '----------------------------- Objekte erzeugen -------------------------------- Dim strCurrentObject i = 0 On Error Resume Next Do err.Clear i = i+1 strCurrentObject = "WScript.Shell" Set wshshell = CreateObject("WScript.Shell") strCurrentObject = "Scripting.FileSystemObject" Set fso = CreateObject("Scripting.FileSystemObject") strCurrentObject = "Install.Functions" Set Fnct = CreateObject("Install.Functions") WScript.Sleep 1000 Loop Until Err.Number = 0 OR i > 30 If Err.Number <> 0 Then MsgBox "Unable to Create Object: " & strCurrentObject WScript.Quit End If On Error Goto 0 '--------------------------- Standardpfade ------------------------------------- strPath = GetCurrentPath() strSystemFolder = fso.GetSpecialFolder(1) & "\" strWinFolder = fso.GetSpecialFolder(0) & "\" strTempFolder = fso.GetSpecialFolder(2) & "\" Dim strMainVolume, strComputerIni, strMbDiagValuesIni strMainVolume = ExpandPath("%MAIN_VOLUME%","c:\") strComputerIni = strMainVolume & "Computer.ini" strMbDiagValuesIni = strTempFolder & "MbDiagValues.ini" '------------------------------ Main ------------------------------------------- Call Main() '------------------------------- 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 Function GetVolumeNumberByName(p_strName) Dim DpScript Dim strDpScript strDpScript = strTempFolder & "ListVolumes.txt" Dim strBatchFile, strOutputFile strBatchFile = strTempFolder & "ListVolumes.bat" strOutputFile = strTempFolder & "ListVolumes.log" Dim bFound bFound = false Dim strCurrent Dim loops loops = 0 do Dim OutputFile Dim strCurrentLine Set OutputFile = fso.OpenTextFile(strOutputFile) do until (OutputFile.atEndOfStream Or (bFound = true)) strCurrentLine = OutputFile.ReadLine If Not IsEmpty(strCurrentLine) And Not IsNull(strCurrentLine) Then If (Instr(1,strCurrentLine,p_strName,1) <> 0) Then bFound = (Err.number = 0) Else wscript.Sleep 1000 End If End If Loop loops = loops + 1 Loop Until bFound Or loops > 5 Dim strVolNumber If loops > 5 Then strCurrent = Fnct.GetIniString("FBR","MissingDrives", strMbDiagValuesIni) If strCurrent <> "" Then strCurrent = strCurrent & ";" strCurrent = strCurrent & p_strName Call Fnct.SetIniString("FBR", "MissingDrives", strCurrent, strMbDiagValuesIni) Else strVolNumber = Mid(strCurrentLine,10,1) End If GetVolumeNumberByName = strVolNumber End Function Function IsBackupDriveG Dim strBackupDrives strBackupDrives = Fnct.GetIniString("Backup","BackupDrives",strComputerIni) If (strBackupDrives = "D:\;G:\") OR (strBackupDrives = "D:\;F:\;G:\") OR (strBackupDrives = "D:\;G:\;F:\") Then IsBackupDriveG = true Else IsBackupDriveG = false End If End Function '------------------------------ Sub ------------------------------------------- Sub Main Dim strBackupVolume Dim strDokuVolume Dim strRemovable Call ListVolumes() If Not fso.FolderExists("c:\temp\Visu2000") Then wscript.quit End If Call Fnct.SetIniString("FBR", "MissingDrives", "", strMbDiagValuesIni) Call RemoveBootFlash() Call AssignLostLetters() strBackupVolume = GetVolumeNumberByName("Backup") strDokuVolume = GetVolumeNumberByName("Documenta") strRemovable = GetVolumeNumberByName("Removeable") Dim DpScript Dim strDpScript strDpScript = strTempFolder & "ReassignVolumes.txt" Set DpScript = fso.CreateTextFile(strDpScript,true) If strBackupVolume <> "" AND NOT fso.FolderExists("d:\") Then Call DpScript.WriteLine("select volume " & strBackupVolume) Call DpScript.WriteLine("remove") Call DpScript.WriteLine("ASSIGN LETTER=D") End If If strDokuVolume <> "" AND NOT fso.folderExists ("e:\") Then Call DpScript.WriteLine("select volume " & strDokuVolume) Call DpScript.WriteLine("remove") Call DpScript.WriteLine("ASSIGN LETTER=E") End If If fso.FolderExists("G:\") And Not fso.FolderExists("F:\") And fso.FileExists("G:\FockeBackupData.inf") Then Call DpScript.WriteLine("select volume " & strRemovable) Call DpScript.WriteLine("ASSIGN LETTER=F") End If If IsBackupDriveG() And strRemovable <> "" Then Call Fnct.SetIniString("Backup","BackupDrives","D:\;F:\",strComputerIni) End If DpScript.Close Set DpScript = Nothing Dim DpBatch Dim strOutputFile,strBatchFile strOutputFile = strTempFolder & "ReassignVolumes.log" strBatchFile = strTempFolder & "ListVolumes.bat" Set DpBatch = fso.CreateTextFile(strBatchFile,true) Call DpBatch.WriteLine("Diskpart /s """ & strDpScript & """ > """ & strOutputFile & """") DpBatch.Close Call wshshell.Run("""" & strBatchFile & """", 1,True) End Sub ' Nimmt der Bootflash den Laufwerksbuchstaben weg. Sub RemoveBootFlash Dim strBootVolume strBootVolume = GetVolumeNumberByName("Boot-Flash") Dim DpScript Dim strDpScript strDpScript = strTempFolder & "RemoveBootFlash.txt" Set DpScript = fso.CreateTextFile(strDpScript,true) if strBootVolume <> "" Then Call DpScript.WriteLine("select volume " & strBootVolume) Call DpScript.WriteLine("remove") End If DpScript.Close Set DpScript = Nothing Dim DpBatch Dim strBatchFile,strOutputFile strOutputFile = strTempFolder & "RemoveBootFlash.log" strBatchFile = strTempFolder & "RemoveBootFlash.bat" Set DpBatch = fso.CreateTextFile(strBatchFile,true) Call DpBatch.WriteLine("Diskpart /s """ & strDpScript & """ > """ & strOutputFile & """") DpBatch.Close Call wshshell.Run("""" & strBatchFile & """", 1,True) End Sub ' Laufwerke auflisten Sub ListVolumes Dim DpScript Dim strDpScript strDpScript = strTempFolder & "ListVolumes.txt" Set DpScript = fso.CreateTextFile(strDpScript,true) Call DpScript.WriteLine("list volume") DpScript.Close Set DpScript = Nothing Dim DpBatch Dim strBatchFile, strOutputFile strBatchFile = strTempFolder & "ListVolumes.bat" strOutputFile = strTempFolder & "ListVolumes.log" Set DpBatch = fso.CreateTextFile(strBatchFile,true) Call DpBatch.WriteLine("Diskpart /s """ & strDpScript & """ > """ & strOutputFile & """") DpBatch.Close Set DpBatch = Nothing Call wshshell.Run("""" & strBatchFile & """", 1,True) End Sub ' Falls versehentlich ein Laufwerk den Buchstaben verloren hat, ' wird er hier zugewiesen Sub AssignLostLetters Dim strVolumes(3) Dim strLetters(3) strVolumes(0) = GetVolumeNumberByName("Backup") strVolumes(1) = GetVolumeNumberByName("Documenta") strVolumes(2) = GetVolumeNumberByName("Removeable") strLetters(0) = "D" strLetters(1) = "E" strLetters(2) = "F" Dim DpScript Dim strDpScript Dim strBatchFile, strOutputFile Dim k For k = 0 To 2 If strVolumes(k) <> "" And Not fso.FolderExists(strLetters(k) & ":\") Then strDpScript = strTempFolder & "AssignLostLetters" & k & ".txt" Set DpScript = fso.CreateTextFile(strDpScript,true) Call DpScript.WriteLine("select volume " & strVolumes(k)) Call DpScript.WriteLine("ASSIGN LETTER=" & strLetters(k)) Call DpScript.Close() Dim DpBatch strOutputFile = strTempFolder & "AssignLostLetters" & k & ".log" strBatchFile = strTempFolder & "AssignLostLetters.bat" Set DpBatch = fso.CreateTextFile(strBatchFile,true) Call DpBatch.WriteLine("Diskpart /s """ & strDpScript & """ > """ & strOutputFile & """") DpBatch.Close Call wshshell.Run("""" & strBatchFile & """", 1,True) End If Next End Sub