I'm trying to modify registry entries within HKCU at logoff. The corresponding script works okay when invoked manually. I was afraid there might be issues with a loopback policy kicking in, but according to rsop.msc this is not the case, i.e. the script should be executed. However, the desired effect in the registry is not there upon next login.
Is there a general problem simply because the script runs "too late"? If so what can be done? What else could this be?
EDIT:
I should have specified what my logoff.vbs
script looks like (minimalized):
const HKCU = &H80000001
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
' ...
oReg.SetStringValue HKCU,"SOFTWARE\Foo","Bar", "Baz"
Best Answer
I use Logoff Scripts fairly frequently. The user's registry is still loaded when the script runs and modifications can be made to their registry. Logoff scripts run synchronously, by design. I have logoff scripts that read from the user's registry but I've never had occasion to write. Even so, I expect it would work fine.
I took your code snippet above, put it in a file and assigned it as a Logoff Script in Local Group Policy on a Windows XP SP3 VM, and obtain the desired result. I set
HKCU\Software\Foo\Bar
equal toxxx
, logged-off, logged-on again, and found that the value had been changed toBaz
, as-expected.I think you're having some other kind of problem, aside from script execution. I added a
MsgBox
call to the code so I could "see" the code running on logoff. Adding the MsdBox did not change the registry-related behavior but did give me a visual indication the code was running (and held-up logoff until I dismissed the dialog).(I can go ahead and test on Windows 7, too, if you'd like but I anticipate no change in functionality.)