Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. windows 7 UAC

windows 7 UAC

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MsmVc
    wrote on last edited by
    #1

    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.

    CPalliniC 1 Reply Last reply
    0
    • M MsmVc

      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.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      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

      In testa che avete, signor di Ceprano?

      M 2 Replies Last reply
      0
      • CPalliniC CPallini

        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

        M Offline
        M Offline
        MsmVc
        wrote on last edited by
        #3

        Thanks for reply

        modified on Saturday, November 20, 2010 7:03 AM

        1 Reply Last reply
        0
        • CPalliniC CPallini

          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

          M Offline
          M Offline
          MsmVc
          wrote on last edited by
          #4

          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

          CPalliniC 1 Reply Last reply
          0
          • M MsmVc

            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

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            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]

            In testa che avete, signor di Ceprano?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups