Adding to Path environment variable

Adding to Path environment variable

Post by Barr » Tue, 05 Oct 2004 19:07:01


I've been looking for a way to add a directory to Path for an installer. I
need to set Path permanently, not just while the command prompt is open, so
I can't use the set command. I figured I should write somewhere in the
registry, so I searched the registry for a directory currently in the Path
system variable, but I couldn't find it. I think I found where PATH data is
stored for the owner, but I'd rather set the Path for all users.

I could call the command line program PathTool (
http://www.yqcomputer.com/ ) from my script to add to
Path, but PathTool is a 72K exe with features that I don't need. The
VBScript at http://www.yqcomputer.com/
more practical for my needs, but I need some help to customize it.

I only have access to Windows XP. With a little help from a VBScript
reference (since I don't know VBScript), I was able to customize the
VBScript to add to Path on XP and other NT based systems. I came up with the
following script:

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("SYSTEM")
WshEnv("Path") = WshEnv("Path") & ";directory/to/add/goes/here"

All I need is a way to sniff out Windows 95, 98 and Me and change the code
as needed when one of those systems is detected. My best guess is to learn
how to read the registry from the command prompt and see if
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\PathName"
contains "C:\WINNT" and if not, assume it's Windows 95, 98, or Me and
(somehow) add to the Path in autoexec.bat, but I don't think users of my
product would appreciate me playing a guessing game with their registry.

Any help would be appreciated.

Barry
 
 
 

Adding to Path environment variable

Post by MV » Tue, 05 Oct 2004 19:32:21


Hi

E.g. take a look at the function GetOsVersionNumber here:

http://www.yqcomputer.com/ %40hydro.com



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.yqcomputer.com/

 
 
 

Adding to Path environment variable

Post by Barr » Wed, 06 Oct 2004 00:51:38

Thanks, that looks like a useful function.

The following is the most complete information I've found in one place (from
http://www.yqcomputer.com/ ) on editing Path
for different versions of Windows, though it's not written for developers.
Microsoft should make a version of this available to developers, for
developers. No wonder so much Windows software I've downloaded doesn't set
Path automatically. Maybe I'll use the 72K PathTool after all.

Windows 9x:
Changes have to be made in

'C:\autoexec.bat' to include a PATH to your *** executables.
'C:\config.sys' to enhance the memory size to store environmental variables
to at least 4096 bytes. You need a line
shell=C:\command.com C:\ /e:4096 /p
in your C:\CONFIG.SYS, assuming that COMMAND.COM resides in C:\ on your
system. If COMMAND.COM is not present in C:\ on your system it is usually
present in the main Windows directory, i.e. C:\WINDOWS by default. Then you
have to set
shell=C:\WINDOWS\command.com C:\WINDOWS /e:4096 /p
instead.
Don't forget to reboot your computer after changes have been done!

---------------------------

Windows ME:
Changing the environment size has to be made as follows:

Browse to your Windows directory (for example, C:\Windows).
Right-click Command.com, and then click Properties from its pop-up menu.
Click the Memory tab.
In the Initial Environment box, set the initial environment size to at least
4096 bytes. Click OK.
Don't forget to reboot your computer after changes have been done!

---------------------------

Windows NT:
Changing the PATH environment variable has to be made as follows:

Right-click on your 'My System' icon on the Desktop and then click
Properties from its pop-up menu.
Here you can specify/change 'System variables', i.e. PATH to ensure all
necessary programs could be found.
On older NT ssystems changes have to be done as described for Windows 9x.
But you have to respect the following:
'autoexec.bat' is located in 'C:\WinNT\System32\autoexec.nt'
'config.sys' is located in 'C:\WinNT\System32\config.nt'
'command.com' is located in 'C:\WinNT\System32\command.com'

---------------------------

Windows 2000:
Changing the PATH environment variable has to be made as follows:

Right-click on your 'My System' icon on the Desktop and then click
Properties from its pop-up menu.
Switch to the 'Advanced' tab and open 'Environment Variables'. Here you can
specify/change 'System variables', i.e. PATH to ensure all necessary
programs could be found.
You don't need to enhance the environment size!