Determine if user has administrator rights (windows)
-
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.
-
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. -
< offtopic >
Oh, such a lot of tags for only twelve comments.
< /offtopic > -
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 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.
-
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.
-
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"?