Display All Windows Users

How to put all the windows users in a listbox

Page 1 of 1

8 Replies - 6120 Views - Last Post: 25 January 2011 - 11:43 PM Rate Topic: -----

#1 ArdaKara  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-May 09

Display All Windows Users

Posted 01 May 2009 - 11:12 PM

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
Is This A Good Question/Topic? 0
  • +

Replies To: Display All Windows Users

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Display All Windows Users

Posted 01 May 2009 - 11:23 PM

you can use the following Class
System.Environment


example
MsgBox(System.Environment.UserName.ToString)


Was This Post Helpful? 0
  • +
  • -

#3 ArdaKara  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-May 09

Re: Display All Windows Users

Posted 02 May 2009 - 02:54 AM

View Postnoorahmad, on 1 May, 2009 - 10:23 PM, said:

you can use the following Class
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
Was This Post Helpful? 0
  • +
  • -

#4 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Display All Windows Users

Posted 02 May 2009 - 03:46 AM

here is the code
 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

Was This Post Helpful? 2

#5 ArdaKara  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-May 09

Re: Display All Windows Users

Posted 02 May 2009 - 04:48 PM

View Postnoorahmad, on 2 May, 2009 - 02:46 AM, said:

here is the code
 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

:D noorahmad you are a legend!!!
Was This Post Helpful? 0
  • +
  • -

#6 kevinn7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-May 09

Re: Display All Windows Users

Posted 10 May 2009 - 09:42 AM

View Postnoorahmad, on 2 May, 2009 - 02:46 AM, said:

here is the code
 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?
Was This Post Helpful? 0
  • +
  • -

#7 shie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-January 11

Re: Display All Windows Users

Posted 23 January 2011 - 02:09 AM

View Postkevinn7, on 10 May 2009 - 09:42 AM, said:

View Postnoorahmad, on 2 May, 2009 - 02:46 AM, said:

here is the code
 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! :)
Was This Post Helpful? 0
  • +
  • -

#8 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,926
  • Joined: 25-September 09

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
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

Was This Post Helpful? 2
  • +
  • -

#9 Guest_shie*


Reputation:

Re: Display All Windows Users

Posted 25 January 2011 - 11:43 PM

View PostCharlieMay, 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
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. :(
Was This Post Helpful? 0

Page 1 of 1