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 workmywindir=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: W12911Filename: Assigning a System Variable to a Path.txt