Jump to content

How to call Windows "Browse for User" box?


ken82m
 Share

Recommended Posts

Does anyone know if or how you can call the browse for user box?

The one you get if for example, you were adding a user to an ACL on a file in windows.

If so do you know how to lock the Object type option? I only want to allow the user to select the user accounts.

Thanks,

Kenny

EDIT: See VB code posted below

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

that's exactly what I need

Now I just need someone to show me how to conert it to AutoIT lol :mellow:

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I read there was a com wrapper on there. Perhaps it will give you the properties to use? Then again "when in doubt...google" or "google the hell out of that skanker!", whichever you prefer lol.

Link to comment
Share on other sites

lol

I found the one com wrapper you mentioned but it seems to have some limitations including not being able to restrict what type of object can be selected.

The user could select a computer if they wanted to.

If anyone is willing I found this other VB example which was much simpler.

It looks pretty simple I think... lol

Half of it seems to be just declaring variables.

Here's a link to the page:

http://vbnet.mvps.org/index.html?code/netw...userbrowser.htm

Thanks,

Kenny

And the actual VB code on the page:

Private Const NERR_SUCCESS                          As Long = 0&
Private Const OPENUSERBROWSER_INCLUDE_SYSTEM          As Long = &H10000
Private Const OPENUSERBROWSER_SINGLE_SELECTION      As Long = &H1000&
Private Const OPENUSERBROWSER_NO_LOCAL_DOMAIN        As Long = &H100&
Private Const OPENUSERBROWSER_INCLUDE_CREATOR_OWNER   As Long = &H80&
Private Const OPENUSERBROWSER_INCLUDE_EVERYONE      As Long = &H40&
Private Const OPENUSERBROWSER_INCLUDE_INTERACTIVE    As Long = &H20&
Private Const OPENUSERBROWSER_INCLUDE_NETWORK        As Long = &H10&
Private Const OPENUSERBROWSER_INCLUDE_USERS        As Long = &H8&
Private Const OPENUSERBROWSER_INCLUDE_USER_BUTTONS  As Long = &H4&
Private Const OPENUSERBROWSER_INCLUDE_GROUPS          As Long = &H2&
Private Const OPENUSERBROWSER_INCLUDE_ALIASES        As Long = &H1&
Private Const OPENUSERBROWSER_FLAGS                As Long = OPENUSERBROWSER_INCLUDE_USERS Or _
                                                                OPENUSERBROWSER_INCLUDE_USER_BUTTONS Or _
                                                                OPENUSERBROWSER_INCLUDE_EVERYONE Or _
                                                                OPENUSERBROWSER_INCLUDE_INTERACTIVE Or _
                                                                OPENUSERBROWSER_INCLUDE_NETWORK Or _
                                                                OPENUSERBROWSER_INCLUDE_ALIASES
Private Type OPENUSERBROWSER_STRUCT
   cbSize       As Long
   fCancelled   As Long
   Unknown     As Long
   hWndParent   As Long
   szTitle     As Long
   szDomainName  As Long
   dwFlags     As Long
   dwHelpID   As Long
   szHelpFile   As Long
End Type

Private Type ENUMUSERBROWSER_STRUCT
   SidType      As Long
   Sid1        As Long
   Sid2        As Long
   szFullName    As Long
   szUserName    As Long
   szDisplayName  As Long
   szDomainName   As Long
   szDescription  As Long
   sBuffer      As String * 1000
End Type

Private Declare Function OpenUserBrowser Lib "netui2.dll" _
  (lpOpenUserBrowser As Any) As Long
   
Private Declare Function EnumUserBrowserSelection Lib "netui2.dll" _
  (ByVal hBrowser As Long, _
   ByRef lpEnumUserBrowser As Any, _
   ByRef cbSize As Long) As Long
   
Private Declare Function CloseUserBrowser Lib "netui2.dll" _
   (ByVal hBrowser As Long) As Long
   
Private Declare Function lstrlenW Lib "kernel32" _
   (ByVal lpString As Long) As Long
   
Private Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
  (Destination As Any, _
   Source As Any, _
   ByVal Length As Long)


