windows 7 UAC
-
Hi All I am try find out UAC is Enable or Disable through this code
HKEY pHKey; BYTE pData\[64\]; DWORD type = REG\_DWORD; DWORD size =64; LONG uVal = RegOpenKeyEx(HKEY\_LOCAL\_MACHINE,"SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System",0,KEY\_ALL\_ACCESS, &pHKey); if(uVal != ERROR\_SUCCESS) { //return 0; } RegQueryValueEx(pHKey, \_T("EnableLUA"), 0, &type, pData, &size); if(pData\[0\] == 1) { //UAC Enable } if(pData\[0\] == 0) { // UAC Disable } RegCloseKey(pHKey);
But it always show Enable.If UAC is enable or disable. Please help me.
-
Hi All I am try find out UAC is Enable or Disable through this code
HKEY pHKey; BYTE pData\[64\]; DWORD type = REG\_DWORD; DWORD size =64; LONG uVal = RegOpenKeyEx(HKEY\_LOCAL\_MACHINE,"SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System",0,KEY\_ALL\_ACCESS, &pHKey); if(uVal != ERROR\_SUCCESS) { //return 0; } RegQueryValueEx(pHKey, \_T("EnableLUA"), 0, &type, pData, &size); if(pData\[0\] == 1) { //UAC Enable } if(pData\[0\] == 0) { // UAC Disable } RegCloseKey(pHKey);
But it always show Enable.If UAC is enable or disable. Please help me.
Why didn't you check
RegQueryValueEx
return value? Anyway I would do:...
DWORD dwEnable;
size = sizeof(dwEnable);
...
LONG lRet = RegQueryValueEx(pHKey, _T("EnableLUA"), 0, &type, (BYTE*) &dwEnable, &size);
if ( lRet != ERROR_SUCCESS)
{
// handle error
}
else
{
if(dwEnable == 1)
{
// UAC Enabled
}
else
{
// UAC Disabled
}
}[added]Thanks to MsmVc for pointing out the mistake[/added] :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]modified on Saturday, November 20, 2010 8:20 AM
-
Why didn't you check
RegQueryValueEx
return value? Anyway I would do:...
DWORD dwEnable;
size = sizeof(dwEnable);
...
LONG lRet = RegQueryValueEx(pHKey, _T("EnableLUA"), 0, &type, (BYTE*) &dwEnable, &size);
if ( lRet != ERROR_SUCCESS)
{
// handle error
}
else
{
if(dwEnable == 1)
{
// UAC Enabled
}
else
{
// UAC Disabled
}
}[added]Thanks to MsmVc for pointing out the mistake[/added] :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]modified on Saturday, November 20, 2010 8:20 AM
-
Why didn't you check
RegQueryValueEx
return value? Anyway I would do:...
DWORD dwEnable;
size = sizeof(dwEnable);
...
LONG lRet = RegQueryValueEx(pHKey, _T("EnableLUA"), 0, &type, (BYTE*) &dwEnable, &size);
if ( lRet != ERROR_SUCCESS)
{
// handle error
}
else
{
if(dwEnable == 1)
{
// UAC Enabled
}
else
{
// UAC Disabled
}
}[added]Thanks to MsmVc for pointing out the mistake[/added] :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]modified on Saturday, November 20, 2010 8:20 AM
One more thing i want to discuss with you.When i follow your step then i am getting UAC Enable or Disabled in Windows 7. Same code when i am running on Vista then give error.But when i run code Run AS Admin then show UAC Enable or Disable. Can you explain me why this type of result showing. Please help me
-
One more thing i want to discuss with you.When i follow your step then i am getting UAC Enable or Disabled in Windows 7. Same code when i am running on Vista then give error.But when i run code Run AS Admin then show UAC Enable or Disable. Can you explain me why this type of result showing. Please help me
Access to the
HKEY_LOCAL_MACHINE
subtree is protected.MsmVc wrote:
Same code when i am running on Vista then give error.But when i run code Run AS Admin then show UAC Enable or Disable.
It looks like the only way to obtain it (It looks like you cannot programmatically elevate current process privileges, see, for instance here[^]) however, I'm not an expert. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]