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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving My docs to server location, but Need help getting usename

Status
Not open for further replies.

evans17

MIS
Feb 5, 2004
75
US
This all works for most users except those that have accounts like:

user.machine
user.Domianname

How can I pull that info??


Set wshNetwork = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set WSHShell = WScript.CreateObject("WScript.Shell")
strUser = WshNetwork.UserName
strDest = "\\server\home\" & strUser
strSource = "C:\Documents and Settings\" & strUser & "\My Documents\*"

On Error Resume Next

RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\"
RegLocate2 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal"
bKey = WSHShell.RegRead (RegLocate2)

wscript.echo

'if bKey = "\\eng-rsbiz\home\%username%" then
' WScript.exit
'End if

'WSHShell.RegDelete RegLocate & "Personal"
'WSHShell.RegDelete RegLocate & "My Pictures"

'WSHShell.RegWrite RegLocate & "Personal", "\\eng-rsbiz\home\%username%", "REG_EXPAND_SZ"
'WSHShell.RegWrite RegLocate & "My Pictures", "\\eng-rsbiz\home\%username%\My Pictures", "REG_EXPAND_SZ"

'fso.CopyFile strSource, strDest
'fso.CopyFolder strSource, strDest
 
Try this.
[tt]'fso.CopyFile strSource, strDest & "\"[/tt]
 
This si what I did. Any better ideas?


If fso.FolderExists("C:\Documents and Settings\" & strUser & ".DOMAINNAME") Then
strSource = "C:\Documents and Settings\" & strUser & ".DOMAINNAME\My Documents\*"
Else
strSource = "C:\Documents and Settings\" & strUser & "\My Documents\*"
End If
 
We don't know where is the problem yet?
 
When I get the user name using the

strUser = WshNetwork.UserName

It does not look at the machine profile. At one point all users had local profiles. Now with Domian profiles, some of the older machines MY DOCS are in a profle where the user.DomainName is the current profile not the username folder. I am using the IF statement cause I did not know how to pull the info of what the profle folder is called on the local machine so I can Copy there MY DOCs.
 
And what about WshShell.SpecialFolders("MyDocuments") ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
evans17,

Username with a dot inside seems okay in principle. Does the script error out if you take out the "On error resume next"? (Why is it there?)

- tsuji
 
HHHmmmm. Yes that might just work.

Code looks like this now.

Set wshNetwork = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set WSHShell = WScript.CreateObject("WScript.Shell")
strUser = WshNetwork.UserName
strDest = "\\eng-rsbiz\home\" & strUser
strSource = WshShell.SpecialFolders("MyDocuments") & "\*"

On Error Resume Next

RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\"
RegLocate2 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal"
bKey = WSHShell.RegRead (RegLocate2)

if bKey = "\\eng-rsbiz\home\%username%" then
WScript.exit
End if

WSHShell.RegDelete RegLocate & "Personal"
WSHShell.RegDelete RegLocate & "My Pictures"

WSHShell.RegWrite RegLocate & "Personal", "\\eng-rsbiz\home\%username%", "REG_EXPAND_SZ"
WSHShell.RegWrite RegLocate & "My Pictures", "\\eng-rsbiz\home\%username%\My Pictures", "REG_EXPAND_SZ"

fso.CopyFile strSource, strDest
fso.CopyFolder strSource, strDest
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top