【问题标题】:Getting environment variables in Classic ASP在经典 ASP 中获取环境变量
【发布时间】:2011-06-15 15:14:55
【问题描述】:

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

【问题讨论】:

    标签: vbscript asp-classic environment-variables


    【解决方案1】:

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

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

    More info on the Shell object as MSDN

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

    【讨论】:

    • 非常好,明显+1!但是权限呢?是否不需要对 IUSR 帐户进行任何提升的权限?
    【解决方案2】:

    以下对我有用,基于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"))
    

    【讨论】:

      猜你喜欢
      • 2014-01-10
      • 2011-02-10
      • 1970-01-01
      • 2014-11-25
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多