Adding a new user to admin group

  • Thread starter Thread starter Ching-Lung
  • Start date Start date
C

Ching-Lung

Hi,

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

Please advice, thanks!
-CL
 
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
 
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


.
 
Back
Top