My PATH variable contains other enviornment variables. For example: My PATH is "%SOME_PATH%; C:\windows\ ..." and i have the varibale "SOME_PATH" which is.."C:\SomePath"..
When i run this code: -
-
using (Microsoft.Win32.RegistryKey l_key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Session Manager\Environment", false))
-
{
-
return (l_key.GetValue("PATH") as String);
-
}
-
I get "C:\SomePath;C:\windows\ ..." instead of "%SOME_PATH%; C:\windows\ ..."
How do i get the unresolved environment variable?
2 2440
Does Environment.GetEnvironmentVariable("path") work for you?
@insertAlias
It does not. It returns the expanded value. I noticed I forgot to mention in my post I was using .Net 1.1. Shortly after posting I found that RegistryKey.GetValue had an overload that takes Microsoft.Win32.RegistryValueOptions that can have the value of DoNotExpandEnvironmentNames. Exactly what i was looking for...except it doesnt exist in .Net 1.1. Heres the code i finally came around to that works in 1.1: (partialy stripped from .Net 2.0) -
-
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW", SetLastError = true)]
-
static extern int RegQueryValueEx(IntPtr hKey, string lpValueName, int lpReserved, out uint lpType, System.Text.StringBuilder lpData, ref uint lpcbData);
-
-
-
new System.Security.Permissions.EnvironmentPermission(System.Security.Permissions.PermissionState.Unrestricted).Demand();
-
using (Microsoft.Win32.RegistryKey l_key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Session Manager\Environment", false))
-
{
-
System.Reflection.FieldInfo l_reg_info = l_key.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)[0];
-
IntPtr lp_hklm = (IntPtr)l_reg_info.GetValue(l_key);
-
uint lui_buffer = 0;
-
System.Text.StringBuilder ls_ret = null;
-
uint lui_type = 0;
-
RegQueryValueEx(lp_hklm, as_variable, 0, out lui_type, ls_ret, ref lui_buffer);
-
ls_ret = new System.Text.StringBuilder((int)lui_buffer);
-
int success = RegQueryValueEx(lp_hklm, as_variable, 0, out lui_type, ls_ret, ref lui_buffer);
-
-
if (success == 0)
-
return ls_ret.ToString();
-
else
-
throw new Exception("Error reading enviornment variable " + as_variable);
-
}
-
note: this only works for machine level environment variables
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ida |
last post by:
Hi,
I am trying to build an dll with Microsoft Visual C++ but during the linking
phase I get linking errors.
Script.obj : error LNK2019: unresolved external symbol
__imp__PyString_AsString...
|
by: Aravind |
last post by:
we have two files:
1. rc4.c (defines one function "create_pin()")
2. MyImpl.c(calling the function "create_pin()"),This implements JNI
method.
1.When I am trying to create .dll file with one...
|
by: Serge |
last post by:
Hi,
I have no problem creating a static member variable with integers, etc but
when I try the same with a vector then I always get linker errors that the
static member variable is unknown...
|
by: cschettle |
last post by:
I think you need to link with msvcrt.lib
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000...
|
by: Rick Jones |
last post by:
I'm using Visual C++ .NET (V7) along with the beta version of the SDK so I
can use x64 (AMD64) compiler. I launch a Win Svr 2003 x64 Build Env (Retail,
PreRelease) window then issue a devenv/useenv...
|
by: f rom |
last post by:
----- Forwarded Message ----
From: Josiah Carlson <jcarlson@uci.edu>
To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: ...
|
by: sadegh |
last post by:
Hi
I have a problem with my program in VC++6
When I compile it, the following errors are listed. I spend a lot of
time on the groups.google.com to find its reason, but none of comments
could...
|
by: dotyet |
last post by:
Hi Everyone,
I am trying to build a DB2 UDB UDF which can perform regex over the
table data. The user defined function will call an external .dll file
to do the task. I am referring to the...
|
by: =?Utf-8?B?YmFzaA==?= |
last post by:
Hello,
I am compiling a CPP code using Visual studion .net 2003. I get the
following error, despite having windldap.h and wldap32.dll in my include and
lib paths. Here is the error.
uuid.lib...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |