couldn’t access registry HKLM keys from windows xp limited/guest user accounts
public int GetEnabledStatus()
{
RegistryKey hklm = Registry.LocalMachine;
int Res;
try
{
RegistryKey run1 =
hklm.OpenSubKey(@"Software\Microsoft\Windows\myApp", true);
hkcu.OpenSubKey(@"Software\Microsoft\Windows\myApp", true);
Res = int.Parse(run1.GetValue("enabled").ToString());
}
catch
{
Res = 0;
return Res;
}
finally
{
hklm.Close();
}
return Res;
}
this code works fine in administrator user accounts, under limited/guest accounts call to this function doest not return value. is there any work around
You are opening the keys in “write” mode (2nd parameter is set to ‘true’). As a limited user, you do not have permissions to write to HKLM. By changing mode to “readonly” (2nd parameter set to ‘false’) you should be able to read the value.
I would recommend updating the code as follows:
No need for exception handling, works on my machine when run as limited user :-).