问题描述
|
如何使用VBScript在经典的ASP页中获取自定义环境变量的值?
解决方法
您可以使用WScript.Shell对象的ExpandEnvironmentStrings方法来检索环境变量。以下代码将PATH环境变量的值分配给var myPath:
set foo = createobject(\"WScript.Shell\")
myPath = foo.ExpandEnvironmentStrings(\"%PATH%\")
有关Shell对象作为MSDN的更多信息
编辑:不得不更改将外壳对象分配给的变量。
, 根据本文,以下内容对我有用
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,or simply print what you want
Set objSystemVariables = objWSH.Environment(\"SYSTEM\")
MsgBox(objSystemVariables(\"PATH\"))