Private Sub Form_Load()

   Dim cnt As Long

  'load and show 11 Check1 controls
   For cnt = 0 To 10
      
      If cnt <> 0 Then Load Check1(cnt)
      
      With Check1(cnt)
      
         If cnt < 6 Then
            .Move 360, 360 + (Check1(cnt).Height * cnt), 2500
         Else
            .Move 2860, 360 + (Check1(cnt).Height * (cnt - 6)), 2500
         End If
         
         Select Case cnt
            Case 0:  .Caption = "include aliases"
            Case 1:  .Caption = "include groups"
            Case 2:  .Caption = "include user buttons"
            Case 3:  .Caption = "include users"
            Case 4:  .Caption = "include network"
            Case 5:  .Caption = "include 'interactive'"
            Case 6:  .Caption = "include 'everyone'"
            Case 7:  .Caption = "include 'creator owner'"
            Case 8:  .Caption = "include 'system'"
            Case 9:  .Caption = "single selection"
            Case 10: .Caption = "no local domain"
            Case Else
         End Select
      
         .Visible = True
      
      End With
      
   Next

   With Command1
      .Caption = "OpenUserBrowser"
      .Move Check1(5).Left, _
           (Check1(5).Height * 5) + 780
   End With
   
   With Text1
      .Move Command1.Left, _
            Command1.Top + Command1.Height + 300, _
            Me.ScaleWidth - 720
                  
      Me.Height = .Top + .Height + 780
      
   End With 
   
End Sub


Private Sub Command1_Click()

   Dim sUsers As String

   If GetBrowserNames(Me.hWnd, _
                      "\\vbnetdev", _
                      "VBnet Add Users & Groups Demo", _
                      sUsers) Then
      Text1.Text = sUsers
   End If

End Sub


Private Function BuildFlags() As Long

  'using a var to shorten web display ...
  'in application can replace var with
  'the function name itself
   Dim bf As Long

  'clear and set flags
   bf = 0&
   
   If Check1(0).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_ALIASES
   If Check1(1).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_GROUPS
   If Check1(2).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_USER_BUTTONS
   If Check1(3).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_USERS
   If Check1(4).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_NETWORK
   If Check1(5).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_INTERACTIVE
   If Check1(6).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_EVERYONE
   If Check1(7).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_CREATOR_OWNER
   If Check1(8).Value = 1 Then bf = bf Or OPENUSERBROWSER_INCLUDE_SYSTEM
   If Check1(9).Value = 1 Then bf = bf Or OPENUSERBROWSER_SINGLE_SELECTION
   If Check1(10).Value = 1 Then bf = bf Or OPENUSERBROWSER_NO_LOCAL_DOMAIN
   
   BuildFlags = bf

End Function


Private Function GetBrowserNames(ByVal hParent As Long, _
                                 ByVal sDomain As String, _
                                 ByVal sTitle As String, _
                                 sBuff As String) As Boolean

   Dim hBrowser   As Long
   Dim browser  As OPENUSERBROWSER_STRUCT
   Dim enumb      As ENUMUSERBROWSER_STRUCT
   
  'initialize the OPENUSERBROWSER structure
   With browser
      .cbSize = Len(browser)
      .fCancelled = 0
      .Unknown = 0
      .hWndParent = hParent
      .szTitle = StrPtr(sTitle)
      .szDomainName = StrPtr(sDomain)
      .dwFlags = BuildFlags()
   End With
   
  'show the dialog function
   hBrowser = OpenUserBrowser(browser)
   
  'if not cancelled...
   If browser.fCancelled = NERR_SUCCESS Then
   
      '...retrieve any selections and populate
      'the sBuff string passed to this function,
      'returning True if successful.
       Do While EnumUserBrowserSelection(hBrowser, enumb, Len(enumb) + 1) <> 0
       
          'return selection as \\DOMAIN\NAME
          'can be adjusted at will
           sBuff = sBuff & GetPointerToByteStringW(enumb.szDomainName) & "\" & _
                           GetPointerToByteStringW(enumb.szUserName) & vbCrLf
                           
           GetBrowserNames = True
           
       Loop
       
       Call CloseUserBrowser(hBrowser)
       
      'if desired, strip the last crlf from the string
       If GetBrowserNames = True Then
           sBuff = Left(sBuff, Len(sBuff) - 2)
       End If
   End If
    
End Function


Private Function GetPointerToByteStringW(ByVal dwData As Long) As String
  
   Dim tmp() As Byte
   Dim tmplen As Long
   
   If dwData <> 0 Then
   
      tmplen = lstrlenW(dwData) * 2
      
      If tmplen <> 0 Then
      
         ReDim tmp(0 To (tmplen - 1)) As Byte
         CopyMemory tmp(0), ByVal dwData, tmplen
         GetPointerToByteStringW = tmp
         
     End If
     
   End If
    
End Function
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Thanks but ahh it's all gibberish to me lol :mellow:

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I'll give a cookie to anyone who has something lol :mellow:

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...