WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Environment

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Environment Variables and Paths

Keywords: environment variable system variable path

Question:

I want to assign a variable to a path that may be different on each machine I run the script on. For instance the file LOADER.DLL should be in each NT machines system32 directory. So I want to have a winbatch line: LOC1="C:\winnt\system32\loader.dll". But "C:\winnt" could be D: or winnt40 or winnt351...etc.

I want to incorporate the system variable (windir) which points to each machines NT directory. Something like LOC1="%windir%\system32\loader.dll". But I haven't been able to get this yet. How can I incorporate a system variable into a regular variable assignment? Anyone with any ideas?

Answer:

Use the Environment function to read environment variables into WinBatch variables. DirWindows(0) may also work
mywindir=Environment("windir")
if mywindir=="" then mywindir=DirWindows(0)
if strsub(mywindir,strlen(mywindir),1)!="\"
   mywindir=strcat(mywindir,"\")
endif
LOC1=strcat(mywindir,"system32\loader.dll")

Article ID:   W12911
Filename:   Assigning a System Variable to a Path.txt
File Created: 1999:04:15:16:50:28
Last Updated: 1999:04:15:16:50:28