Link to home
Get AccessLog in
Avatar of chasmant
chasmant

asked on

got 3 scripts can I make it into one script some how

I have 3 scripts attached that buckup reg keys and  folders in a users profile
is there anyway to make this one script? I have one script calling the next
Also is there a way to put that if it gets and error on any of these copy file or reg ket to just go to next


Run-this-one-only-make-backupapp.txt
Export-userdata-for-apps.txt
Backup-OL-QL-and-sig-folder.txt
backup-appdata..txt
Avatar of chasmant
chasmant

ASKER

reason people get error is some don't have these folders or keys  so don't need to copy
Any help would be great ly appreciated  Thanks
Avatar of Chris Bottomley
Assuming        
Run-this-one-only-make-backupapp.txt as a vbs is the first file run, I take it you want all the three other files to run in the order as presented?

Chris
try the attached script.

you can rewrite the handling of errors at each stage.


'------------------EE VB_Script/Q_27048451 ----
'v1  Robberbaron  20.May.2011

Option Explicit
'<<<MAIN ZONE>>>
dim buFolder, part1 , part2, part3 , part4
buFolder = "c:\backupappdata"


part1 = MakeBackupFolder(buFolder)

If part1 Then 
     'was successful
     part2 = ExportRegKeys(buFolder)
End If

If part2 Then 
     'was successful
     part3 = CopyFolders(buFolder)
End If

If part3 Then 
     'was successful
     part4 = BackupFolders(buFolder)
End If

WScript.Echo "Script Results", part1,part2,part3,part4
WScript.Quit

Function MakeBackupFolder(sFolder)

	Dim objFSO, objFolder,  bExitVal
	
	bExitVal = false
	
	' Create FileSystemObject. So we can apply .createFolder method
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	
	Err.Clear
	On Error Resume next
	' Here is the key line Create a Folder, using strDirectory 
	Set objFolder = objFSO.CreateFolder(sFolder)
	If Err.Number = 0 then 
	    'all ok as err58 = already exists
		bExitVal = True
		WScript.Echo "Just created " & sFolder 
	 ElseIf Err.Number=58 Then
	    'all ok as err58 = already exists
		bExitVal = True
		WScript.Echo "Already exists " & sFolder 
		
		'<<<< does this need to be cleaned out so that reg export works ?
	 Else
	 	MsgBox "error" & Err.Number
	End if

	MakeBackupFolder = bExitVal
End Function

Function ExportRegKeys(sFolder)

	Dim wshShell, strOutputDir, bExitVal
	
	bExitVal = false
	
	Set wshShell = CreateObject("WScript.Shell")
	strOutputDir = sFolder & "\"
	Err.Clear
	On Error Resume next	
	wshShell.Run "Regedit /E """ & strOutputDir & "adobe.reg"" ""HKEY_CURRENT_USER\software\adobe"""
	wshShell.Run "Regedit /E """ & strOutputDir & "ipswitch.reg"" ""HKEY_CURRENT_USER\software\ipswitch"""
	wshShell.Run "Regedit /E """ & strOutputDir & "business_objects.reg"" ""HKEY_CURRENT_USER\software\business objects"""
	wshShell.Run "Regedit /E """ & strOutputDir & "IDM_Computer_Solutions.reg"" ""HKEY_CURRENT_USER\software\IDM Computer Solutions"""
	wshShell.Run "Regedit /E """ & strOutputDir & "printers.reg"" ""HKEY_CURRENT_USER\Printers"""
	wshShell.Run "Regedit /E """ & strOutputDir & "Networks.reg"" ""HKEY_CURRENT_USER\Network"""
	wshShell.Run "Regedit /E """ & strOutputDir & "ipswitch.reg"" ""HKEY_CURRENT_USER\software\Business Objects"""
	If Err.Number = 0 Then 
		bExitVal = True
		WScript.Echo "Export Complete 2!"
	 else
	 	MsgBox "errorER=" & Err.Number
	
	End if

	ExportRegKeys = bExitVal
