Expanding environmental variables using vbs
12/14/07
Expanding environmental variables using vbs
Recently I was messing around with some registry enumeration scripts to show the paths of executables that were being referenced in the registry. To do this properly, I needed to expand the system variables that were stored in the registry. I figured that there might be some other folks that needed to do the same thing, so here is a little function that will handle it for you.
function expandEnvString( envVal )
dim wshShell
set wshShell = createobject("WScript.Shell")
if isnull( envVal ) or envVal = "" then
expandEnvString = ""
exit function
end if
expandEnvString = wshShell.expandenvironmentstrings( envVal )
set wshShell = nothing
end function
To use the function, you call it passing in the environmental variable you want expanded. Something like......
wscript.echo expandEnvString( "%WINDIR%" )
This will give you results something like......
C:\>cscript funcTest.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
C:\WINDOWS
I hope this post helped you out. If it didn't, I am always looking for new scripts to add so submit a request for your question or need and I will see if I can answer it.
Pingbacks:
No Pingbacks for this post yet...
Scripts
This is somewhere I can post interesting snippets as I come across them. Hopefully some folks out there will find this helpful.
Search
Follow Me:
Categories
- All
- Web Technologies (2)
- PHP (1)
- Windows Scripting (37)
- Batch Scripts (13)
- Wsh Scripts (23)
Archives
- December 2009 (2)
- March 2009 (2)
- February 2009 (3)
- January 2009 (2)
- December 2008 (4)
- November 2008 (1)
- October 2008 (1)
- February 2008 (1)
- December 2007 (3)
- July 2007 (1)
- April 2007 (1)
- February 2007 (2)
- More...
Misc
Who's Online?
- Guest Users: 1




