Getting environment variables in Classic ASP

£可爱£侵袭症+ 提交于 2020-01-01 08:22:27

问题


How can I get the value of a custom environment variable in a classic ASP page using VBScript?


回答1:


You can use the ExpandEnvironmentStrings method of the WScript.Shell object to retrieve environment variables. The following code will assign the value of the PATH environment variable to var myPath:

set foo = createobject("WScript.Shell")
myPath = foo.ExpandEnvironmentStrings("%PATH%")

More info on the Shell object as MSDN

Edit: Had to change the variable to which the shell object is assigned.




回答2:


The following worked for me, based on 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"))


来源:https://stackoverflow.com/questions/6360036/getting-environment-variables-in-classic-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!