开发者

what is wrong with this code to read specific registry value in a subkey then do a if exist/if not statement

开发者 https://www.devze.com 2023-01-08 19:51 出处:网络
well with some help fr开发者_JS百科om this site and dream in code i fixed my error, but am now the code just plain doesn\'t seem to be working. Here is the code:

well with some help fr开发者_JS百科om this site and dream in code i fixed my error, but am now the code just plain doesn't seem to be working. Here is the code:

using (RegistryKey Key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"))
if (Key != null)
{
    string val = (string)Key.GetValue("COMODO Internet Security");
    if (val == null)
    {
        MessageBox.Show("value not found");
    }
    else
    {
        // use the value
    }
}
else
{
    MessageBox.Show("key not found");
}

and when i use it, it give the "value not found" message box like its supposed to if it doesn't exist, only problem is the value DOES exist... i checked manually through regedit. so whats wrong?


Probably you have the problem to query registry values of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run key on 64-bit operation system from a 32-bit application. In the case you will see values existion only under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run (see http://msdn.microsoft.com/en-us/library/aa384232.aspx). If you use unmanaged API (or invoce) you can open Run key with RegOpenKeyEx and KEY_QUERY_VALUE | KEY_WOW64_64KEY flags (see http://msdn.microsoft.com/en-us/library/aa384129.aspx). You should test whether the application run under 64-bit operation system before using KEY_QUERY_VALUE | KEY_WOW64_64KEY flag. In case of 32-bit operation system you should use KEY_QUERY_VALUE flag only.

0

精彩评论

暂无评论...
验证码 换一张
取 消