Hi guys,
I just started playing around with vb.net and wanted to know how to put all the windows users in a listbox. Thanks in advance
Display All Windows UsersHow to put all the windows users in a listbox
Page 1 of 1
8 Replies - 4273 Views - Last Post: 25 January 2011 - 11:43 PM
Replies To: Display All Windows Users
#2
Re: Display All Windows Users
Posted 01 May 2009 - 11:23 PM
you can use the following Class
example
System.Environment
example
MsgBox(System.Environment.UserName.ToString)
#3
Re: Display All Windows Users
Posted 02 May 2009 - 02:54 AM
noorahmad, on 1 May, 2009 - 10:23 PM, said:
you can use the following Class
example
System.Environment
example
MsgBox(System.Environment.UserName.ToString)
Thanks for a quick reply, but i was more interested in displaying all the local users eg: if there were 3 different user accounts (Tom, Dick & Harry) i want the code to display all 3 users on the listbox not just the person who is logged in. I hope that made it a little more clearer.
Cheers
#4
Re: Display All Windows Users
Posted 02 May 2009 - 03:46 AM
here is the code
It Will Help You
Dim _RegistryKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
Using SubKey As RegistryKey = _RegistryKey.OpenSubKey(_KeyName)
Dim _Users As String = DirectCast(SubKey.GetValue("ProfileImagePath"), String)
Dim _Username As String = System.IO.Path.GetFileNameWithoutExtension(_Users)
ListBox1.Items.Add(_Username)
End Using
Next
It Will Help You
This post has been edited by noorahmad: 02 May 2009 - 03:53 AM
#5
Re: Display All Windows Users
Posted 02 May 2009 - 04:48 PM
noorahmad, on 2 May, 2009 - 02:46 AM, said:
here is the code
It Will Help You
Dim _RegistryKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
Using SubKey As RegistryKey = _RegistryKey.OpenSubKey(_KeyName)
Dim _Users As String = DirectCast(SubKey.GetValue("ProfileImagePath"), String)
Dim _Username As String = System.IO.Path.GetFileNameWithoutExtension(_Users)
ListBox1.Items.Add(_Username)
End Using
Next
It Will Help You
#6
Re: Display All Windows Users
Posted 10 May 2009 - 09:42 AM
noorahmad, on 2 May, 2009 - 02:46 AM, said:
here is the code
It Will Help You
Dim _RegistryKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
Using SubKey As RegistryKey = _RegistryKey.OpenSubKey(_KeyName)
Dim _Users As String = DirectCast(SubKey.GetValue("ProfileImagePath"), String)
Dim _Username As String = System.IO.Path.GetFileNameWithoutExtension(_Users)
ListBox1.Items.Add(_Username)
End Using
Next
It Will Help You
Nice. But I seem to get the Network Service, Local Service and systemprofile as well.
How do i avoid getting those system logins?
#7
Re: Display All Windows Users
Posted 23 January 2011 - 02:09 AM
kevinn7, on 10 May 2009 - 09:42 AM, said:
noorahmad, on 2 May, 2009 - 02:46 AM, said:
here is the code
It Will Help You
Dim _RegistryKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
Using SubKey As RegistryKey = _RegistryKey.OpenSubKey(_KeyName)
Dim _Users As String = DirectCast(SubKey.GetValue("ProfileImagePath"), String)
Dim _Username As String = System.IO.Path.GetFileNameWithoutExtension(_Users)
ListBox1.Items.Add(_Username)
End Using
Next
It Will Help You
Nice. But I seem to get the Network Service, Local Service and systemprofile as well.
How do i avoid getting those system logins?
i have the same problem. how can we avoid those system logins? thanks!
#8
Re: Display All Windows Users
Posted 24 January 2011 - 08:52 AM
I'm sure there's something in place to do this more easily but I can say that you can limit the list to only the '\users\' path by including
Since Network Service, Local Service and systemprofile reside in system folders.
If you still have Non-Valid entries you could try to access "RunLogonScriptSync" and if it exists, it should be a user that can log in to the system.
It's a hack but it did remove the QBDataServiceUser from my list.
If _Users.ToLower.Contains("\users\") Then
ListBox1.Items.Add(_Username)
End If
Since Network Service, Local Service and systemprofile reside in system folders.
If you still have Non-Valid entries you could try to access "RunLogonScriptSync" and if it exists, it should be a user that can log in to the system.
It's a hack but it did remove the QBDataServiceUser from my list.
Dim _RegistryKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
Using SubKey As RegistryKey = _RegistryKey.OpenSubKey(_KeyName)
Try
Dim Valid As Integer = DirectCast(SubKey.GetValue("RunLogonScriptSync"), Integer)
Dim _Users As String = DirectCast(SubKey.GetValue("ProfileImagePath"), String)
Dim _Username As String = System.IO.Path.GetFileNameWithoutExtension(_Users)
If _Users.ToLower.Contains("\users\") Then
ListBox1.Items.Add(_Username)
End If
Catch ex As Exception
'bury the exception.
End Try
End Using
Next
This post has been edited by CharlieMay: 24 January 2011 - 09:11 AM
#9 Guest_shie*
Re: Display All Windows Users
Posted 25 January 2011 - 11:43 PM
CharlieMay, on 24 January 2011 - 08:52 AM, said:
I'm sure there's something in place to do this more easily but I can say that you can limit the list to only the '\users\' path by including
Since Network Service, Local Service and systemprofile reside in system folders.
If you still have Non-Valid entries you could try to access "RunLogonScriptSync" and if it exists, it should be a user that can log in to the system.
It's a hack but it did remove the QBDataServiceUser from my list.
If _Users.ToLower.Contains("\users\") Then
ListBox1.Items.Add(_Username)
End If
Since Network Service, Local Service and systemprofile reside in system folders.
If you still have Non-Valid entries you could try to access "RunLogonScriptSync" and if it exists, it should be a user that can log in to the system.
It's a hack but it did remove the QBDataServiceUser from my list.
Dim _RegistryKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList")
For Each _KeyName As String In _RegistryKey.GetSubKeyNames()
Using SubKey As RegistryKey = _RegistryKey.OpenSubKey(_KeyName)
Try
Dim Valid As Integer = DirectCast(SubKey.GetValue("RunLogonScriptSync"), Integer)
Dim _Users As String = DirectCast(SubKey.GetValue("ProfileImagePath"), String)
Dim _Username As String = System.IO.Path.GetFileNameWithoutExtension(_Users)
If _Users.ToLower.Contains("\users\") Then
ListBox1.Items.Add(_Username)
End If
Catch ex As Exception
'bury the exception.
End Try
End Using
Next
it only shows the current user and not all the user accounts.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|