繁体   English   中英

在Classic ASP中获取环境变量

[英]Getting environment variables in Classic ASP

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

您可以使用WScript.Shell对象的ExpandEnvironmentStrings方法来检索环境变量。 以下代码将PATH环境变量的值分配给var myPath:

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

有关Shell对象的更多信息,请参阅MSDN

编辑:必须更改分配shell对象的变量。

基于这篇文章 ,以下内容对我有用

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM