Script to map "My Documents" to arbitrary directory

A

ajkessel

My network group policy overwrites my local "My Documents" mapping.
When I leave the network, "my documents" remains mapped to a network
drive which no longer exists. I'd like to write a batch file to reset
the "My Documents" location, but have had no luck so far.

This question has come up in newsgroups before, see, e.g., <http://
groups.google.com/group/microsoft.public.windowsxp.customize/
browse_frm/thread/491a3e316df31e3f/e3f07c4d79d89970?lnk=st&q=%22my
+documents%22+batch+file&rnum=5#e3f07c4d79d89970> and <http://
groups.google.com/group/microsoft.public.windowsxp.general/browse_frm/
thread/85b7fda9bcc5ecc4/49c8fc88390ed754?lnk=st&q=map+%22my+documents
%22+batch+file&rnum=4#49c8fc88390ed754>, but there are no satisfactory
solutions.

My first attempt was to search through the registry for every key with
the "my documents" path, set that to the desired destination, and
export those registry entries and re-load them with a batch file when
I want to reset "my documents." No luck--either you need to reboot to
have the registry change take effect, or perhaps the group policy is
overriding the registry setting. Maybe there is some way to get the OS
to "reload" the my documents setting from the registry -- but I don't
know what that is.

I also tried this solution <http://www.novell.com/coolsolutions/tools/
14324.html> which adds a local group policy, but changing the shell
personal folder there does not appear to have any effect.

Any suggestions?
 
A

ajkessel

This is not a scripting newsgroup & batch files aren't scripting either:

Sorry, where I come from, "scripting" just means writing code that
isn't compiled. Python and Perl code, as well as shell scripts and
batch files would all be "scripts."
Ask the admins to map your home directory to a different location

Unfortunately, not an option here.

In any case, perhaps my question was not clearly presented: I know how
to write scripts/batch files/what-have-you; I'm looking for a
programmatic way of setting the "my documents" mapping. I can take
care of implementation -- I just haven't found any way to do it other
than by manually right-clicking on the "my documents" folder and
changing the target on every boot-up.
 
P

Pegasus

ajkessel said:
My network group policy overwrites my local "My Documents" mapping.
When I leave the network, "my documents" remains mapped to a network
drive which no longer exists. I'd like to write a batch file to reset
the "My Documents" location, but have had no luck so far.

This question has come up in newsgroups before, see, e.g., <http://
groups.google.com/group/microsoft.public.windowsxp.customize/
browse_frm/thread/491a3e316df31e3f/e3f07c4d79d89970?lnk=st&q=%22my
+documents%22+batch+file&rnum=5#e3f07c4d79d89970> and <http://
groups.google.com/group/microsoft.public.windowsxp.general/browse_frm/
thread/85b7fda9bcc5ecc4/49c8fc88390ed754?lnk=st&q=map+%22my+documents
%22+batch+file&rnum=4#49c8fc88390ed754>, but there are no satisfactory
solutions.

My first attempt was to search through the registry for every key with
the "my documents" path, set that to the desired destination, and
export those registry entries and re-load them with a batch file when
I want to reset "my documents." No luck--either you need to reboot to
have the registry change take effect, or perhaps the group policy is
overriding the registry setting. Maybe there is some way to get the OS
to "reload" the my documents setting from the registry -- but I don't
know what that is.

I also tried this solution <http://www.novell.com/coolsolutions/tools/
14324.html> which adds a local group policy, but changing the shell
personal folder there does not appear to have any effect.

Any suggestions?

It's a bit unclear what exactly you're trying to achieve by
resetting the location pointed at by "My Documents", and
why you would "leave" the network. I suggest you carefully
think through these issues before going any further.

There are several references in the registry that point to
the folder used for "My Documents". You can easily find
them like so:
1. Set My Documents to something easily recognisable,
e.g. d:\supercali
2. Search the registry for strings "d:\supercali".

To change these keys, do this:
1. Export them to c:\MyDocs.reg.
2. Modify them with notepad.exe.
3. Import them with this command:
regedit /s c:\MyDocs.reg

This method will change "My Documents" for applications but it
won't affect the desktop shortcut "My Documents" until you next
log on.
 
A

ajkessel

