在Classic ASP中获取环境变量

时间:2011-06-15 15:14:56

标签: vbscript asp-classic environment-variables

如何使用VBScript在经典ASP页面中获取自定义环境变量的值?

2 个答案:

答案 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)

根据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"))