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.

Setting DOS Environment Variables and Path

Keywords:	 DOS environment variables RunEnviron  winset envars.exe

Question:

Is there a possibility to use enviroment variables in WINDOWS and DOS? We've got an application that needs an environment variable in the autoexec.bat but i'm looking for a possible solution calling the application with a variable from a Winbatch script. EnvironSet and RunEnviron don't work.

Answer:

It depends. What version of Windows are you running? What environment variable do you want to set?

There is a Microsoft utility that can be used to set a global DOS variable in Windows 95. The utility is called "WinSet" and it's in a self-extracting archive file named "envars.exe". It's used almost identically to the DOS Set command, except it changes the master DOS environment in Windows 95.

If it is a DOS program under 32 bit Windows, one trick is to pass parameters to a BAT file that sets the environment variable THEN runs the DOS program (in the SAME bat file)

To run DOS applications from WinBatch and to alter the path for DOS programs, you'll need to set up a batch file, and launch it with the WIL Run command.

Assuming the case where one wished to run "command.com" with the path "c:\special", a batch file as shown below will work, along with passing all the information required as parameters in the WIL Run command:

rem DOPATH.BAT file
		SET PATH=%1
		ECHO %PATH%
		PAUSE
rem The following line runs whatever DOS exe you want, followed by params:
		%2   %3	  %4   %5   %6	 %7   %8   %9
WIL Run Command:
		Run("dopath.bat", "c:\special  command.com")

As long as your environment size is large enough, this should work fine. Also take a look at your PIF settings for setting the environment space.

If your App is a DOS App, then the EnvironSet command will not show up in the DOS environment, so that is why you cannot use the EnvironSet function to set DOS environment variables. (Windows keep two copies of the environment, one for DOS and one for Windows)

Additional Notes:

In your DOS batch file, after setting the environment variable, you could also add a line to do a DOS Call on a second batch file, to launch your DOS application. In this case, your DOS app would inherit your environment settings for the local session.

The RunEnviron function CAN ONLY SET THE ENVIRONMENT AND RUN WINDOWS PROGRAMS. IT CANNOT RUN DOS PROGRAMS.


Article ID:   W12915
Filename:   DOS Environment Variables.txt
File Created: 1999:04:15:16:50:30
Last Updated: 1999:04:15:16:50:30