Solved

Retrieve Windows User priviledges vba

Posted on 2013-12-17
3
218 Views
Last Modified: 2014-01-12
In VBA, I'm trying to determine the type of privileges for the current logged in user account (Guest, standard or administrator)
0
Comment
Question by:askolits
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Assisted Solution

by:Steven Harris
Steven Harris earned 230 total points
ID: 39737285
VB or VBA?

With VB, you can use the following which will look for the current user, displayed as GROUP, then USER:

Option Explicit
Dim objNetwork, objLocalGroup
Dim objTrans, strComputer, strNetBIOSDomain
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Set objNetwork = CreateObject("Wscript.Network")
strNetBIOSDomain = objNetwork.UserDomain
strComputer = objNetwork.ComputerName
Set objNetwork = Nothing
Set objLocalGroup = GetObject("WinNT://" & strComputer _
    & "/Administrators,group")
Call EnumLocalGroup(objLocalGroup)
Sub EnumLocalGroup(ByVal objGroup)
    Dim objMember
    For Each objMember In objGroup.Members
        Wscript.Echo objMember.AdsPath
        If (LCase(objMember.Class) = "group") Then
            If (InStr(LCase(objMember.AdsPath), "/" _
                    & LCase(strComputer) & "/") > 0) Then
                Call EnumLocalGroup(objMember)
            ElseIf (InStr(LCase(objMember.AdsPath), _
                    "/nt authority/") > 0) Then
            Else
                Call EnumDomainGroup(objMember, True)
            End If
        End If
    Next
End Sub
Sub EnumDomainGroup(ByVal objDomainGroup, ByVal blnNT)
    Dim strNTName, strGroupDN, objGroup, objMember
    If (IsEmpty(objTrans) = True) Then
        Set objTrans = CreateObject("NameTranslate")
        objTrans.Init ADS_NAME_INITTYPE_GC, ""

        strNTName = strNetBIOSDomain & "\" & objDomainGroup.Name
        objTrans.Set ADS_NAME_TYPE_NT4, strNTName
        strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
        strGroupDN = Replace(strGroupDN, "/", "\/")
    Else
        If (blnNT = True) Then
            strNTName = strNetBIOSDomain & "\" & objDomainGroup.Name
            objTrans.Set ADS_NAME_TYPE_NT4, strNTName
            strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
            strGroupDN = Replace(strGroupDN, "/", "\/")
        Else
            strGroupDN = objDomainGroup.distinguishedName
            strGroupDN = Replace(strGroupDN, "/", "\/")
        End If
    End If
    If (blnNT = True) Then
        Set objGroup = GetObject("LDAP://" & strGroupDN)
    Else
        Set objGroup = objDomainGroup
    End If
    For Each objMember In objGroup.Members
        Wscript.Echo objMember.AdsPath
        If (LCase(objMember.Class) = "group") Then
            Call EnumDomainGroup(objMember, False)
        End If
    Next
End Sub

Open in new window

0
 

Accepted Solution

by:
askolits earned 0 total points
ID: 39763144
Finally got around to testing this.
I needed it for VBA and I have modified it to work with VBA.
I'm going to play around with it a bit more with different OS's, but it seems to work for me.

Option Compare Database
Option Explicit

Public objNetwork, objLocalGroup
Public objTrans, strComputer, strNetBIOSDomain

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1


Sub EnumLocalGroup(ByVal objGroup)
    Dim objMember
    For Each objMember In objGroup.Members
        Debug.Print objMember.AdsPath
        If (LCase(objMember.Class) = "group") Then
            If (InStr(LCase(objMember.AdsPath), "/" _
                    & LCase(strComputer) & "/") > 0) Then
                Call EnumLocalGroup(objMember)
            ElseIf (InStr(LCase(objMember.AdsPath), _
                    "/nt authority/") > 0) Then
            Else
                Call EnumDomainGroup(objMember, True)
            End If
        End If
    Next
End Sub
Sub EnumDomainGroup(ByVal objDomainGroup, ByVal blnNT)
    Dim strNTName, strGroupDN, objGroup, objMember
    If (IsEmpty(objTrans) = True) Then
        Set objTrans = CreateObject("NameTranslate")
        objTrans.Init ADS_NAME_INITTYPE_GC, ""

        strNTName = strNetBIOSDomain & "\" & objDomainGroup.Name
        objTrans.Set ADS_NAME_TYPE_NT4, strNTName
        strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
        strGroupDN = Replace(strGroupDN, "/", "\/")
    Else
        If (blnNT = True) Then
            strNTName = strNetBIOSDomain & "\" & objDomainGroup.Name
            objTrans.Set ADS_NAME_TYPE_NT4, strNTName
            strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
            strGroupDN = Replace(strGroupDN, "/", "\/")
        Else
            strGroupDN = objDomainGroup.distinguishedName
            strGroupDN = Replace(strGroupDN, "/", "\/")
        End If
    End If
    If (blnNT = True) Then
        Set objGroup = GetObject("LDAP://" & strGroupDN)
    Else
        Set objGroup = objDomainGroup
    End If
    For Each objMember In objGroup.Members
        Debug.Print objMember.AdsPath
        If (LCase(objMember.Class) = "group") Then
            Call EnumDomainGroup(objMember, False)
        End If
    Next
End Sub

Sub GetCurrentUserLevel()
Set objNetwork = CreateObject("Wscript.Network")
strNetBIOSDomain = objNetwork.UserDomain
strComputer = objNetwork.computername
Set objNetwork = Nothing
Set objLocalGroup = GetObject("WinNT://" & strComputer _
    & "/Administrators,group")
Call EnumLocalGroup(objLocalGroup)
 
End Sub

Open in new window

0
 

Author Closing Comment

by:askolits
ID: 39774467
I made a modification to make it work with VBA.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configuring Remote Assistance for use with SCCM
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question