Forcing Explorer to re-read registry settings?

Forum: LXer Meta ForumTotal Replies: 10
Author Content
techiem2

Apr 09, 2008
11:18 AM EDT
Ok, so we have this new (or new version I think) certification program we need to run. Our labs are on the domain, and have My Documents directed to the user's mapped share on the server (p:). The problem is, the certification program requires My Documents to be on c:.

So I am trying to figure out how to change it on the fly. Basically, change the setting, run the program, exit program, change setting back.

I found the appropriate registry entries for changing the location, but windows only reads them on login.

Anybody know how to make explorer re-read the settings? Obviously there's a way since it does it when you change the My Docs location the normal windows way.

I called tech support (I wanted to use their "live esupport" but it requires you to download a windows program...yeah...) and the guy said he hasn't found a workaround for the issue, but there must be one. :)

(Have I mentioned lately how much I hate working on windows? - It's just so....illogical...)
tuxchick

Apr 09, 2008
11:30 AM EDT
I would say you're joking, except I've been there, and sorry, I don't know of a way to make it work. What kind of moron writes an application that hardcodes drive letters? What kind of doofus buys such an application?

**bangs head**
jdixon

Apr 09, 2008
11:47 AM EDT
Curiosity rears it's head. Would creating a link to the networked directory work from the expected location work? I doubt it, but it's worth a quick try.

The My Documents setting is usually a per-user setting. Could you run the program as a user for which it is not set to the network drive?

If not, then you'll have to find out how Windows changes the settings and duplicate it. A quick web search didn't turn up any useful info, however.
techiem2

Apr 09, 2008
12:17 PM EDT
Windows doesn't do symlinks. :) I know the registry entries that need to be changed. I just can't find a way to force explorer to re-read them. I'm googling all over trying to find some way to do it...
jdixon

Apr 09, 2008
12:54 PM EDT
> Windows doesn't do symlinks

No, but they do have a poor imitation, which seems to work for most Windows functions. I have no idea if it would work for My Documents or not.

However, this thread seems to cover the subject:

http://forum.sysinternals.com/forum_posts.asp?TID=11826

It looks like the SHChangeNotify function they discuss may be what you want.
Sander_Marechal

Apr 09, 2008
1:37 PM EDT
AFAIK toe only way to make explorer reread the registry is a reboot.
techiem2

Apr 09, 2008
1:45 PM EDT
Hmm. I haven't tried the shchangenotify function yet.

I've tried the wm_settingchange function and it hasn't worked (though from what I've read it SHOULD).

Oddly enough, one of the very common "solutions" for the issue is "use task manager to kill and restart explorer"

techiem2

Apr 10, 2008
10:40 AM EDT
So, we discovered that the program doesn't need explorer to re-read the settings to work since it just reads the registry settings itself. So we can just change the registry entries, run the program, then change them back...supposedly. Our new problem is that it requires Administrative level access to the registry. Which means we need to use runas to launch it. Not a problem, I found a nice sample vbscript to do that automatically. However: runas sets the current directory to c:windowssystem32 (i.e. where it is). The cert program looks for its settings files in the directory it is launched from (more lovely coding)...... So...right clicking the normal shortcut to use runas works (since the shortcut has the start in setting), but launching via a vbs script (or via cmd) doesn't, because in those cases runas forces the starting dir to c:windowssystem32 (even when you run runas from the program's directory).

*bangs head on desk*
Sander_Marechal

Apr 10, 2008
12:39 PM EDT
Can't you edit the VB script to change working directory after acquiring Administrative privileges?
techiem2

Apr 10, 2008
1:00 PM EDT
hmmm. So...run runas to launch the prog, then immediated change the working dir and see if the prog picks up the change? *goes to test that*

*edit* nope. It still uses the path set by runas.

:(
Sander_Marechal

Apr 10, 2008
1:15 PM EDT
If that doesn't work, perhaps this will: http://www.tek-tips.com/viewthread.cfm?qid=1235871

Basically it's a VB class that allows you to run a piece of VB code as a different user. Perhaps you could write a script like:

imp.ImpersonateStart(DomainName, UserName, Password) WshShell.CurrentDirectory = "C:SomeNewPath" shell("c:myapplication.exe",3) imp.ImpersonateStop()

Posting in this forum is limited to members of the group: [Editors, MEMBERS, SITEADMINS.]

Becoming a member of LXer is easy and free. Join Us!