Question about Windows Registry

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thephatp

    Question about Windows Registry

    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\IE Test\Local Settings
    \Temp" (notice `IETest` instead of `IETester`).

    The locations that I found in the registry are:

    HKEY_CURRENT_US ER\Software\Mic rosoft\Windows\ CurrentVersion\ Explorer
    \Shell Folders

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

    HKEY_LOCAL_MACH INE\SOFTWARE\Mi crosoft\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.GetTe mpPath() returns the value "C:\Documen ts 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!
  • Peter Duniho

    #2
    Re: Question about Windows Registry

    On Mon, 16 Jun 2008 20:55:46 -0700, thephatp <chad.a.morris@ gmail.com>
    wrote:
    [...]
    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

    Comment

    • thephatp

      #3
      Re: Question about Windows Registry

      On Jun 17, 12:44 am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
      wrote:
      On Mon, 16 Jun 2008 20:55:46 -0700, thephatp <chad.a.mor...@ gmail.com 
      wrote:
      >
      [...]
      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!

      Comment

      • Peter Duniho

        #4
        Re: Question about Windows Registry

        On Tue, 17 Jun 2008 05:29:58 -0700, thephatp <chad.a.morris@ gmail.com>
        wrote:
        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%?
        I don't recall the details. You should find a newsgroup more specific to
        unmanaged Windows API programming. However, I do have a vague memory that
        there's a section in the HKEY_USER section for the user themselves that
        contains the value for that variable.

        You may find the easiest thing is to just create a brand new user, and
        snoop around in the registry for that user to see what you find. Even a
        brand new user will have lots of stuff in there, but at least that should
        help minimize the extraneous stuff.

        Pete

        Comment

        Working...