'Ranger Package Installer 'Copyright (c) http://ccgi.maxpower.plus.com 'This will install a Ranger software package onto a machine. 'This script is not provided with any warranty implied or otherwise - use at your own risk! On Error Resume Next Dim strConn, conn, rs Const ForReading = 1, ForWriting = 2, ForAppending = 8 Const rWindir = "" Const rWinSysDir = "" Const rRangerDir = "" Const rProfileDir = "" Const rAllUsersDir = "" Const rTempDir = "" Const rSysDrive = "" if Wscript.Arguments.Count > 0 Then 'Fire up FileSystemObject Set objFSO = CreateObject("Scripting.FileSystemObject") 'Fire up the scripting shell - we're running some progs Set objShell = CreateObject("WScript.Shell") 'Enumerate the passed in file names For i = 0 to wscript.arguments.count - 1 'Get file If objFSO.FileExists(strArgs) Then strArgs = WScript.Arguments(i) Set objFile = objFSO.GetFile(strArgs) ElseIf objFSO.FileExists(WScript.Arguments(i) & "\filediff.txt") Then strArgs = WScript.Arguments(i) & "\filediff.txt" Set objFile = objFSO.GetFile(strArgs) Else MsgBox ("This isn't a valid package file or folder. Can't carry on.") WScript.quit End If 'wscript.echo objFile.path 'Get parent folder and file names installFolder = objFSO.GetParentFolderName(objFile) installFile = objFSO.GetFileName(objFile) 'wscript.echo installFolder 'wscript.echo installFile objFile.Close 'Now get the substitutions Set objConfigFile = objFSO.OpenTextFile(installFolder & "\Info.ini") 'wscript.echo objConfigFile.path Do Until objConfigFile.AtEndOfStream strInfo = objConfigFile.ReadLine if Left(strInfo, Len("")) = "" Then strWindir = Mid(strInfo,InStr(strInfo,"=")+1) if Left(strInfo, Len("")) = "" Then strWinSysDir = Mid(strInfo,InStr(strInfo,"=")+1) if Left(strInfo, Len("")) = "" Then strRangerDir = Mid(strInfo,InStr(strInfo,"=")+1) if Left(strInfo, Len("")) = "" Then strProfileDir = Mid(strInfo,InStr(strInfo,"=")+1) if Left(strInfo, Len("")) = "" Then strAllUsersDir = Mid(strInfo,InStr(strInfo,"=")+1) if Left(strInfo, Len("")) = "" Then strTempDir = Mid(strInfo,InStr(strInfo,"=")+1) if Left(strInfo, Len("")) = "" Then strSysDrive = Mid(strInfo,InStr(strInfo,"=")+1) Loop Set objFile = objFSO.OpenTextFile(strArgs) Do Until objFile.AtEndOfStream strCommand = objFile.ReadLine arrCommand = Split(strCommand,"|") 'Now run the various functions 'Replace the string with the actual path strTargetPath = strReplacer(arrCommand(1)) strSourcePath = strSourceRep(arrCommand(1)) if arrCommand(0) = "+f" or arrCommand(0) = "+fc" Then 'Copy file 'wscript.echo "Copy " & installFolder & "\CopyRoot" & "\" & strSourcePath & " to" 'wscript.echo strTargetPath GenPath (strTargetPath) if objFSO.FileExists(installFolder & "\CopyRoot" & "\" & strSourcePath) Then objFSO.CopyFile installFolder & "\CopyRoot" & "\" & strSourcePath, strTargetPath, true End If ElseIf arrCommand(0) = "-f" Then 'Delete File 'wscript.echo "Delete " & strTargetPath if objFSO.FileExists(strTargetPath) Then objFSO.DeleteFile strTargetPath,true End If ElseIf arrCommand(0) = "+d" Then 'Create Directory 'wscript.echo "Create folder: " & strTargetPath If Not objFSO.FolderExists(strTargetPath) Then GenPath (strTargetPath) End If ElseIf arrCommand(0) = "-d" Then 'Delete Directory If objFSO.FolderExists(strTargetPath) Then objFSO.DeleteFolder strTargetPath,true End If 'wscript.echo "Delete folder: " & strTargetPath End If Loop 'Now we can make the registry changes 'Let's enumerate the install folder and get the registry files Set objFolder = objFSO.GetFolder(installFolder) Set colFiles = objFolder.Files 'We'll fire up a new reg file for good measure... We're going to combine all of the registry tweaks in one strRegFile = installFolder & "\installreg.reg" 'wscript.echo "Creating new .REG file... " & strRegFile Set objRegFile = objFSO.CreateTextFile(strRegFile, True, True) 'Write RegEditor info objRegFile.WriteLine("Windows Registry Editor Version 5.00") 'wscript.echo "Searching for .rrg files in " & installFolder For Each objFile in colFiles 'Find .rrg files and put the content into our new reg file if lcase(objFSO.GetExtensionName(objFile)) = "rrg" Then Set newRegFile = objFSO.OpenTextFile(objFile.Path, ForReading) Do While newRegFile.AtEndOfStream <> True objRegFile.WriteLine(newRegFile.ReadLine) Loop newRegFile.close End If Next objRegFile.close 'Now import the regstry file 'wscript.echo "reg import " & chr(34) & installFolder & "\installreg.reg" & chr(34) objShell.Exec("reg import " & chr(34) & installFolder & "\installreg.reg" & chr(34)) 'Now delete the registry file objFSO.DeleteFile installFolder & "\installreg.reg",true msgbox("Package installation complete") Next Else msgbox("You must select a file to install. Drag either a filediff.txt file or the package folder onto the script to install.") End If Function strReplacer (strLine) strLine = Replace(strLine,rWinDir,strWinDir) strLine = Replace(strLine,rWinSysDir,strWinSysDir) strLine = Replace(strLine,rRangerDir,strRangerDir) strLine = Replace(strLine,rProfileDir,strProfileDir) strLine = Replace(strLine,rAllUsersDir,strAllUsersDir) strLine = Replace(strLine,rTempDir,strTempDir) strLine = Replace(strLine,rSysDrive,strSysDrive) strReplacer = strLine End Function Function strSourceRep (strLine) strLine = Replace(strLine,rWinDir,"C\WINDOWS") strLine = Replace(strLine,rWinSysDir,"C\WINDOWS\SYSTEM32") strLine = Replace(strLine,rRangerDir,strRangerDir) strLine = Replace(strLine,rProfileDir,strProfileDir) strLine = Replace(strLine,rAllUsersDir,strAllUsersDir) strLine = Replace(strLine,rTempDir,strTempDir) strLine = Replace(strLine,rSysDrive,strSysDrive) strSourceRep = Replace(strLine,":","") End Function Function GenPath (rFolderPath) 'Gets the parent folder of a non-existant path and calls Generate Path to create the tree. arrPath = Split(rFolderPath,"\") rFolderPath = "" for iindex = 0 to ubound(arrPath) - 1 rFolderPath = rFolderPath & arrPath(iindex) & "\" Next GeneratePath(left(rFolderPath,len(rFolderPath)-1)) End Function Function GeneratePath(pFolderPath) 'Recursive function to create a folder path 'wscript.echo "Creating " & pFolderPath GeneratePath = False If Not objFSO.FolderExists(pFolderPath) Then If GeneratePath(objFSO.GetParentFolderName(pFolderPath)) Then GeneratePath = True Call objFSO.CreateFolder(pFolderPath) End If Else GeneratePath = True End If End Function