Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BackupMyDocs script and username 1

Status
Not open for further replies.

elmurado

IS-IT--Management
Jul 15, 2003
673
AU
Hi, I have a script that seems to work fine but I have a particular problem.
On our workstations, user profiles are in the form username.domainname
eg for Michael Smith;
smith_m.mydomain

So this would be the name of the folder that appears under c:\documents and settings\smith_m.mydomain\my documents

How can I modify this script to reflect that?
---------------
Option Explicit

Dim objFSO, objWSH, strMyDocs, strUserName

Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set objWSH = Wscript.CreateObject("WScript.Shell")

strUserName = objWSH.ExpandEnvironmentStrings("%username%")
If strUserName = "" Then
WScript.Echo("Unable to get %username%")
WScript.Quit 1
End if

strMyDocs = ("c:\documents and settings\%username%\MyDocuments")

If (objFSO.FolderExists(strMyDocs)) Then
objFSO.CopyFolder strMyDocs, "\\backup server\user folders\" & strUserName & "\My Documents"
Else
WScript.Echo("Unable to locate folder")
WScript.Quit 1
End if

Set objFSO = Nothing

Wscript.Quit 0


------------------------------

TIA
 
No special measure has to be taken, only to respect the correct syntax.
>strMyDocs = ("c:\documents and settings\%username%\MyDocuments")
[tt]strMyDocs = "c:\documents and settings\" & strUserName & "\MyDocuments"[/tt]
 
But when i do it like that, if the user has a folder called smith_m and a folder called smith_m.mydomain then the script tries to copy the \smith_m\My documents folder(which is a 'local' folder/profile, rather than the 'domain' profile eg \smith_m.mydomain\My documents).
Hope that makes sense.
Sorry about the brackets-I was trying this and forgot to delete them;

strMyDocs = "c:\documents and settings\" & strUserName.mydomain & "\MyDocuments"

I even tried adding it to the
strUserName = objWSH.ExpandEnvironmentStrings("%username%") & .mydomain

But that is wrong too.
maybe I need something to enumerate the user in a better way and link to the user's folder?
 
I may not understand. Is this what you mean?
[tt]
sdomain="mydomain" 'real name on the right=hand side
strMyDocs = "c:\documents and settings\" & strUserName & "." & sdomain & "\MyDocuments"
[/tt]
 
That looks like it-so I just need to declare the sdomain where I would declare any other strings? Simple. Doh. Will try it after I stop banging my forehead with the palm of my hand....
 
And why not simply this ?
strMyDocs = objWSH.SpecialFolders("MyDocuments")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV-I might try that as the
----
sdomain="mydomain" 'real name on the right=hand side
strMyDocs = "c:\documents and settings\" & strUserName & "." & sdomain & "\MyDocuments"
------
Gives me an Unable to locate folder....hmm...
Cheers
 
Couldn't you use:

strMyDocs = "c:\documents and settings\" & strUserName & ".domain\MyDocuments"

I think PHV's answer is your best bet though.

Alex
 
I guess it may not be the best method, but there isn't any mystery below it. If it cannot find the directory, it is either the path is wrong or there isn't physically the directory. How about echo out and see what it gives?
[tt] wscript.echo strMyDocs [/tt]
Do you see it exactly what you intend it be?
 
Okay. I am officially stupid.
Spot the difference here:

MyDocuments
My Documents

Taa-daa! Thanks guys.
 
Final question on this. How can I show progress or show a completed dialog box when the process is finished?
 
If I just add WSCript.Echo("Backup Complete") at the end of the script here:
-------
If (objFSO.FolderExists(strMyDocs)) Then
objFSO.CopyFolder strMyDocs, "\\backup server\user folders\" & strUserName & "\My Documents"
Else
WScript.Echo("Unable to locate folder")
WScript.Quit 1
End if
WSCript.Echo("Backup Complete")

Set objFSO = Nothing

Wscript.Quit 0
---------------
Does that mean it will show backup Complete at the end of the copy. I'm guessing I could have some code to do some more robust error checking(like diff or comp?) and then pass the errors or validation to the final message box?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top