
Adding Environmental Variable to System Variables thru VB
You can read & write to the registry environment settings directly, or use
the Wscript.environment object.
dim wSH
dim oSenv
dim sCurPath
dim sNewPath
Set wSH = WScript.CreateObject ("WSCript.shell")
set oSysenv=wscript.createObject ("Wscript.environment")
'// Method one
sCurPath = wSH.RegRead("HKLM\System\CurrentControlSet\Control\Session
Manager\Environment\path")
'// todo: Search sCurPath for H:\myapp before appending it
sNewPath = sCurPath & ";H:\myapp"
wSH.RegWrite "HKLM\System\CurrentControlSet\Control\Session
Manager\Environment\path", sNewPath, "REG_SZ"
'// echo the new path
WScript.Echo wSH.RegRead("HKLM\System\CurrentControlSet\Control\Session
Manager\Environment\path")
'//Method two
oSysenv("path")= oSysenv("path") & ";H:\myapp"
wScript.echo oSysenv("path")
Quote:
> Not sure if I can do that.... this app is an add on module for another
> larger app and there is no install on the workstation except to add this
> statement to the System Variables. I called tech support about this
before
> and they gave me the standard response,"We only support entering it in the
> System Variables".
> I'm a software/hardware consultant and basically the reason for this is to
> ensure my clients do this step. I document, I preach, I post notes on
their
> monitors and everytime a client upgrades a machine they forget this step.
I
> deal with a lot of very non-technical clients and if i had a script I
could
> have a client run it would save me a lot of stupid support calls (and
> possible mistakes).
> thanks again
> rob
> > Are you sure you need to modify the PATH variable? This is an old,
> > difficult way of doing things. It still works, but mostly for backwards
> > compatibility.
> > If you do need an environment variable, it would be a better approach to
> use
> > a custom variable and store only your data directory in it, and leave
the
> > system PATH alone.
> > The recommended way would be to add a Registry value with the location
of
> > the data folder, and then the app would read this registry value. Would
> > this be an option for you?
> > > I support an app that needs a statement added to the PATH variable.
It
> > > basically
> > > tells windows where to look for the app data directory.
> > > PATH=H:/APP/APPFOLDER
> > > I'm still new to VB scripting so any help would be great.
> > > Thanks
> > > Rob