It's a bit unclear what exactly you're trying to achieve by
resetting the location pointed at by "My Documents", and
why you would "leave" the network. I suggest you carefully
think through these issues before going any further.

Really, I want to permanently set "My Documents" to a local folder,
but I can't get a specific exception from an administrator. I have to
implement any change myself on my client.
There are several references in the registry that point to
the folder used for "My Documents". You can easily find ....
regedit /s c:\MyDocs.reg
This method will change "My Documents" for applications but it
won't affect the desktop shortcut "My Documents" until you next
log on.

Right, that's precisely what I did. I'm looking for some way to reset
the desktop shortcut programmatically. If I log off/log on again, the
shortcut will again be reset by the group policy. Isn't there some
scriptable way to reset the desktop shortcut?
 
P

Pegasus

See below.

ajkessel said:
Really, I want to permanently set "My Documents" to a local folder,
but I can't get a specific exception from an administrator. I have to
implement any change myself on my client.

You can do this with the method I gave you. However,
you cannot prevent the policy from resetting it each time
you log on.
Right, that's precisely what I did. I'm looking for some way to reset
the desktop shortcut programmatically. If I log off/log on again, the
shortcut will again be reset by the group policy. Isn't there some
scriptable way to reset the desktop shortcut?

Don't cling to the desktop shortcut - it's more or less irrelevant.
What counts is the registry entries. As I said above, they will
be reset by the systems policy each time you log on.

Instead of tinkering with registry hacks, you should discuss your
needs with your system administrators in order to find a solution
that is acceptable to both sides. Involve your manager if necessary.
 
A

ajkessel

Don't cling to the desktop shortcut - it's more or less irrelevant.
What counts is the registry entries. As I said above, they will
be reset by the systems policy each time you log on.

I suppose that's right. I hadn't actually noticed before that the
desktop shortcut is not necessarily the same as the location
identified in applications. I guess I could just hide the desktop
shortcut and make a new static shortcut to the "real" location.
Instead of tinkering with registry hacks, you should discuss your
needs with your system administrators in order to find a solution
that is acceptable to both sides. Involve your manager if necessary.

Understood, although that's really more of a political/organizational
issue than a technical one. The main reason I want "My Documents" to
be local is certain applications have a hard-coded habit of scanning
that folder on startup. If the network drive isn't there, they choke.

It's still a little surprising that there is no way to actually change
the desktop shortcut with a script, but I now have a decent workaround.
 
T

Terry R.

On 6/10/2007 12:31 PM On a whim, ajkessel pounded out on the keyboard
I suppose that's right. I hadn't actually noticed before that the
desktop shortcut is not necessarily the same as the location
identified in applications. I guess I could just hide the desktop
shortcut and make a new static shortcut to the "real" location.


Understood, although that's really more of a political/organizational
issue than a technical one. The main reason I want "My Documents" to
be local is certain applications have a hard-coded habit of scanning
that folder on startup. If the network drive isn't there, they choke.

It's still a little surprising that there is no way to actually change
the desktop shortcut with a script, but I now have a decent workaround.

Can't you just set the caching/offline folders of My Documents up? On
one network I admin, I have all the laptop users My Documents located on
a server, but I have a local copy via offline folders that they use
whenever they're away from the network. Files are synchronized each
time a user logs in or off of the network, so files are always available.

--
Terry R.

***Reply Note***
Anti-spam measures are included in my email address.
Delete NOSPAM from the email address after clicking Reply.
 
A

ajkessel

Can't you just set the caching/offline folders of My Documents up? On
one network I admin, I have all the laptop users My Documents located on
a server, but I have a local copy via offline folders that they use
whenever they're away from the network. Files are synchronized each
time a user logs in or off of the network, so files are always available.

That might work, but I'm actually using SyncToy to manage online/
offline folders. It works better for me than the default offline
folders mechanism.
 
T

Terry R.

On 6/11/2007 1:36 PM On a whim, ajkessel pounded out on the keyboard
That might work, but I'm actually using SyncToy to manage online/
offline folders. It works better for me than the default offline
folders mechanism.

Either way (not familiar with SyncToy), you shouldn't have any need for
a script if set up properly.

--
Terry R.

***Reply Note***
Anti-spam measures are included in my email address.
Delete NOSPAM from the email address after clicking Reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top