473,320 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Local Users on Windows XP

Hi,

My OS is Windows XP without any network, nor Active Directory. There
are only a few local users. I am trying to list all my local users in
a list box. Here is my code:

string strMachine;

strMachine = String.Format("WinNT://{0}", Environment.MachineName);
DirectoryEntry allUsers = new DirectoryEntry(strMachine);
foreach (DirectoryEntry user in allUsers.Children)
{
lstUsers.Items.Add(user.Name);
}

Though it doesn't generate any errors, there is a problem. I get a
long list of about 100 items which includes internal users like
ASPNet, HelpAssistant and even explorer. I have tried with appending
<<<",group">>> at the end of machine name but in that case it gives
error in <<<foreach...>>> line. I tried Directory Searcher but that
too generates Unknown Runtime Error when doing searcher.FindOne() or
searcher.FindAll(). I have tried so many examples from the web/groups
- none works.

Please help me with this.

Arshad
Jul 21 '05 #1
2 4438
Elp
On 16 Feb 2005 07:13:17 -0800, Arshad Parvez wrote:
My OS is Windows XP without any network, nor Active Directory. There
are only a few local users. I am trying to list all my local users in
a list box. Here is my code:

string strMachine;

strMachine = String.Format("WinNT://{0}", Environment.MachineName);
DirectoryEntry allUsers = new DirectoryEntry(strMachine);
foreach (DirectoryEntry user in allUsers.Children)
{
lstUsers.Items.Add(user.Name);
}

Though it doesn't generate any errors, there is a problem. I get a
long list of about 100 items


The SchemaClassName for Windows users is "user". In your foreach, check if
the SchemaClass name is "user" before adding it to your list box. I've
never tried to list all users on a machine before but here is how i check
is a user exists (so i guess that this is the same if you want to list all
users):

DirectoryEntry localDirectory = null;
DirectoryEntry user = null;

//Open a connection to the local Active Directory
localDirectory = new DirectoryEntry("WinNT://" + Environment.MachineName +
",computer");

//Look for the user
try
{
user = localDirectory.Children.Find(username, "user");
}
catch(Exception e)
{
// Problem
}
Jul 21 '05 #2
Thanks a lot!

I have mangaed to get users with this code:

strMachine = String.Format("WinNT://{0}", Environment.MachineName);
DirectoryEntry Machine = new DirectoryEntry(strMachine);
foreach(DirectoryEntry entry in Machine.Children)
{
switch (entry.SchemaClassName)
{
case "User" :
lstTable.Items.Add(entry.Name);
break;
}
}

This solves the problem only partially, as I am still getting few
additional users which are ACTUser, ASPNET, HelpAssistant,
SQLDebugger, SUPPORT_388945a0 and VUSR_ARSHAD.

How can I limit this list to only include those user which are
explicitly created by the Administrator (myself)?

How can I list users of a certain group - I can fetch group names by
searching "Group" in SchemaClassName.

Arshad

-------------------------------------------
Elp <ro********@REMOVEME.hotmail.com> wrote in message news:<20*****************************@40tude.net>. ..
On 16 Feb 2005 07:13:17 -0800, Arshad Parvez wrote:

The SchemaClassName for Windows users is "user". In your foreach, check if
the SchemaClass name is "user" before adding it to your list box. I've
never tried to list all users on a machine before but here is how i check
is a user exists (so i guess that this is the same if you want to list all
users):

DirectoryEntry localDirectory = null;
DirectoryEntry user = null;

//Open a connection to the local Active Directory
localDirectory = new DirectoryEntry("WinNT://" + Environment.MachineName +
",computer");

//Look for the user
try
{
user = localDirectory.Children.Find(username, "user");
}
catch(Exception e)
{
// Problem
}

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rob | last post by:
Hi, I am working on a project that requires a Windows Service which performs the following file transfer functions. 1. It monitors a specific local directory on a Windows 2003 Server. 2. When...
2
by: Arshad Parvez | last post by:
Hi, My OS is Windows XP without any network, nor Active Directory. There are only a few local users. I am trying to list all my local users in a list box. Here is my code: string strMachine;...
0
by: el dio | last post by:
Hi, i'm trying to add domain user to a local Windows group. Imagine I have domain 'myDomain', domain user 'myDomain\domainUser', my computer is 'myComputer', local group is 'Guests'. I used...
4
by: rdemyan via AccessMonster.com | last post by:
My application is calculation intensive and the servers are agonizingly slow. Administrators of my application only update the backends once a month (twice a month max). So, my launching program...
3
by: dion.naidoo | last post by:
Hi ,is there any way one can restrict users to copy files with extensions that we dont want on our networks or local pcs. Users are local administrators of their pcs. PS. If this is not possible...
4
by: shashank kadge | last post by:
hi all, i am trying to get local admin users and groups on a windows server. here is the C# code that i am using...
1
by: ringoschplingo | last post by:
Hi, (sorry this is a long one) I have MSSQL 2000 (version 8.00.2187) installed on Windows Server 2K3, nothing 'special' has been done to either of these servers as far as configuration goes. ...
1
by: Michael Howes | last post by:
I would think this would be very, very easy but in the 50 searches I've done I haven't found anything. If our application requires login and that user/password be a local windows account or more...
8
by: martinsmith160 | last post by:
Hi everyone I am trying to create a simple wpf program that allows a user to select an image from a combo box and then where they click on th screen draw that image at the mouse co-ordinates. The...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.