LeighWardle
asked on
vb.net - How to check if current user is an administrator?
Hi Experts,
How can I check if the current user of my application is an administrator?
Regards,
Leigh
How can I check if the current user of my application is an administrator?
Regards,
Leigh
The NET USER command gives this to you. Run inside VB.
ASKER
Thanks, John.
I was hoping for a simple function call from VB.NET.
But I will use CMD if necessary.
I was hoping for a simple function call from VB.NET.
But I will use CMD if necessary.
Use a native .Net method such as My.User.IsInRole.
See here -> https://msdn.microsoft.com/en-us/library/ms172996(v=vs.90).aspx
See here -> https://msdn.microsoft.com/en-us/library/ms172996(v=vs.90).aspx
ASKER
Thanks, Wayne.
I tried using the example on the Microsoft webpage you quoted.
Here's my code:
But I'm logged in as an Administrator, but the code is outputting:
User is not Administrator
I tried using the example on the Microsoft webpage you quoted.
Here's my code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
MsgBox("User is Administrator")
Else
MsgBox("User is not Administrator")
End If
End Sub
End Class
But I'm logged in as an Administrator, but the code is outputting:
User is not Administrator
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Wayne,
Thanks for the insights regarding Administrator mode.
The application works OK when I start it using Run As Administrator.
That meets my needs.
Regards,
Leigh
Thanks for the insights regarding Administrator mode.
The application works OK when I start it using Run As Administrator.
That meets my needs.
Regards,
Leigh