473,396 Members | 1,982 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,396 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 4441
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.