Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Question about Windows Registry and environment variables  (Read 3111 times)

0 Members and 1 Guest are viewing this topic.

thephatp

  • Guest
Question about Windows Registry and environment variables
« on: June 17, 2008, 06:33:20 AM »
BLUF:  I need to build up the actual %TEMP% path for all users
methodically using values in the registry, and I need to do this both
by the current user AND as a service will do this running as "Local
System."  Thus, I can't rely on it always being ...\<Username>\Local
Settings\Temp.


I have a service running as Local System, and I need to find each
user's %TEMP% directory.  I've found a location in the registry that
is helpful, but not exactly what I am looking for.  So, any help is
greatly appreciated.

I need this information, because I need the service to write something
to a particular user's directory, and as evidenced by MSFT's Virtual
PC Images, this is not always how a machine in set up (the user is
`IETester` but the %TEMP% dir is `C:\DOCUME~1\IETest\Local Settings
\Temp" (notice `IETest` instead of `IETester`).

The locations that I found in the registry are:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
\Shell Folders

HKEY_USERS\S-1-...\Software\Microsoft\Windows\CurrentVersion\Explorer
\Shell Folders

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer
\DocFolderPaths


Obviously, the CURRENT_USER is useless, because the service (running
as Local System) won't know the current user (and I need all users
anyway).  If I use the value in USERS, I'll have to backtrace and find
the value of %USERPROFILE% somewhere.  The LOCAL_MACHINE looks like a
reasonable place, but I don't know if it is exactly what I'm looking
for.  Another problem with LOCAL_MACHINE (at least, with the registry
key I'm referencing above), is that the "Value" listed is still not
the user name for the current user.  (Ex: Value is `IETest` and the
value's data is set to `C:\Documents and Settings\IETest\My
Documents`.  However, the actual USER NAME is `IETester`.

Sidenote: System.IO.GetTempPath() returns the value "C:\Documents and
Settings\IETest\Local Settings\Temp," so that at least jives with what
I'm seeing in the registry (instead of relying on the actual username
to hardcode paths), but I still can't put everything together.


What is the best way to do this?  I'm not sure which values in the
registry get changed if the user changes the default setting/location,
so I don't know exactly where to look.  And one last question: Is this
location/forumlation the same between XP and Vista (ignoring the
Wow6432Node)?

Any help/insite is greatly appreciated!