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 Settings in Windows 3.1 and Windows 95/NT

Keywords:  environment EnvironSet Registry entries Environment Manager extender RunEnviron   WINSET

Question:

I am using Windows 3.1 if I use the Environment extender (WWWENV16I.DLL) to set DOS environment variables from a Winbatch script using the 16 bit extender, will I be able to use it in Windows 95 or NT? If not how can I set the DOS variables without the extender? How do I set the environment variables in Windows 95?

Answer:

The Environment stuff is way different for 16 bit Windows, Windows 95 and Windows NT. They are really 3 different operating systems. Setting environment variables in them use different means with different effects.

You can change the environment in 16 bit Windows, using the Environment Manager extender, WWENV16I.DLL and WWENV.HLP (help file). You cannot do things like delete DOS Environment variables in Windows 95, although you can do so in Windows 3.1 using the Environment Manager.

You can change the environment settings for when an application is launched, with the EnvironSet and RunEnviron functions, in both Windows 95 and Windows 3.1. Note that for 16 bit Windows, the @NOWAIT flag cannot be used in the RunEnviron.

You can do things like make sure the location of your application's DLLs in in the path, using the EnvItemize function. If your application is having problems locating its DLL when you launch it using RunEnviron, then you might need to change into the directory where the DLL is located, and launch the EXE using RunEnviron with the full path to it.

It is really easy to modify NT 3.5, 3.51 and 4.0 environment variables. No problem. In Windows NT, it is a simple as modifying some Registry entries.

On the other hand, Windows 95 is a disaster. It depends what you want to do. If ALL you want to do is modify the PATH statement, then it is VERY easy. Just use the RegApp function before calling the EXE file. The "RegApp" function is very handy to modify the path for a particular exe file - as long as WinBatch or an "approved: shell (like Explorer) runs it.

If WinBatch launches the EXEs involved, then the EnvironSet and RunEnviron functions may be used to change environment variables.

Otherwise, you get to edit AUTOEXEC.BAT and reboot.

Additional Tech Notes:

Windows 95 comes with WINSET, which changes some environment settings in Windows.(You probably can find the WINSET utility on the WIndows 95 CD-Rom in the ADMIN\ENVVARS subdirectory.)

Here is a workaround, so that Winbatch can access these environment settings:

When you use the DOS SET command to make changes to your DOS environment from within a DOS window, the changes only affect that particular DOS window and are not accessible to WinBatch or any other Windows application. There are utilities which can change the master DOS environment, but these changes are not visible to WinBatch either. What you can do is to make a DOS batch file such as this, which redirects the DOS environment to an output file:

                                                                                
  REM ENVLIST.BAT                                                               
  SET > ENVLIST.OUT                                                             
and then use WinBatch to run the batch file and parse the output, eg:
;------------------------------
myvar = "testvar"  ; variable we are looking for
;------------------------------

RunHideWait("envlist.bat", "")
hfile = FileOpen("envlist.out", "READ")
val = ""

While @TRUE
  line = FileRead(hfile)
  If line == "*EOF*" Then Break
  equals = StrIndex(line, "=", 1, @FWDSCAN)
  var = StrSub(line, 1, equals - 1)

  If StriCmp(var, myvar) == 0
    val = StrSub(line, equals + 1, -1)
    Break
  Endif
EndWhile

FileClose(hfile)
FileDelete("envlist.out")

; "val" is now set to the value of "myvar", or "" if not found
Message(myvar, val)


Article ID:   W12916
Filename:   Environment Settings.txt
File Created: 1999:04:15:16:50:30
Last Updated: 1999:04:15:16:50:30