Although this site is not about coding, I thought I would share some of the code I eventually figured out after looking online and having a hard time finding exactly what I was looking for.
Perhaps it was the way (terms) I searched Google, but I found it hard to find what I thought would be pretty common code.
I am not a coder / programmer by any means. So I use books and Google.
I usually have to edit the code I find to suite my needs because I might find something close to what I want but not exactly.
Obviously, there is no licensing since most of it is basic and available in many places, and I just put it together.

Backup user data with prompts
This is a VBscript (Visual Basic script) with source and destination prompts to backup user data with Robocopy.
The default source is the users Profile directory. It will copy everything like Documents, Pictures, Favorites… except the AppData folder and other hidden folders.
*Oh, it seems hard to copy Chrome and Firefox bookmarks, So I have separate code to copy their profile folders. see next code for them. 
It will create the destination folder if needed or quit if the destination folder already exists to not over write other backups. I chose this option because I usually use last names as the destination folder, and you can easily have multiple people with the same last name – or other reasons…

You can include AppData  by removing the /XD AppData switch.


Dim objFSO
Set objShell = CreateObject(“Wscript.Shell”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”) ‘Standard File System Object

Call ElevateThisScript()
Sub ElevateThisScript()

objSource = InputBox(“Add the SSO to complete source location”, “Backup”, “C:\users\”)

objDestination = InputBox(“Enter the Destination directory path. Backup will begin”, “Backup Destination”, “D:\”)
If objFSO.FolderExists(objDestination) Then
Wscript.Echo “That folder already exists. Quiting. Create/ use a new folder”
WScript.Quit

Else
objFSO.CreateFolder(objDestination) ‘Create the backupdoc folder
End If

objShell.Run( “cmd.exe /k robocopy.exe ” & Chr(34) & objSource & Chr(34) &” ” & Chr(34) & objDestination & Chr(34) & ” /MIR /XA:SH /XD AppData /XJD /R:1 /W:1″)

End Sub

WScript.Echo “Backup in progress! – REMINDER get .PST files. Confirm BOX files. Ask user about other folders and bookmarks”


Restore user data
Here is the code to restore the files to the new computer. Also with prompts. you will want to run this while logged into the user account, or have the account created.


‘Restoere Files  Script
‘Declarations
Dim BackupDriveLetter, WshNetwork, strUser, objShell, objFSO
Dim spath, dpath, s0
Set WshNetwork = WScript.CreateObject(“WScript.Network”)  ’Standard Network Object
Set objShell = CreateObject(“WScript.Shell”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”) ’Standard File System Object

spath = InputBox(“Backup drive folder for source locatoin”, ”Restore to PC”, ”D:\”)’Source Path we will be copying

s0 = ”/MIR ” ’ Restore switches for Robocopy, mirror

‘Asks to start the backup
X=MsgBox(spath,36,”Confirm Source path”)
If X = 6 Then ’If MsgBox is answered YES

StartBackup() ’Start main Subroutine
Else
X=MsgBox(“Choose correct source location and try again ”,48,”Error”)
WScript.Quit ’If MsgBox is answered NO
End If

‘Main Program ****************************************
Sub StartBackup()

‘ Check to see if the My Documents Path exists
dpath = InputBox(“Enter the Destination directory path. Restore will begin”, ”Restore Destination”, ”C:\Users\”)
If objFSO.FolderExists(dpath) Then
Wscript.Echo ”The user does exists.”
Else
X=MsgBox(“No such user. Choose correct SSO or destination and try again ”,48,”Error”)
WScript.Quit ’If MsgBox is answered NO
End If

objShell.Run( ”cmd.exe /k robocopy.exe ””” & spath & ””” ””” & dpath & ””” ” & s0 )

End Sub

Wscript.Echo ”Restore in progress. REMINDER get .PST files. Confirm BOX files. and bookmarks”


 

Chrome and Firefox bookmarks location and backup.
Chrome and Firefox bookmarks are kept in the AppData folder, and it seems to be hard to copy them automatically with prompts for username’s. So for  now I manually copy the file/folder they are in. It’s actually faster then editing the code each time.
*If you can get into the users logon, it is best to export them.


Firefox:   C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles
Then you need to go into the randomly created profile name \bookmarkbackups\
Then copy the most recent .jsonlz4  file.

Chrome:  C:\Users\username\AppData\Local\Google\Chrome\User Data\Default\bookmarks     file with no extention.
you can also get bookmarks.bak if you want.


 

Network drives and Printers export
It also seems hard to make a code to export printers and mapped drives, but if you
copy and paste these into a command line cmd box, you can get the registry file to then double click on and import into the new PC.


Network mapped drives:       reg export HKEY_CURRENT_USER\Network C:\netdrives.reg

Network Printers :                   reg export HKEY_CURRENT_USER\Printers C:\printers.reg


 

Erase temp files or other files. 
Robocopy can also be used to delete files with the /purge switch.
Where I work our software seems to save temp files like crazy. Gigs and Gigs and more Gigs. Enough to fill a hard drive to have Windows warn the user their C: drive is full.
Here are batch and the VBscript to delete the various temp files and clean the hard drive.
I think the .bat file (has to be run as admin) can delete more files/folders.
You have to edit the .bat with the username (represented by SSO) before running it.
The VBscript prompts for username.


Bat file:
mkdir c:\empty
call robocopy c:\empty c:\temp /purge
robocopy c:\empty c:\tmp /purge
robocopy c:\empty c:\windows\temp /purge
robocopy c:\empty c:\users\SSO\appdata\local\temp /purge
echo “Ask user to empty or clean up Downlods folder? check other users and empty Recycle Bin”
pause


vbscript:
‘Declarations
Dim WshNetwork, strUser, objShell, objFSO
Dim spath, dpath, s0
Set WshNetwork = WScript.CreateObject(“WScript.Network”) ‘Standard Network Object
Set objShell = CreateObject(“WScript.Shell”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”) ‘Standard File System Object

dpath = InputBox(“Enter the user SSO”, “Destination”, “SSO”)
objShell.Run( “cmd.exe /k mkdir c:\empty & robocopy c:\empty c:\temp /purge & robocopy c:\empty c:\tmp /purge & robocopy c:\empty c:\windows\temp /purge &robocopy c:\empty c:\users\”& dpath & “\appdata\local\temp /purge”)
Wscript.Echo “REMINDER empty Recycle Bin, Downloads folder? Check for other users”


 

 

 

 

 

I think I have to approve comments and I don’t always see them quickly, so they might not show up for a while…. If anyone leave any…..

 

 

 

 

Key words: Backup user data. Data backup. Computer backup. User profile backup. Backup my documents. Backup to another computer. Move data to another computer. Robocopy. cmd. command line. chrome bookmarks location export copy. firefox bookmarks location export copy. copy or export network mapped drives and printers. robocopy to delete files.

Advertisements

Posted by Ken Barker

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s