/build/static/layout/Breadcrumb_cap_w.png

VBS to perform backup of folder in user profile

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
Next

If you could help me get my theory in a script that would be greatly appreciated :)

0 Comments   [ + ] Show comments

Answers (4)

Posted by: anonymous_9363 9 years ago
Red Belt
1
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.
Posted by: lordmarte 3 years ago
White Belt
0

At top of your script place this 2 lines:

Dim strLocalPC

strLocalPC = "."

....

at bottom this line:

Wscript.Echo strSubPath


Then start your script in Administrator Command Prompt : wscript /nologo script.vbs


Z


Hope this helps you.


Posted by: EdT 9 years ago
Red Belt
0
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.

Comments:
  • 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. - gmassamo 9 years ago
Posted by: anonymous_9363 9 years ago
Red Belt
0
>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.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