作成 2011.02.12
更新 2013.11.09
ASP.NET で環境変数を列挙する
コード
GetEnvironmentVariables() が本体です。
アセンブリはデフォルトで有効です。
<%@ PAGE LANGUAGE="C#" %>
<html>
<head>
<title>getenvironments</title>
<style>
table{border-collapse:collapse;}
tr{vertical-align:top;}
td{border:1px solid #999;}
</style>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
  String result = "";
  IDictionary envs = Environment.GetEnvironmentVariables();
  foreach (DictionaryEntry de in envs)
  {
    result += "<tr><td>"+de.Key+"</td><td>"+de.Value+"</td></tr>";
  }
  lbl_result.Text = "<table>"+result+"</table>";
}
</script>
</head>
<body>
  <form runat="server">
  <asp:Label id="lbl_result" Text="" runat="server" />
  </form>
</body>
</html>
実行結果
Windows Server 2003 R2 の実行結果
PSModulePath C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
USERPROFILE C:\Documents and Settings\Default User
Path C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\
ClusterLog C:\WINDOWS\Cluster\cluster.log
CommonProgramFiles C:\Program Files\Common Files
TMP C:\WINDOWS\TEMP
ProgramFiles C:\Program Files
NUMBER_OF_PROCESSORS 1
TEMP C:\WINDOWS\TEMP
SystemDrive C:
ComSpec C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK NO
COMPUTERNAME testhost1
PROCESSOR_LEVEL 6
OS Windows_NT
SystemRoot C:\WINDOWS
windir C:\WINDOWS
APP_POOL_ID DefaultAppPool
ALLUSERSPROFILE C:\Documents and Settings\All Users
PROCESSOR_IDENTIFIER x86 Family 6 Model 15 Stepping 11, GenuineIntel
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1
PROCESSOR_ARCHITECTURE x86
PROCESSOR_REVISION 0f0b
Windows Server 2008 R2 の実行結果
COMPUTERNAME testhost2
APPDATA C:\Windows\system32\config\systemprofile\AppData\Roaming
LOCALAPPDATA C:\Windows\system32\config\systemprofile\AppData\Local
PSModulePath C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PROCESSOR_ARCHITECTURE AMD64
CommonProgramW6432 C:\Program Files\Common Files
CommonProgramFiles(x86) C:\Program Files (x86)\Common Files
ProgramFiles(x86) C:\Program Files (x86)
PROCESSOR_LEVEL 6
ProgramFiles C:\Program Files
USERNAME testhost2$
SystemRoot C:\Windows
APP_POOL_CONFIG C:\inetpub\temp\apppools\DefaultAppPool.config
APP_POOL_ID DefaultAppPool
ALLUSERSPROFILE C:\ProgramData
FP_NO_HOST_CHECK NO
ProgramData C:\ProgramData
USERPROFILE C:\Windows\system32\config\systemprofile
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
CommonProgramFiles C:\Program Files\Common Files
OS Windows_NT
PROCESSOR_IDENTIFIER Intel64 Family 6 Model 15 Stepping 11, GenuineIntel
ComSpec C:\Windows\system32\cmd.exe
PUBLIC C:\Users\Public
SystemDrive C:
PROCESSOR_REVISION 0f0b
NUMBER_OF_PROCESSORS 1
TEMP C:\Windows\TEMP
TMP C:\Windows\TEMP
ProgramW6432 C:\Program Files
Path C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
USERDOMAIN SAMPLE
windir C:\Windows
参考
タグ: ASP.NET CSharp

©2004-2017 UPKEN IPv4