Question about Windows Registry

T

thephatp

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.


So, this partially applies to C#, because I'll need to do this in C#
code. But, I think I already know how to do it. What I don't know is
where to find the information in the registry.

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!
 
T

thephatp

[...]
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.

Well, for better or worse, that's what you have to do.  The "HKEY_USERS" 
sub-keys are the ones that are per-user.  If you want per-user  
information, you need to inspect that part of the registry.

Pete

I was hoping that wouldn't be the answer. D'oh. So, if I have to do
that, where can I find the value of %USERPROFILE%?

Thanks!
 

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