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 / C++ / MFC
  4. How can I Access Environnemental variable

How can I Access Environnemental variable

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasequestionsql-serversysadmin
10 Posts 5 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.
  • M Offline
    M Offline
    mikobi
    wrote on last edited by
    #1

    I am using SQl SERVER 2000 as database, and visual c++ 6.0. I want to write my sql server path in a variable and to access it in my program so to write the path. secondly, i want to have in my program the name of my computer and user name. How can I do it ? I learn my self -- modified at 9:32 Tuesday 17th January, 2006

    D M M 3 Replies Last reply
    0
    • M mikobi

      I am using SQl SERVER 2000 as database, and visual c++ 6.0. I want to write my sql server path in a variable and to access it in my program so to write the path. secondly, i want to have in my program the name of my computer and user name. How can I do it ? I learn my self -- modified at 9:32 Tuesday 17th January, 2006

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Using environment variables is usually not a good idea. In any case, you can get them via the following registry keys: HKEY_CURRENT_USER\Environment HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment Also GetEnvironmentVariable().


      "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

      M 1 Reply Last reply
      0
      • D David Crow

        Using environment variables is usually not a good idea. In any case, you can get them via the following registry keys: HKEY_CURRENT_USER\Environment HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment Also GetEnvironmentVariable().


        "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

        M Offline
        M Offline
        mikobi
        wrote on last edited by
        #3

        I want to solve a problem that I have; my main problem is to execute my program outside my PC. As i use SQL SERVER 2000, I usually change manually in my program this variable : dbinit.AddProperty(DBPROP_INIT_DATASOURCE,OLESTR("sem1"); "sem1" is the name of my sQl SERVER 2000 path. Now I need to replace this path by a variable so that if I install my program any where, I will put the environnement variable and i my program I use it because the name of this variable must be the same.like : dbinit.AddProperty(DBPROP_INIT_DATASOURCE,VARPATH); VARPATH is an environnement variable. How can I remplace "sem1" by an environnemnt variable ? How to to do it I learn my self -- modified at 10:25 Tuesday 17th January, 2006

        D 1 Reply Last reply
        0
        • M mikobi

          I am using SQl SERVER 2000 as database, and visual c++ 6.0. I want to write my sql server path in a variable and to access it in my program so to write the path. secondly, i want to have in my program the name of my computer and user name. How can I do it ? I learn my self -- modified at 9:32 Tuesday 17th January, 2006

          M Offline
          M Offline
          mikobi
          wrote on last edited by
          #4

          Help me to access this environnment variable in Visual c++ 6.0 please

          S K 2 Replies Last reply
          0
          • M mikobi

            Help me to access this environnment variable in Visual c++ 6.0 please

            S Offline
            S Offline
            Sebastian Schneider
            wrote on last edited by
            #5

            Like David said: Search the MSDN for GetEnvironmentVariable(). If you dont want to use it, look for Registry Access Methods and use the path he mentioned. You also could use a higher-level file access which evaluates the "Command Line"-Variables and use that instead. Or, if your app is merely a test and not productive, you could pass the name as a parameter (e.g. "myExe -server=sem1"). Using that approach, you could then write a batch file which gets the "-server="-parameter from an environment variable. Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

            1 Reply Last reply
            0
            • M mikobi

              I want to solve a problem that I have; my main problem is to execute my program outside my PC. As i use SQL SERVER 2000, I usually change manually in my program this variable : dbinit.AddProperty(DBPROP_INIT_DATASOURCE,OLESTR("sem1"); "sem1" is the name of my sQl SERVER 2000 path. Now I need to replace this path by a variable so that if I install my program any where, I will put the environnement variable and i my program I use it because the name of this variable must be the same.like : dbinit.AddProperty(DBPROP_INIT_DATASOURCE,VARPATH); VARPATH is an environnement variable. How can I remplace "sem1" by an environnemnt variable ? How to to do it I learn my self -- modified at 10:25 Tuesday 17th January, 2006

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              I'm not sure exactly what you are asking, but is SetEnvironmentVariable() of any help?


              "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

              1 Reply Last reply
              0
              • M mikobi

                I am using SQl SERVER 2000 as database, and visual c++ 6.0. I want to write my sql server path in a variable and to access it in my program so to write the path. secondly, i want to have in my program the name of my computer and user name. How can I do it ? I learn my self -- modified at 9:32 Tuesday 17th January, 2006

                M Offline
                M Offline
                Mayur Mahajan
                wrote on last edited by
                #7

                You can use 'GetComputerName' and 'GetUserName' to retrive name of computer and user name resp. Set/GetEnvironmentVariable API should help you work with the environment variables. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                M 1 Reply Last reply
                0
                • M mikobi

                  Help me to access this environnment variable in Visual c++ 6.0 please

                  K Offline
                  K Offline
                  kakan
                  wrote on last edited by
                  #8

                  Try getenv()

                  M 1 Reply Last reply
                  0
                  • M Mayur Mahajan

                    You can use 'GetComputerName' and 'GetUserName' to retrive name of computer and user name resp. Set/GetEnvironmentVariable API should help you work with the environment variables. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                    M Offline
                    M Offline
                    mikobi
                    wrote on last edited by
                    #9

                    those variables are not known in Visual c++, I have an error undeclared variable: my sentence is : dbinit.AddProperty(DBPROP_INIT_DATASOURCE, getComputerName() ); I insert these libraries : #include #include but the error is there, what to do ?

                    1 Reply Last reply
                    0
                    • K kakan

                      Try getenv()

                      M Offline
                      M Offline
                      mikobi
                      wrote on last edited by
                      #10

                      With getenv it works well. thanks

                      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