Did you ever want to know if the user has Administrator rights?
Some programs rely on the user to be an administrator, this simple function does just that.
Credits Digital Thunder : http://www.codeproject.com/KB/vb/SysInfo.aspx
Imports System.Security.Principal
Imports System.Threading
' A function to return the Admin status of the user running our program.
Public Function IsAdmin() As Boolean
IsAdmin = False
Dim securityGroup As WindowsPrincipal
' Get the security credentials of the user that is running our program.
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
securityGroup = CType(Thread.CurrentPrincipal, WindowsPrincipal)
' Are they a member of the Administrators Group?
If securityGroup.IsInRole(WindowsBuiltInRole.Administrator) Then
IsAdmin = True
End If
Return IsAdmin
End Function
No comments:
Post a Comment