

InterviewSolution
Saved Bookmarks
1. |
Solve : Question about Windows Registry and environment variables? |
Answer» <html><body><p>BLUF: I need to build up the actual %TEMP% path for all users<br/>methodically using values in the <a href="https://interviewquestions.tuteehub.com/tag/registry-1182422" style="font-weight:bold;" target="_blank" title="Click to know more about REGISTRY">REGISTRY</a>, and I need to do this both<br/>by the current user AND as a service will do this running as "Local<br/>System." Thus, I can't rely on it always being ...\\Local<br/>Settings\Temp.<br/><br/><br/>I have a service running as Local System, and I need to find each<br/>user's %TEMP% directory. I've found a location in the registry that<br/>is helpful, but not exactly what I am <a href="https://interviewquestions.tuteehub.com/tag/looking-1079184" style="font-weight:bold;" target="_blank" title="Click to know more about LOOKING">LOOKING</a> for. So, any help is<br/>greatly appreciated.<br/><br/>I need this information, because I need the service to write something<br/>to a particular user's directory, and as evidenced by MSFT's Virtual<br/>PC Images, this is not always how a machine in set up (the user is<br/>`IETester` but the %TEMP% dir is `C:\DOCUME~1\IETest\Local Settings<br/>\Temp" (notice `IETest` instead of `IETester`).<br/><br/>The locations that I found in the registry are:<br/><br/>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer<br/>\Shell Folders<br/><br/>HKEY_USERS\S-1-...\Software\Microsoft\Windows\CurrentVersion\Explorer<br/>\Shell Folders<br/><br/>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer<br/>\DocFolderPaths<br/><br/><br/>Obviously, the CURRENT_USER is useless, because the service (running<br/>as Local System) won't know the current user (and I need all users<br/>anyway). If I use the value in USERS, I'll have to backtrace and find<br/>the value of %USERPROFILE% somewhere. The LOCAL_MACHINE looks like a<br/>reasonable place, but I don't know if it is exactly what I'm looking<br/>for. Another problem with LOCAL_MACHINE (at least, with the registry<br/>key I'm referencing above), is that the "Value" listed is still not<br/>the user name for the current user. (Ex: Value is `IETest` and the<br/>value's data is set to `C:\Documents and Settings\IETest\My<br/>Documents`. <a href="https://interviewquestions.tuteehub.com/tag/however-at-491999" style="font-weight:bold;" target="_blank" title="Click to know more about HOWEVER">HOWEVER</a>, the actual USER NAME is `IETester`.<br/><br/>Sidenote: System.IO.GetTempPath() returns the value "C:\Documents and<br/>Settings\IETest\Local Settings\Temp," so that at least jives with what<br/>I'm seeing in the registry (instead of relying on the actual username<br/>to hardcode paths), but I still can't put everything together.<br/><br/><br/>What is the best way to do this? I'm not sure which values in the<br/>registry get changed if the user changes the default setting/location,<br/>so I don't know exactly where to look. And one last question: Is this<br/>location/forumlation the same between <a href="https://interviewquestions.tuteehub.com/tag/xp-747558" style="font-weight:bold;" target="_blank" title="Click to know more about XP">XP</a> and <a href="https://interviewquestions.tuteehub.com/tag/vista-728089" style="font-weight:bold;" target="_blank" title="Click to know more about VISTA">VISTA</a> (ignoring the<br/>Wow6432Node)?<br/><br/>Any help/insite is greatly appreciated!</p></body></html> | |