Change Environ using SetEnv..Var.A
Hi forum members
I am trying to add an extra folder eg C:\new to the existing path in the Environment variables using VB6.
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? Help appreciated.
Re: Change Environ using SetEnv..Var.A
What version of Windows are you using? If it's Vista or 7, with UAC on I think you will need admin rights for that (run application as admin).
Re: Change Environ using SetEnv..Var.A
Hello Yu
I was tinkering in xpwin.sp2 using vb6.sp5 as administrator. I came to the conclusion that the path is not changed when i look at the MyPc>properties>Environment Vars. By the way using Shell "cmd set path = ..new.." it will change the path temporary for that instance of cmd and will revert to the old path after closing that instance of cmd.
Hope u can throw some light on the setEnv function. Cheers!
Re: Change Environ using SetEnv..Var.A
i believe it will only set for the instance your program runs in
Re: Change Environ using SetEnv..Var.A
Applications are not supposed to do this at runtime anyway. It is an installer function.
If you do this programmatically you risk adding your path to the paths list once for every run. Even Adobe did this with Reader one release recently and they got flamed nastily for doing it.
If you package with VSI 1.1 or another tool for creating MSI (Microsoft Installer) packages you can edit the Environment Table with Orca to include your path during installation and remove it upon uninstall.
Re: Change Environ using SetEnv..Var.A
Thanks all of you for the response. As dil.. already said, if we can access the PC we can change the environ without resorting to an Application. Cheers!