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.

Adding a new user to admin group

Hi,

Is there any way to add a new user to local admin group
via C#?

Please advice, thanks!
-CL
Nov 15 '05 #1
2 5569
Use the DirectoryServices library - something like:

DirectoryEntry objLocalAdmins = new
DirectoryEntry("WinNT://MACHINE/Administrators,group");
object oUserPath = "WinNT://MACHINE/Username";
objLocalAdmins.Invoke("Add", new object[] {oUserPath});

Check out the docs for the DirectoryEntry object, and IADSGroup etc in MSDN.
Can also be used to add domain users, use domain in stead of machinename for
the userpath.
Arild

"Ching-Lung" <cl******@hotmail.com> wrote in message
news:04****************************@phx.gbl...
Hi,

Is there any way to add a new user to local admin group
via C#?

Please advice, thanks!
-CL

Nov 15 '05 #2
Arild,

Thank you so much!
-CL

-----Original Message-----
Use the DirectoryServices library - something like:

DirectoryEntry objLocalAdmins = new
DirectoryEntry("WinNT://MACHINE/Administrators,group");
object oUserPath = "WinNT://MACHINE/Username";
objLocalAdmins.Invoke("Add", new object[] {oUserPath});

Check out the docs for the DirectoryEntry object, and IADSGroup etc in MSDN.Can also be used to add domain users, use domain in stead of machinename forthe userpath.
Arild

"Ching-Lung" <cl******@hotmail.com> wrote in message
news:04****************************@phx.gbl...
Hi,

Is there any way to add a new user to local admin group
via C#?

Please advice, thanks!
-CL

.

Nov 15 '05 #3

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

Similar topics

12
by: Google Mike | last post by:
You know, while working on my moonlight corporation's LAMP project at home this weekend, I couldn't help but wonder if people writing similar projects are solving similar problems with having to...
3
by: MLH | last post by:
I was running the following code while logged in as a user belonging only to the Users group. Set usrNew = .CreateUser(Me!UserID) 'The user ID is in a control on the form usrNew.PID =...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
3
by: Andy_Alpha | last post by:
Here's code,that i think,add user in group .... DirectoryEntry grp=new DirectoryEntry(GroupName); MessageBox.Show(GroupName,"group to add"); try { if (grp!=null) { grp.Invoke("Add",new...
1
by: Ching-Lung | last post by:
Hi, Is there any way to add new user to local admin group in C# ASP.NET? Thanks, -CL
5
by: Rocky | last post by:
Hi, I have a webform, with 2 textboxs and a submit button. In the text box1, i enter a username and in textbox2 I enter the computer name. Both the username and computer name is in active...
2
by: Norman Chong | last post by:
Hi ng, I want to know if a user has admin rightsSo I wrote the following code to check, if the user is in the admin-group: Dim bIsInRole as Boolean Dim myUser As...
31
by: zdenko | last post by:
I have a multi user database and users were created by user level security wizzard - as I mentioned in message before. Everything works fine for those users, but now I have another problem. I have...
4
by: Don Calloway | last post by:
I'm attempting to implement User-level security on an Access 2003 database in Access 2000 format and have hit a brick wall. I created a Workgroup Information File with myself as admin and added...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.