Adding a new user to admin group

C

Ching-Lung

Hi,

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

Please advice, thanks!
-CL
 
A

Arild Bakken

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
 
C

Ching-Lung

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 for
the userpath.


Arild

Ching-Lung said:
Hi,

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

Please advice, thanks!
-CL


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top