Results 1 to 6 of 6

Thread: Changing the Path (environment variable) under VISTA with VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    3

    Changing the Path (environment variable) under VISTA with VB

    Hi, i need to change the "PATH" environment variable in a VB program (Visual Studio 2008). Here is the code i use to add the "C:\TEST\" folder at the end of the existing one.

    test Code:
    1. Dim PathVal As String
    2.  
    3. PathVal = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User)
    4. Environment.SetEnvironmentVariable("Path", PathVal & ";C:\TEST\", EnvironmentVariableTarget.User)

    It work great under Windows XP but under Vista it did'nt work at all (even when running as a administrator).

    How can i change the "PATH" under Vista?

    Thanks in advance...

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: Changing the Path (environment variable) under VISTA with VB

    I know this might not help but according to MSDN it 'should' work.

    However there is an example here http://msdn.microsoft.com/en-us/library/z46c489x.aspx

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    3

    Re: Changing the Path (environment variable) under VISTA with VB

    By the way it's not even the "SetEnvironmentVariable" that give me a error it's the "GetEnvironmentVariable"...

    Let's take this bit of code for exemple:

    Code:
    Dim PathVal As String
    
    On Error GoTo FinTrt
    
    PathVal = System.Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User)
    
    FinTrt:
           If Err.Number <> 0 Then
                MSGBOX(Err.Description)
            Else
                MSGBOX("OK")
            End If
    Under XP i receive "OK" and under VISTA here his the error (Soory for the french error but the Vista is a french one)

    "La référence d'objet n'est pas définie à une instance d'un objet."

    Thanks again...

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Changing the Path (environment variable) under VISTA with VB

    is it possible that the language is the problem? What's the french word for "Path" ???? just taking a stab in the dark here.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    3

    Re: Changing the Path (environment variable) under VISTA with VB

    I don't think the language is the problem because the XP one is in French too and work perfectly.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Changing the Path (environment variable) under VISTA with VB

    Ah.. ok, well, there goes that theory then.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width