Getting the SYSTEM environment variable


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">From a thread over an internal alias
today.. "urn:schemas-microsoft-com:office:office" />


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Some have noticed that in V1 we give
you access the user’s environment variables… We are fixing it in Whidbey where
you can get the user or machine


style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 21pt; mso-layout-grid-align: none"> style="FONT-SIZE: 9pt; COLOR: navy; FONT-FAMILY: Arial">Environment.GetEnvironmentVariable(“TEMP”,EnvironmentVariableTarget.Machine)


style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> style="FONT-SIZE: 9pt; COLOR: navy; FONT-FAMILY: Arial"> 


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Notice you can do this in V1
with:


style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> style="FONT-SIZE: 9pt; COLOR: navy; FONT-FAMILY: Arial"> style="mso-spacerun: yes">               
using (RegistryKey environmentKey =


style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> style="FONT-SIZE: 9pt; COLOR: navy; FONT-FAMILY: Arial"> style="mso-spacerun: yes">                      
Registry.LocalMachine.OpenSubKey(@”System\CurrentControlSet\Control\Session
Manager\Environment”, false)) {


style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> style="FONT-SIZE: 9pt; COLOR: navy; FONT-FAMILY: Arial"> style="mso-spacerun: yes">                  
string value = environmentKey.GetValue(variable) as
string;


style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> style="FONT-SIZE: 9pt; COLOR: navy; FONT-FAMILY: Arial"> style="mso-spacerun: yes">                  
return value;


style="FONT-SIZE: 9pt; COLOR: navy; FONT-FAMILY: Arial"> style="mso-spacerun: yes">               
}


style="FONT-SIZE: 9pt; COLOR: navy; FONT-FAMILY: Arial"> 


style="FONT-SIZE: 9pt; COLOR: navy; FONT-FAMILY: Arial">Useful?


 

Comments (2)

  1. David Levine says:

    Anything that reduces the amount of code and hides operating system specific details without sacrificing functionality is a good thing. Most people would not have known how to retrieve that data anyway, so that makes it even better.

  2. dannyR says:

    Yes, it is useful. In addition, taking the target as an argument makes it clear to the developer that there is more than one set of environment variables he should consider. It will help devs write less bugs.