How can I get the value of a custom environment variable in a classic ASP page using VBScript?
Asked
Active
Viewed 8,351 times
2 Answers
13
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.

dmogle
- 321
- 2
- 4
-
Very nice, obvious +1! But what about permissions? Doesn't it require any elevated permissions for the IUSR account? – Shadow The GPT Wizard Jun 16 '11 at 08:09
3
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"))

Alex
- 9,250
- 11
- 70
- 81