【发布时间】:2011-06-15 15:14:55
【问题描述】:
如何使用 VBScript 在经典 ASP 页面中获取自定义环境变量的值?
【问题讨论】:
标签: vbscript asp-classic environment-variables
如何使用 VBScript 在经典 ASP 页面中获取自定义环境变量的值?
【问题讨论】:
标签: vbscript asp-classic environment-variables
您可以使用 WScript.Shell 对象的 ExpandEnvironmentStrings 方法来检索环境变量。以下代码会将 PATH 环境变量的值分配给 var myPath:
set foo = createobject("WScript.Shell")
myPath = foo.ExpandEnvironmentStrings("%PATH%")
More info on the Shell object as MSDN
编辑:必须更改分配给 shell 对象的变量。
【讨论】:
以下对我有用,基于this article
Set objWSH = CreateObject("WScript.Shell")
'This actually returns all the User Variables, and you either loop through all, or simply print what you want
Set objUserVariables = objWSH.Environment("USER")
MsgBox(objUserVariables("TEMP"))
'This returns all the System Variables, and you either loop through all, or simply print what you want
Set objSystemVariables = objWSH.Environment("SYSTEM")
MsgBox(objSystemVariables("PATH"))
【讨论】: