Change My Documents Path With VBScript 
Author Message
 Change My Documents Path With VBScript

I've been working on this for days and just cant make it work.

I need to be able to change the my documents path when my users log on to
the network.  I'm told there are only two reg keys that handle this but
changing them via the reg just doesn't seem to work.

example
Change My Documents to:
\\file\users$\jemlay

 reboot machine and logon with "plam" which then run a script that changes
the two reg entries.

Now when I go to properties on My Documents it now says \\file\users$\plam
but if you double click on it, it still takes you to the old one (jemlay).

Has anyone found an acceptable solution to this?

Thanks



Mon, 08 Nov 2004 06:01:21 GMT  
 Change My Documents Path With VBScript

Quote:

> I need to be able to change the my documents path when my users log on to
> the network.  I'm told there are only two reg keys that handle this but
> changing them via the reg just doesn't seem to work.

> example
> Change My Documents to:
> \\file\users$\jemlay

>  reboot machine and logon with "plam" which then run a script that changes
> the two reg entries.

> Now when I go to properties on My Documents it now says \\file\users$\plam
> but if you double click on it, it still takes you to the old one (jemlay).

The user will need to log off and then on again to see the change.

--
torgeir



Mon, 08 Nov 2004 06:18:07 GMT  
 Change My Documents Path With VBScript
So they have to reboot and logon twice!  That stinks.

So if a user walks up to the machine and turns it on then logs in (script
runs), they then have to reboot and log in again just so the update works?

There must be another way?  After all if you change the path from the My
Documents icon it works fine so there must be a way to update it realtime?

Anyone?


Quote:

> > I need to be able to change the my documents path when my users log on
to
> > the network.  I'm told there are only two reg keys that handle this but
> > changing them via the reg just doesn't seem to work.

> > example
> > Change My Documents to:
> > \\file\users$\jemlay

> >  reboot machine and logon with "plam" which then run a script that
changes
> > the two reg entries.

> > Now when I go to properties on My Documents it now says
\\file\users$\plam
> > but if you double click on it, it still takes you to the old one
(jemlay).

> The user will need to log off and then on again to see the change.

> --
> torgeir



Mon, 08 Nov 2004 06:45:48 GMT  
 Change My Documents Path With VBScript

Quote:

> So they have to reboot and logon twice!  That stinks.

> So if a user walks up to the machine and turns it on then logs in (script
> runs), they then have to reboot and log in again just so the update works?

They do not need to reboot. A logoff/logon is good enough.

Quote:
> There must be another way?  After all if you change the path from the My
> Documents icon it works fine so there must be a way to update it realtime?

Well, the My Documents icon method uses some API that refreshes the shell. If
you find this API and wraps it in a COM object so you can use it from your
script (or create a standalone exe that does all the job so you don't need a
script), your users will not need to log off and then on again to see the
change.

--
torgeir



Mon, 08 Nov 2004 07:07:08 GMT  
 Change My Documents Path With VBScript
Ugh, you just went went 1 step beyond my reach.  Crash course time!

Thanks for your help Torgeir


Quote:

> > So they have to reboot and logon twice!  That stinks.

> > So if a user walks up to the machine and turns it on then logs in
(script
> > runs), they then have to reboot and log in again just so the update
works?

> They do not need to reboot. A logoff/logon is good enough.

> > There must be another way?  After all if you change the path from the My
> > Documents icon it works fine so there must be a way to update it
realtime?

> Well, the My Documents icon method uses some API that refreshes the shell.
If
> you find this API and wraps it in a COM object so you can use it from your
> script (or create a standalone exe that does all the job so you don't need
a
> script), your users will not need to log off and then on again to see the
> change.

> --
> torgeir



Mon, 08 Nov 2004 07:12:09 GMT  
 Change My Documents Path With VBScript

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



Mon, 08 Nov 2004 17:17:21 GMT  
 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



Tue, 09 Nov 2004 23:49:22 GMT  
 Change My Documents Path With VBScript
OK, I see the problem!!!!!!!!!

If you set this info after login then a reboot is needed.  However if you
set this info during login then NO reboot is needed.

Now what I have noticed is that this info is NOT available at login
"WScript.CreateObject("WScript.Network")"

If I try to plug this information in during login then I get an error
because it doesn't exist yet.  So I have a sleep for 3000 put in to wait a
little then run.  This makes it run AFTER login so thats why it's not
working.

Any one know of a different way to grab the login name???

Thanks

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



Wed, 10 Nov 2004 03:11:55 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Parsing an HTML Document - Change Relative paths to fully qualified paths

2. printing a changed document.body without changing the existing document.body

3. Changing active document path

4. Change NT path variable using VBScript?

5. ? How do you change a path to a dos path name

6. Changing Long Paths to Short Paths in a 16-bit App

7. Paths -- Creating File Path with several levels -- VBScript

8. Document variable with value that changes throughout the document

9. .JS Files - Problem with linking HTML documents (Path)

10. Using PATH With document.cookie

11. Altering My Document Path in Windows 2000

12. changing a path dynamically

 

 
Powered by phpBB® Forum Software