Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# SetEnvironmentVariable

C# SetEnvironmentVariable

Scheduled Pinned Locked Moved C#
csharpquestionworkspace
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kir Birger
    wrote on last edited by
    #1

    Is there some trick to using this method? I looked up code samples and they are all just one line: Environment.SetEnvironmentVariable(strName, strValue); Yet when I do it, nothing is changed... I'm trying to modify the PATH variable by the way

    R L 3 Replies Last reply
    0
    • K Kir Birger

      Is there some trick to using this method? I looked up code samples and they are all just one line: Environment.SetEnvironmentVariable(strName, strValue); Yet when I do it, nothing is changed... I'm trying to modify the PATH variable by the way

      R Offline
      R Offline
      Robert M Greene
      wrote on last edited by
      #2

      [DllImport("Kernel32.dll")] public static extern int SetEnvironmentVariable( string name , string value ) ; ............................. There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life. Fiat justitia, et ruat cælum

      K 1 Reply Last reply
      0
      • K Kir Birger

        Is there some trick to using this method? I looked up code samples and they are all just one line: Environment.SetEnvironmentVariable(strName, strValue); Yet when I do it, nothing is changed... I'm trying to modify the PATH variable by the way

        R Offline
        R Offline
        Robert M Greene
        wrote on last edited by
        #3

        http://blogs.msdn.com/brada/archive/2004/02/23/78870.aspx[^] ............................. There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life. Fiat justitia, et ruat cælum

        K 1 Reply Last reply
        0
        • R Robert M Greene

          [DllImport("Kernel32.dll")] public static extern int SetEnvironmentVariable( string name , string value ) ; ............................. There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life. Fiat justitia, et ruat cælum

          K Offline
          K Offline
          Kir Birger
          wrote on last edited by
          #4

          It's integrated into VS2005, but I tried that anyway=). importing that is the same as doing Environment.SetEnviornmentVariable()

          1 Reply Last reply
          0
          • R Robert M Greene

            http://blogs.msdn.com/brada/archive/2004/02/23/78870.aspx[^] ............................. There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life. Fiat justitia, et ruat cælum

            K Offline
            K Offline
            Kir Birger
            wrote on last edited by
            #5

            Very odd... Doing that I get an error on this line: envObject["PATH"] = sPath; Error reads: Unable to cast COM object of type 'System.Management.WbemDefPath' to interface type 'System.Management.IWmiSec'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2FD73A3B-64B3-480D-AEE9-54469D77123E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

            1 Reply Last reply
            0
            • K Kir Birger

              Is there some trick to using this method? I looked up code samples and they are all just one line: Environment.SetEnvironmentVariable(strName, strValue); Yet when I do it, nothing is changed... I'm trying to modify the PATH variable by the way

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              You realise the values will only be changed within your current process? And will not be persisted?

              xacc.ide-0.1.3.2

              K 1 Reply Last reply
              0
              • L leppie

                You realise the values will only be changed within your current process? And will not be persisted?

                xacc.ide-0.1.3.2

                K Offline
                K Offline
                Kir Birger
                wrote on last edited by
                #7

                Then how do i Change the actual values? I've also tried changing them via registry and making a sendmessage call to 'update' them, but it didn't work.

                R 1 Reply Last reply
                0
                • K Kir Birger

                  Then how do i Change the actual values? I've also tried changing them via registry and making a sendmessage call to 'update' them, but it didn't work.

                  R Offline
                  R Offline
                  Robert M Greene
                  wrote on last edited by
                  #8

                  You tried, http://support.microsoft.com/default.aspx?scid=kb;en-us;Q104011[^] ? ............................. There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life. Fiat justitia, et ruat cælum

                  K 1 Reply Last reply
                  0
                  • R Robert M Greene

                    You tried, http://support.microsoft.com/default.aspx?scid=kb;en-us;Q104011[^] ? ............................. There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life. Fiat justitia, et ruat cælum

                    K Offline
                    K Offline
                    Kir Birger
                    wrote on last edited by
                    #9

                    I've tried a few variations of that SendMessage attempt...

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups