Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grab usernames

Status
Not open for further replies.

neoice

Programmer
Feb 15, 2003
110
GB
Hello,

Does anybody know how I can grab all the usernames from an NT 4.0 domain. I basically want to populate a list box with all usernames.
I have visual basic 6

thanks in advance

neil
 
Neil,
How are you storing the names? I know a way to retrieve but it require a bit of user assistance.
Code:
Public Sub The_User_Initiated_this_vent()

Dim strUserName as String

strUserName = Environ("UserName")

'Put your code here to do what ever you want to with the
'strUserName

End Sub

Environ works well in nt...not so well in xp

Good look
Scoty ::)

"Learn from others' mistakes. You could not live long enough to make them all yourself."
-- Hyman George Rickover (1900-86),
 
I have used this function:

The corprate LAN is somewhat tweaked so I am not sure if the call is to a generic NT object, and thus available to you or if it is unique to our NT. I borrowed the code from another application and have used it many times. Hopefully it works.


Private Function PullSysID() As String
'returns the ID
Dim objICFVars
Const kErr As String = "PullSysID "
On Error GoTo Error1
Set objICFVars = CreateObject("ICF.vars")
PullSysID = objICFVars.UserID
Set objICFVars = Nothing

On Error GoTo 0
Exit Function
Error1:
On Error GoTo 0
MsgBox (MsgStr & kErr & Err.Description)
Set objICFVars = Nothing
End Function
 
Unfortunately both of the above only get the name of the current user on the local machine. The following thread contains two solutions that get the list of users in an entire NT4 domain, one from rorubin and one from me: thread222-469216
 
Try using ADSI.
___
[tt]
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Sub Form_Load()
Dim Users, User, N As Long, Domain As String
N = 100
Domain = Space$(N)
GetComputerName Domain, N
Domain = Left$(Domain, N)
Set Users = GetObject("WinNT://" & Domain)
Users.Filter = Array("User")
For Each User In Users
Debug.Print User.Name
Next
End
End Sub
[/tt]
 
Hello guys,

Thank you very much for your ideas.

A big thank you to STRONGM for pointing me in the right direction and for the code supplied. It was just what I wanted.

cheers,

Neil
 
hello again,

After completing my program and deploying it I now find that it is far too slow. It took approx 7 mins to populate 1500 accounts. How does the user manager utility do it so fast?

Cheers,

Neil

 
Yes, well I'm assuming that you are using the first code example, which is dramatically slower than the second (but then I'm biaised, since I wrote the second example)
 
Yes, I did choose the first code - simply because it was easier to comprehend. I put your code into a module and had trouble trying to get it to work. I kept getting "no sub defined" and so on. I noticed the arrays are not in global format, am I to assume that this code should not be called from within a form?

Sorry if I am not making any sense. I am a novice...after all :O)

Could you explain to me how to launch your code - there is a purple star in it for you :O)

Cheers,

Neil
 
More-or-less everything you need is there. Did you follow the instructions? The first chunk of blue code needs to be copied and pasted into a module (select Project menu, and click 'Add Module'). Okey dokey, now, where it says [tt]Debug.Print UName[/tt] in the code (just before the last End Sub), this is where you can do what ever you like with the result; UName is a string containing the username. Change this to [tt]Form1.List1.AddItem Uname[/tt] if you'd like it in a listbox on a form (obviously you'll need a form with a listbox on it for this to work). The three lines at the bottom are just different ways of calling the routine, depending on what it is you want to do. You can use the simplest one ([tt]EnumerateUsers[/tt]). Put this in a Commandbutton's click event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top