Besides being able to access environment variables on remote computers, WMI's Win32_Environment class also allows us to access (read set) environment variables for other users!
See MSDN for detailed information on this class' properties.
The most generic way that Windows Azure Web Sites provides these values to a running website is through environment variables.
For example, using the data shown in the earlier screenshot, the following is a code snippet from ASP.
The full list of database connection string types and the prepended string used for naming environment variables is shown below: If you select “Sql Databases”, the prepended string is “SQLAZURECONNSTR_” If you select “SQL Server” the prepended string is “SQLCONNSTR_” If you select “My SQL” the prepended string is “MYSQLCONNSTR_” If you select “Custom” the prepended string is “CUSTOMCONNSTR_” So far we have shown how the key-value pairs entered in the portal flow through to a web application via environment variables. NET web applications, there is some extra runtime magic that is available as well when using the . If the application setting(s) happen to already exist in your web.config file, Windows Azure Web Sites will automatically override them at runtime using the values associated with your website.
Since the key-value pairs are stored behind the scenes in the Windows Azure Web Sites configuration store, the key-value pairs don’t need to be stored in the file content of your web application.This behaviour is exactly like that of a batch file: the environment variable is replaced by its value when the string is processed. Some environment variables are actually the result of two variables being merged. Echo "SYSTEM: TEMP=" & wsh System Env( "TEMP" ) Set wsh System Env = Nothing Set wsh Shell = Nothing Set wsh Shell = Create Object( "WScript. Echo Left( "Expanded" & Space( 12 ), 12 ) & wsh Shell. However, if Windows Azure Web Sites cannot find a connection string with a matching name from the web.config, then the connection string entered in the portal will only be available as an environment variable (as shown earlier).As an example, assume a web.config entry like the following: A website can reference this connection string in an environment-agnostic fashion with the following code snippet: When this code runs on a developer’s local machine, the value returned will be the one from the web.config file.