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
  1. Home
  2. General Programming
  3. C#
  4. Couldn't able to set the environment variables

Couldn't able to set the environment variables

Scheduled Pinned Locked Moved C#
workspace
9 Posts 4 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.
  • N Offline
    N Offline
    NarVish
    wrote on last edited by
    #1

    Hi I'm trying to set envronment variables programatically using below code. But its failed to set the environment variables.

    System.Environment.SetEnvironmentVariable("PATH", "C:\Dev");

    Thanks in advance

    R D P 4 Replies Last reply
    0
    • N NarVish

      Hi I'm trying to set envronment variables programatically using below code. But its failed to set the environment variables.

      System.Environment.SetEnvironmentVariable("PATH", "C:\Dev");

      Thanks in advance

      D Offline
      D Offline
      Daniel Grondal
      wrote on last edited by
      #2

      Do you see any error messages?

      //daniel

      N 1 Reply Last reply
      0
      • N NarVish

        Hi I'm trying to set envronment variables programatically using below code. But its failed to set the environment variables.

        System.Environment.SetEnvironmentVariable("PATH", "C:\Dev");

        Thanks in advance

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        One thing I see wrong is your specification of the directory.  Try:

        System.Environment.SetEnvironmentVariable("PATH", @"C:\\Dev");
        

        /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        N 1 Reply Last reply
        0
        • D Daniel Grondal

          Do you see any error messages?

          //daniel

          N Offline
          N Offline
          NarVish
          wrote on last edited by
          #4

          No, its not giving any error messages

          D 1 Reply Last reply
          0
          • R Ravi Bhavnani

            One thing I see wrong is your specification of the directory.  Try:

            System.Environment.SetEnvironmentVariable("PATH", @"C:\\Dev");
            

            /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            N Offline
            N Offline
            NarVish
            wrote on last edited by
            #5

            Even though its not working

            1 Reply Last reply
            0
            • N NarVish

              Hi I'm trying to set envronment variables programatically using below code. But its failed to set the environment variables.

              System.Environment.SetEnvironmentVariable("PATH", "C:\Dev");

              Thanks in advance

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Per the documentation: "Creates, modifies, or deletes an environment variable stored in the current process." (Emphasis mine) If you expect the settings to remain in place after the program completes, you'll be disappointed.

              1 Reply Last reply
              0
              • N NarVish

                Hi I'm trying to set envronment variables programatically using below code. But its failed to set the environment variables.

                System.Environment.SetEnvironmentVariable("PATH", "C:\Dev");

                Thanks in advance

                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #7

                Following on PIEBALDconsult's reply, specify EnvironmentVariableTarget.User as the target if you want the environment variable to be set after your process ends. /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                1 Reply Last reply
                0
                • N NarVish

                  No, its not giving any error messages

                  D Offline
                  D Offline
                  Daniel Grondal
                  wrote on last edited by
                  #8

                  So, how do you know its failing? Do you attempt to read it once set or?

                  //daniel

                  N 1 Reply Last reply
                  0
                  • D Daniel Grondal

                    So, how do you know its failing? Do you attempt to read it once set or?

                    //daniel

                    N Offline
                    N Offline
                    NarVish
                    wrote on last edited by
                    #9

                    yes, I've seen system environment variables in my computer properties. those were not set

                    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