We have a vbs script that has hardcoded a destination folder, including
drive letter. Unfortunately, our servers sometimes have the destination on
the C: drive and others may, for example, be on an F: drive. I am thinking
the way to generalize the script would be to set a global environment
variable and instead of hardcoding the drive, substitute the environment
variable value instead.

Does anyone know if this is doable?

Re: Can VBS read an environment variable? by McKirahan

McKirahan
Tue Jun 06 18:26:10 CDT 2006

"Thirsty Traveler" <nfr@nospam.com> wrote in message
news:edqrgobiGHA.1264@TK2MSFTNGP05.phx.gbl...
> We have a vbs script that has hardcoded a destination folder, including
> drive letter. Unfortunately, our servers sometimes have the destination on
> the C: drive and others may, for example, be on an F: drive. I am thinking
> the way to generalize the script would be to set a global environment
> variable and instead of hardcoding the drive, substitute the environment
> variable value instead.
>
> Does anyone know if this is doable?


Will this help?

Option Explicit
Dim objWSS
Set objWSS = CreateObject("WScript.Shell")
objWSS.Environment("VOLATILE")("Drive") = "F:"
WScript.Echo objWSS.Environment("VOLATILE")("Drive")
Set objWSS = Nothing

It's stored under: HKEY_CURRENT_USER/Volatile Environment/



Re: Can VBS read an environment variable? by \

\
Thu Jun 08 07:07:09 CDT 2006

> We have a vbs script that has hardcoded a destination folder, including
> drive letter. Unfortunately, our servers sometimes have the destination on
> the C: drive and others may, for example, be on an F: drive. I am thinking
> the way to generalize the script would be to set a global environment
> variable and instead of hardcoding the drive, substitute the environment
> variable value instead.

> Does anyone know if this is doable?

Yes. This is for an environment variable named "Target" assigned to the system,
and thus the same for all users logged on to that computer.

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
WScript.Echo WshSysEnv("Target")

If you want to assign the target on a per user basis, enter the environment
variable in the "user" section and change SYSTEM above to USER.
--
Crash

"In statesmanship get the formalities right, never mind about the moralities."
~ Mark Twain ~