开发者

Getting environment variables in Classic ASP

开发者 https://www.devze.com 2023-03-13 16:32 出处:网络
How can I get the value of a custom environment variable in a classic ASP page using V开发者_如何学JAVABScript?You can use the ExpandEnvironmentStrings method of the WScript.Shell object to retrieve e

How can I get the value of a custom environment variable in a classic ASP page using V开发者_如何学JAVABScript?


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.


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"))
0

精彩评论

暂无评论...
验证码 换一张
取 消