You will need to use an API to determine if the current user has administrative rights or not.
Luckily, there is one function that returns 0
for False
to indicate the status of the current user. Namely: IsUserAnAdmin
Here is how to declare it and use it:
'In a module file:
Public Declare Function IsUserAnAdmin Lib "Shell32" Alias "#680" () As Integer
Then in your Form_Load()
Sub Form_Load()
If IsUserAnAdmin() = 0 Then
MsgBox "Not admin"
Else
MsgBox "Admin"
End If
End Sub
Note: The Shell function IsUserAnAdmin
is depricated. You can replace the functionality with something like (pseudocode):
Boolean IsUserAdmin()
{
PSID administratorsGroup = StringToSid("S-1-5-32-544"); //well-known Administrators group
Boolean isAdmin;
if (not CheckTokenMembership(0, administratorsGroup, out isAdmin) then
isAdmin = false;
FreeSid(administratorsGroup);
return isAdmin;
}