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

Registry
plus

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

PATH Information when Running Winbatch

Keywords:    apppaths 

When you run WINBATCH.EXE, (either from Explorer or from the Start button), the AppPath section of the registry is checked and if anything is there for winbatch.exe, it is prepended to the system path (the AppPath section of the registry is where an app registers the path where it locates its executable (.EXE) files as well as dynamic-link library (DLL) files).

All uncompiled scripts run via winbatch.exe, so the PATH when running an uncompiled WBT might look something like:


PATH=D:\Program Files\WinBatch\system\;D:\Program Files\WinBatch\System\;;D:\WINNT\system32;D:\WINNT;D:\Program Files\Mtx;C:\WINDOWS;C:\WINDOWS\COMMAND;c:\;c:\dos;

When you compile the script into xyz.exe, then xyz.exe is looked up in the AppPath section, and if nothing is found, nothing is prepended. So the PATH when running the compiled EXE on the same computer might look like:


PATH=D:\WINNT\system32;D:\WINNT;D:\Program Files\Mtx;C:\WINDOWS;C:\WINDOWS\COMMAND;c:\;c:\dos;

If you need to look information up in the registry, there are three parts of the registry where PATH information is stored: there's the system path part, user added path part, and AppPath section. You can use Winbatch Registry reading functions to grab the information out directly.

For the User Environment Path variable use:


userenv=Environment("PATH")
For the System Environment Path variable use:

path=Environment("PATH")
sysenv="SYSTEM\CurrentControlSet\Control\Session Manager\Environment[path]"
For the AppPaths variable, read the appropriate value under:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion

Note that the RegApp function creates (or updates) a sub-key in the registration database for the specified program, of the form PROGNAME.EXE, under the key:


HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\

The RegApp function can be used to add data to the appPath section, so for example, if you compile a Winbatch EXE called "xyz.exe" and want to add it to the AppPath section of the Registry, you could do something like:


residence="c:\Program Files\Winbatch\WBscripts\xyz.exe"
path="c:\Program Files\Winbatch\WBscripts"
RegApp(residence, path)
Basically Winbatch cannot make system-wide changes, but it can influence the path for any application WinBatch launches and/or for any application launched by the approved apppath methods (WinBatch, Explorer, the RUN command, etc., are all approved, while many other applicatios are not).

Here's some sample code to change the System path in NT:


curpath = Environment("PATH")
message("path",curpath)

sysenv="SYSTEM\CurrentControlSet\Control\Session Manager\Environment[path]"
oldpath=RegQueryExpSz(@Regmachine, sysenv)
message("ORIGINAL reg path", oldpath)

;Set to new path
junkpath="c:\Program Files\WinBatch\System"
	
newpath=strcat(oldpath,";",junkpath)
message("sysenv", sysenv)
modpath=RegSetExpSz(@RegMachine, sysenv, newpath)

sysenv="SYSTEM\CurrentControlSet\Control\Session Manager\Environment[path]"
newpath=RegQueryExpSz(@Regmachine, sysenv)
message("NEW reg path", newpath)

;Set back to original path
modpath=RegSetExpSz(@RegMachine, sysenv, oldpath)

sysenv="SYSTEM\CurrentControlSet\Control\Session Manager\Environment[path]"
oldpath=RegQueryExpSz(@Regmachine, sysenv)
message("Back to ORIG reg path", oldpath)


Article ID:   W13723
Filename:   PATH Information and RegApp.txt
File Created: 2001:01:31:10:15:42
Last Updated: 2001:01:31:10:15:42