如何使用VBScript在经典ASP页面中获取自定义环境变量的值?
答案 0 :(得分:13)
您可以使用WScript.Shell对象的ExpandEnvironmentStrings方法来检索环境变量。以下代码将PATH环境变量的值分配给var myPath:
set foo = createobject("WScript.Shell")
myPath = foo.ExpandEnvironmentStrings("%PATH%")
More info on the Shell object as MSDN
编辑:必须更改分配shell对象的变量。
答案 1 :(得分:2)
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"))