|
-
Jul 16th, 2010, 01:58 AM
#1
Thread Starter
Addicted Member
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.
-
Jul 16th, 2010, 02:00 AM
#2
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).
-
Jul 16th, 2010, 02:14 AM
#3
Thread Starter
Addicted Member
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!
Last edited by FuzMic; Jul 16th, 2010 at 02:21 AM.
-
Jul 16th, 2010, 04:10 AM
#4
Re: Change Environ using SetEnv..Var.A
i believe it will only set for the instance your program runs in
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 17th, 2010, 01:44 PM
#5
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.
-
Jul 18th, 2010, 10:38 PM
#6
Thread Starter
Addicted Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|