End Function


Function CopyFolders(sFolder)

	Dim objFSO, objFolder, WshShell, strDirectory, bExitVal
	Dim srcFolder, strSrcRoot, TargetFolder, i

	Set WshShell = WScript.CreateObject("WScript.Shell") 
	strSrcRoot = WshShell.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\"

	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Dim MovFolders(2)
	
	MovFolders(0) = "Outlook"
	MovFolders(1) = "Internet Explorer"
	MovFolders(2) = "Signatures"
	
	bExitVal = 0
	'use ubound to make it easier to add folders to list
	for i = 0 to UBound(MovFolders)
		srcFolder = strSrcRoot & MovFolders(i)
		TargetFolder = sFolder & "\" & MovFolders(i)
		objFSO.CopyFolder srcFolder, TargetFolder
		If Err.Number = 0 Then 
			bExitVal = bExitVal + 1   'count the successes
			WScript.Echo "Copy done MF" & i
		 Else
		 	WScript.Echo "Copy FAIL MF" & i
		 	MsgBox "errorER=" & Err.Number
				
		End if
	Next 

	If bExitVal = UBound(MovFolders)+1 Then
		bExitVal = True
		WScript.Echo "Just created " & strDirectory 
	 Else 
	 	bExitVal = false
	End if
	CopyFolders = bExitVal
End Function


Function BackupFolders(sFolder)

	Dim objFSO, objFolder, WshShell, strDirectory, bExitVal
	Dim srcFolder, strSrcRoot, TargetFolder, i

	Set WshShell = WScript.CreateObject("WScript.Shell") 
	strSrcRoot = WshShell.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\"

	Set objFSO = CreateObject("Scripting.FileSystemObject")
	
	Dim MovFolders(3)
	
	MovFolders(0) = "Business Objects"
	MovFolders(1) = "Ipswitch"
	MovFolders(2) = "IDMComp"
	MovFolders(3) = "Adobe"
	
	bExitVal = 0
	'use ubound to make it easier to add folders to list
	for i = 0 to UBound(MovFolders)
		srcFolder = strSrcRoot & MovFolders(i)
		TargetFolder = sFolder & "\" & MovFolders(i)
		On Error Resume next
		objFSO.CopyFolder srcFolder, TargetFolder
		'is this needed? is CopyFolder syncronous
		MsgBox "Wait for the DONE May take a while!", vbInformation + vbSystemModal, "Export" 
		WScript.Sleep 5000		
		If Err.Number = 0 Then 
			bExitVal = bExitVal + 1   'count the successes
			WScript.Echo "Copy done BF" & i
		  Else
		  	WScript.Echo "FAIL copy BF" & i
		End if
	Next 

	If bExitVal = UBound(MovFolders)+1 Then
		bExitVal = True
		WScript.Echo "Backup Folders Done" 
	 Else 
	 	bExitVal = false
	End if

	BackupFolders = bExitValjavascript:void(0);
End Function

Open in new window

getting this error
error.jpg
got it to work by removing  ;
      BackupFolders = bExitValjavascript:void(0);
New       
BackupFolders = bExitValjavascript:void(0)
could you help also with the restore of these? Basically putting everything back where it was. I tried but I guess I am just to much of a rokkie
I really appreciate it
If you would like I can put the restore as another question
The  javascriptvoid is an error inthe way you saved my script
Apologies  !!  the error is on my posting.

should be     BackupFolders = bExitVal

probably should ask a related question regarding restore as it likely raises a new set of issues regarding permissions with Vista & W7.  post what you have done and what errors you get.  asking for help with something you have already tried is far more likely to get assistance that "please do this....."
Thanks robberaron
Got all errors taken care of  now just need to be able to reverse it and put the folders and reg keys back. I looked through script but not sure how I can do this. Any help would be great
ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
thanks  this helped a Lot!