Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Determine if user has administrator rights (windows)
Forum Updated to NodeBB v4.3 + New Features

Determine if user has administrator rights (windows)

Scheduled Pinned Locked Moved General and Desktop
23 Posts 5 Posters 20.6k 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.
  • S Offline
    S Offline
    szh1
    wrote on last edited by
    #11

    Sorry about my lack of knowledge about the innards of the Windows operating system. What exactly is the difference between privileges and rights? And if I changed my previous post to:

    Maybe I should just try to edit the registry, and if it fails, I assume the user lacks the correct rights?

    Would that work better?

    By the way, I don't work for Microsoft, and I didn't build Windows either.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      szh1
      wrote on last edited by
      #12

      Why does the MSDN code sample not work in Qt?

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ixSci
        wrote on last edited by
        #13

        What exactly is the difference between privileges and rights?
        It is a really big topic and I'd recommend you to read some articles or books(e.g. Jeffrey Richter) about it if you really have an interest. Shortly - rights is the object specific term and privilege is the system wide term.
        Maybe I should just try to edit the registry, and if it fails, I assume the user lacks the correct rights?
        You can only check if the user has a particular right against a particular registry entry.
        Really you'd better tell us what is your end goal because security in windows isn't the easy topic to explain it in the forum.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          szh1
          wrote on last edited by
          #14

          My application requires registry editing, and in main() I want to make sure the user has the rights to edit the registry so I don't get errors when I try to do it.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DenisKormalev
            wrote on last edited by
            #15

            < offtopic >
            Oh, such a lot of tags for only twelve comments.
            < /offtopic >

            1 Reply Last reply
            0
            • I Offline
              I Offline
              ixSci
              wrote on last edited by
              #16

              Ok, presume you want to check if the user has a right to change some registry entry. You should:
              @
              if(RegOpenKeyEx(XXX, XXX, XXX, KEY_WRITE, XXX) == ERROR_ACCESS_DENIED)
              //user has no right to write in this registry key
              @
              It's just a pseudo-code but I think you'll grasp the idea

              1 Reply Last reply
              0
              • S Offline
                S Offline
                szh1
                wrote on last edited by
                #17

                Thanks! I think I'll try that. But I am still wondering why the MSDN sample code didn't work.

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  ixSci
                  wrote on last edited by
                  #18

                  I don't know, may be some troubles with Windows SDK? Check the headers which you had included whether they have that function declaration.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    szh1
                    wrote on last edited by
                    #19

                    It says I need to include Windows.h, and I did. I also tried including Winbase.h. Still doesn't work.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      szh1
                      wrote on last edited by
                      #20

                      [quote author="ixSci" date="1287770694"]Ok, presume you want to check if the user has a right to change some registry entry. You should:
                      @
                      if(RegOpenKeyEx(XXX, XXX, XXX, KEY_WRITE, XXX) == ERROR_ACCESS_DENIED)
                      //user has no right to write in this registry key
                      @
                      It's just a pseudo-code but I think you'll grasp the idea[/quote]

                      You can actually use QSettings to edit the registry.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        szh1
                        wrote on last edited by
                        #21

                        I just got it working! Here's my code:
                        @
                        // get ready to attempt to edit the registry
                        QSettings adminTest("HKEY_LOCAL_MACHINE", QSettings::NativeFormat);
                        // get the current value and put it back
                        QVariant currentValue = adminTest.value("(Default)");
                        adminTest.setValue("(Default)", currentValue);
                        adminTest.sync();
                        // see if there was an error
                        if (adminTest.status() == QSettings::AccessError)
                        return false;
                        else
                        return true;
                        @

                        Thanks a lot for the help everyone! I definitely learned a lot from this.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          szh1
                          wrote on last edited by
                          #22

                          By the way, I checked, and the above code puts in another "(Default)" Value Name with a Value Data of "@Invalid()". I am not sure if this is good or bad, but it hasn't causes me any problems. You do it at your own risk.

                          1 Reply Last reply
                          0
                          • terma.abaT Offline
                            terma.abaT Offline
                            terma.aba
                            wrote on last edited by
                            #23

                            It is a valid question because: QSettings::Scope allows writes at QSettings::SystemScope - but only if you have sufficient rights (in the general sense of the English word rather than the Microsoft one).

                            The remaining posts seems to be Win API based, so I guess the answer is "no"?

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved