Changing Environ variables

FuzMic

DataBase Tinker
Local time
Tomorrow, 02:13
Joined
Sep 13, 2006
Messages
744
Hi friends

I am trying to add an extra eg C:\new to the existing path in the Environment variables using VB

I tried the following:

Declare Function SetEnvironVar Lib "kernel32" Alias "SetEnvironmentVariableA" (ByVal lpName As String, ByVal lpValue As String) As Long

Now_path$ = Environ("Path")
SetEnvironVar "path", Now_Path$ & ";C:\new"

but it did not work. Where did i go wrong?



I next tried to use Shell

Shell "cmd Path = Now_Path$ & ";C:\new"

still don't work?

I could have placed the the command line in a .bat file but i prefer to do it without an extra .bat file and i have not tinkered if it works.


Any help appreciated.
 
Last edited:
try:

Shell "cmd /c SET PATH=" & Now_Path$ & ";C:\new"

or

Shell "cmd /c set PATH=%PATH%;C:\new"
 
Thanks Coach

... but after running both shell when i look at path in cmd prompt there is no change, same unchanged at the MyComputer > Environment variables. Is it a matter of reboot?? In short /c did not work. If it work i would have said short and sweet!!
 
I am curious. I rarely see Windows Apps the need to use the PATH. For example, DLLs, are regestiered. Why do you need to add somehting to the PATH?

What version of VB are you using, VB6 or VB.net?
 
Re: Changing Environ variables - NEW finding

Hi Coach

The reason why i want to change path is allow application to get to a series of dll kept in a different folder other than system32. These dll will not appear in the reference and not required to do so. In Access.03-07 it is VB6 i presume. By the way does Access.10 using vb.net?

My latest finding is shell "Cmd Set Path=%path%;c:\new" do in fact change the path but it is within the new cmd; meaning i can execute an .exe file in the new folder without typing its path.
However on checking with Computer > Environment, the path don't change at all. Thereafter i exit from this instance of Cmd, the new path does not exist anymore.
So that solved the shell issue.


Hence the problem is how to change the path environ for the whole pc, i would image i still have to rely on following:

Declare Function SetEnvironVar Lib "kernel32" Alias "SetEnvironmentVariableA" (ByVal lpName As String, ByVal lpValue As String) As Long
SetEnvironVar "path", %Path& & ";C:\new"

Cheers!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom