2011-06-15 24 views

cevap

13

Ortam değişkenlerini almak için WScript.Shell nesnesinin ExpandEnvironmentStrings yöntemini kullanabilirsiniz. Aşağıdaki kod var MyPath için yol ortam değişkeninin değerini atar:

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

More info on the Shell object as MSDN

Düzenleme: kabuk nesne atandığı değişken değiştirmek zorunda kaldı.

+0

Mükemmel dayalı, benim için çalıştı. Teşekkürler! – MikeWyatt

+0

Çok hoş, açık +1! Peki izinler ne olacak? IUSR hesabı için herhangi bir yükseltilmiş izin gerektirmez mi? –

2

şu çalışmış 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")) 
İlgili konular