How can I Access Environnemental variable
-
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
-
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
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
-
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
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
-
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
-
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.
-
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
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
-
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
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. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
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. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~