Scheduling a script that reads HKCU

M

Michael Brown

I have a script which reads the users HKCU registry to get the outlook
security folder, and then wipes all files within that directory.

The script runs perfectly when scheduled using the users account and
password. It fails however whenever it is run under any other account
(including local administrator or a domain admin account)

The problem is that is somewhat tedious to have to change the
passwords of a scheduled script every time the user changes their
passwords.

Does anyone have any ideas on how I could schedule the script with the
system account or as the local administrator?
 
T

Torgeir Bakken \(MVP\)

Michael said:
I have a script which reads the users HKCU registry to get the outlook
security folder, and then wipes all files within that directory.

The script runs perfectly when scheduled using the users account and
password. It fails however whenever it is run under any other account
(including local administrator or a domain admin account)

The problem is that is somewhat tedious to have to change the
passwords of a scheduled script every time the user changes their
passwords.

Does anyone have any ideas on how I could schedule the script with the
system account or as the local administrator?
Hi

Note that if you want to access another user's HKEY_CURRENT_USER
registry hive the script will need to load the hive file itself.

You might use the command line utility reg.exe for this (it comes
builtin with WinXP).

You would need to start out with loading another user's HKCU hive
("Tor" in the path below), to a *temporary* key under HKLM, like this:

reg.exe load HKLM\TempHive "C:\Documents and Settings\Tor\NTUSER.DAT"

Then you can use reg.exe to query and/or manipulate the hive,
addressing the HKEY_LOCAL_MACHINE\TempHive key that actually represent
the HKEY_CURRENT_USER key for the user "Tor".

When finished, unload the hive again like this:

reg.exe unload HKLM\TempHive

Run "reg.exe /?" in a command prompt for more help.

To get a better feeling for this technique, load a hive with reg.exe,
and then start regedit.exe and locate the new hive there (you can also
use regedit.exe to manually load and unload hives, but for a script
it is reg.exe that is the tool for the job)


You could also in e.g. a VBScript use reg.exe to just load the hive,
and then you could use VBScript's registry methods to do any query
and/or manipulation.


'--------------------8<----------------------
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

oShell.Run _
"reg.exe load HKLM\TempHive ""C:\Documents and Settings\Tor\NTUSER.DAT""", _
1, True

sWinDir = oFSO.GetSpecialFolder(0)
sWallPaper = sWinDir & "\Coffee Bean.bmp"

' update wallpaper in registry for user Tor
oShell.RegWrite "HKLM\TempHive\Control Panel\Desktop\Wallpaper", sWallPaper

'--------------------8<----------------------

*Important*: All your Run statements calling reg.exe needs to have True
as third parameter, to let the script wait for the reg.exe command to
finish before continuing.


Another example, using reg.exe to import a registry file to this
temporary hive:

reg.exe import x:\powerfix\powerfix.reg

The registry file would need to look like this:

--------------------8<----------------------
REGEDIT4

[HKEY_LOCAL_MACHINE\TempHive\Control Panel\PowerCfg]
"CurrentPowerPolicy"="0"

--------------------8<----------------------
using the same "TempHive" value (and HKEY_LOCAL_MACHINE) as in the
"reg.exe load ..." command.)

This would then actually update the HKEY_CURRENT_USER\Control Panel\PowerCfg
key for the user "Tor".


************************************************************

If you want to handle all the users on the computer, you will need
to enumerate all the user profiles, and handle them in a loop.

Some VBScript examples on enumerating user profiles on a computer:
http://groups.google.com/groups?as_...ugroup=microsoft.public.*&as_uauthors=torgeir

Of course, if the Outlook Security folder is always in the same place
(relatively) in the different users profiles, there is no need to load
the registry hives at all, just enumerate the profile paths as the
examples in the link above shows you.
 

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