12
如何在使用VBScript的傳統ASP頁面中獲取自定義環境變量的值?在經典ASP中獲取環境變量
如何在使用VBScript的傳統ASP頁面中獲取自定義環境變量的值?在經典ASP中獲取環境變量
可以使用WScript.Shell對象的ExpandEnvironmentStrings方法來檢索環境變量。下面的代碼將PATH環境變量的值分配給VAR mypath中:
set foo = createobject("WScript.Shell")
myPath = foo.ExpandEnvironmentStrings("%PATH%")
More info on the Shell object as MSDN
編輯:不得不改變到的殼對象被分配的變量。
以下爲我工作的基礎上,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"))
良好,即工作。謝謝! – MikeWyatt 2011-06-15 20:29:14
非常好,很明顯+1!但是權限呢?它是否需要任何提升的IUSR帳戶權限? – 2011-06-16 08:09:35