Minor: Why is it that even if a User has admin rights, they still have to explicitly run an app as Administrator?
Major: How can I detect programmatically that a user is running with Administrator rights? I mean, not just his Account-dictated rights, but those that come from launching the app as Run as administrator… (see minor question).
Ah, actually, I use an amended method that contains this bit at the top.
if System.IsFunctionAvailable( "IsUserAnAdmin", "shell32" ) then
declare function IsUserAnAdmin Lib "shell32" () as Boolean
Return IsUserAnAdmin
end if
Edit to add the link to the documentation page for this function:
Thanks Anthony! Two questions: Doesn’t your ammendum apply all the time? When would that function ever not exist? It says in the spec that it goes back to XP. Also, the Advanced Build thing - doesn’t that apply to just Debug builds? Or is that just my confusion?
Also applies to builds. There is no exclusionary statement in the documentation here or here, and I’ve been using this successfully since it was added.
So really you took this 100 line code snippet and pared it down to 3? Impressive! (I’m not talking about it replacing Aaron’s code, but again I can’t see your found-Shell function ever NOT existing. Except in based OS installs. But that doesn’t happen anymore really.) It’d be, in your words, "in"sane. =)
I still use the combination of both checks. I think there was some reason, but I’ve not needed to review that code in a very long time since it just works now.
Using IsFunctionAvailable() is only useful with soft declares. This sanity check will never be reached on a system where it would fail because the app has already crashed.
if System.IsFunctionAvailable( "IsUserAnAdmin", "shell32" ) then
soft declare function IsUserAnAdmin Lib "shell32" () as Boolean
Return IsUserAnAdmin
end if
@Garth_Hjelte Please be sure to pick a solution so that it’s easier for others who come across this in the future.