Good morning,
I'm very new to VBS and I need to create a script that locates if a folder is present under the %userprofile% and if so performs a backup of it just adding a .old in the end of the name. I know how to do this with an active setup, but I was told it is not a good idea to use an active setup for this since we wouldn't be sure the folder was properly backed up.
So I was thinking I could read the users profiles from [HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList], get the list of profiles from there and do a while loop checking if the folder exists and if not, perform a backup of it .
I found this script for the first part but I don't really know how to go from there:

Const HKEY_LOCAL_MACHINE = &H80000002
Set objRegistry=GetObject("winmgmts:\\" & strLocalPC & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
For Each objSubkey In arrSubkeys
strValueName = "ProfileImagePath"
strSubPath = strKeyPath & "\" & objSubkey
objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue

If you could help me get my theory in a script that would be greatly appreciated :)
0 Comments   [ + ] Show Comments


Please log in to comment

Community Chosen Answer

I just Googled 'VBS backup user profile'. Take your pick but the 'Windows 7 Migrate User Profiles' hit on StackOverflow looks like a good place to start.
Answered 09/15/2015 by: VBScab
Red Belt

Please log in to comment


Couple of questions:
1. Do you use roaming profiles?  If so, the profile list may not be accurate.
2. What account will be running your code?
3. Your code is incomplete as the variable strLocalPC is unspecified. Generally it should be set to * - have a look at other code which uses the GetObject("winmgmts:\\" & strLocalPC & "\root\default:StdRegProv") method.
4. You will need to ignore the standard local accounts such as default user.

You could use a login script to do this work - assuming your environment has these.
Answered 09/14/2015 by: EdT
Red Belt

  • thank you EdT
    1. no, we don't use roaming profiles
    2. The script will be distributed by SCCM, so the system account will run the code.

    thank you, after I entered this question I read some articles and made some changes to the script, but I'm still stuck in the same part.

    unfortunately we don't have login scripts in this environment.
Please log in to comment
>I know how to do this with an active setup
Really? How? Active Setup is merely a mechanism to trigger the running of a script or executable.

Moving on...there are a quadzillion scripts around which walk a folder tree. Find another one which will copy a folder's content and another which will rename a folder and combine them.

In order to be sure that the backup succeeded, you might want to do something like creating a hash value for the source and destination folders and comparing them. If they differ, it's likely that the backup failed.
Answered 09/15/2015 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity