
Change My Documents Path With VBScript
My current script work to change the users My documents path, the problem
was that it doesn't update until after the user reboot after running the
script:
dim WSHShell, WSHNetwork
dim MyDoc1SubKey, MyDoc2SubKey
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WSHNetwork = WScript.CreateObject("WScript.Network")
MyDoc1SubKey =
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell
Folders\Personal"
MyDoc2SubKey =
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User
Shell Folders\Personal"
WScript.Sleep 3000
NewRegValueMyDoc = "\\file\users$\" & WSHNetwork.Username
WSHShell.RegWrite MyDoc1SubKey, NewRegValueMyDoc
WSHShell.RegWrite MyDoc2SubKey, NewRegValueMyDoc
Are you saying that what you propose below will not require a reboot?
Thanks for all your help guys!
Quote:
> > Ugh, you just went went 1 step beyond my reach. Crash course time!
> > Thanks for your help Torgeir
> I have done this by login script, for some users.
> Basically the relevant registry value is:-
> HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User
> Shell Folders\Personal
> It's type is REG_EXPAND_SZ.
> I've previously had Kixtart scripts, and used the writevalue function to
set
> it to: %HOMESHARE%\My Documents
> If you are using vbscript within a Windows Script Host environment, you
can
> use the wscript.shell object and regwrite method, eg:-
> <start of impromptu script...>
> Dim objEnv,objWSHShell
> Dim strHomeDir
> set objWSHShell=createobject("wscript.shell")
> set objEnv=objWSHShell.environment("process")
> strHomeDir=objEnv("HOMESHARE")
> objWSHShell.regwrite
> "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell
> Folders\Personal",strHomeDir&"\My Documents","REG_EXPAND_SZ"
> set objEnv=nothing
> set objWSHShell=nothing
> <end of impromptu script...>
> Note: this would work as a login script (or part of), and presumes the
user
> has a properly defined, networked, home directory. Also, I'm using the
> abbreviation HKCU - which is valid syntax. I note WSH stuff is probably
not
> explicitly within the remit of this newsgroup, as there is a separate
> newsgroup for it, but given you're using vbscript, and probably using WSH,
> it's a reasonable assumption that it's relevant to you.
> HTH
> Neil