Adding Environmental Variable to System Variables thru VB 
Author Message
 Adding Environmental Variable to System Variables thru VB

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



Sun, 06 Nov 2005 22:16:57 GMT  
 Adding Environmental Variable to System Variables thru VB

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?


Quote:
> 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



Sun, 06 Nov 2005 22:57:17 GMT  
 Adding Environmental Variable to System Variables thru VB
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


Quote:

> 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



Sun, 06 Nov 2005 23:41:27 GMT  
 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



Mon, 07 Nov 2005 11:40:11 GMT  
 Adding Environmental Variable to System Variables thru VB
Note: the data type should be REG_EXPAND_SZ instead of REG_SZ


Quote:
> 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")



> > 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



Mon, 07 Nov 2005 12:30:19 GMT  
 Adding Environmental Variable to System Variables thru VB

Quote:

>I support an app that needs a statement added to the PATH variable.

The best way is to use PATHMAN.EXE from the Resource Kit.

For a pure VBS solution, look here:

http://groups.google.com/groups?&selm=o7lhkuknb0fao0kvr93ug4kdmb0r6ao...

In that thread, you will also find a link to where you can download
PATHMAN.EXE.

--
Helge Wunderlich
(Please remove the spam trap if you wish to send email)



Mon, 07 Nov 2005 15:16:32 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Getting environmental variable in VB

2. Getting environmental variable in VB

3. Getting environmental variable in VB

4. DOS Environmental Variables in QBASIC

5. DOS Environmental Variables

6. Setting DOS environmental variables

7. DOS Environmental Variables not working in LoadPicture

8. Setting DOS environmental variable

9. Environmental Variables access

10. cmd.exe environmental variables

11. Environmental Variables

12. creating, setting environmental variables

 

 
Powered by phpBB® Forum Software