2011-06-15 61 views

Respuesta

13

Puede usar el método ExpandEnvironmentStrings del objeto WScript.Shell para recuperar variables de entorno. El siguiente código asignar el valor de la variable de entorno PATH para myPath var:

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

More info on the Shell object as MSDN

Editar: Tuvimos que cambiar la variable a la que se asigna el objeto shell.

+0

excelente, que trabajó. ¡Gracias! – MikeWyatt

+0

Muy bonito, obvio +1! Pero, ¿y los permisos? ¿No requiere ningún permiso elevado para la cuenta IUSR? –

2

A continuación trabajó para mí, basado en 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")) 
Cuestiones relacionadas