|
-
Apr 7th, 2003, 05:52 AM
#1
Thread Starter
Frenzied Member
Is the logged in user an administrator?
How (in VB.Net) do I find out if the logged in user is an administrator?
-
Apr 7th, 2003, 08:52 AM
#2
Hyperactive Member
If you mean local admin, you should be able to get what you need from this sample.
Check out where I invoke IsMember.
Code:
Private Function AddUserToWinGroup(ByVal szGroup As String, ByVal szUser As String) As Boolean
Const MODULE_NAME = "AddUserToWinGroup"
Const ADSI_PROVIDER = "WinNT://"
Dim szPathGroup As String = ADSI_PROVIDER & m_szLocalMachine & "/" & szGroup & ",group"
' the username comes in looking like <domain>\<username>
' we need it to look like <domain>/<username> for ADSI to work
Dim szPathUser As String = ADSI_PROVIDER & szUser.Replace("\", "/") & ""
Try
Dim entryGroup As New DirectoryServices.DirectoryEntry(szPathGroup)
' Dim entryUser As New DirectoryServices.DirectoryEntry(szPathUser)
' only add the user if not already a member
If Not entryGroup.Invoke("ismember", szPathUser) Then
entryGroup.Invoke("add", szPathUser)
End If
Catch
m_szLastError = MODULE_NAME & ": " & Err.Description
Return False
End Try
Return True
End Function
-
Apr 7th, 2003, 10:09 AM
#3
VB Code:
Dim wp As New Security.Principal.WindowsPrincipal(Security.Principal.WindowsIdentity.GetCurrent)
MsgBox(wp.IsInRole(Security.Principal.WindowsBuiltInRole.Administrator), , wp.Identity.Name)
'for none built in groups just use a string (domain\group)
MsgBox(wp.IsInRole("MHC\PS Admins"), , wp.Identity.Name)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|