Adding 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 new user to local admin group in
C# ASP.NET?

Thanks,
-CL
 
Here is one method that you could use to accomplish this:

You can invoke a DOS batch script which will add the user to the group. The
DOS command would be as follows:
net localgroup administrators DOMAIN\username /add

Then, generate a text file containing the above commands/usernames and save
the file as adduser.bat.

Then, add the following code to whatever event you wanted to use to add the
user:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="c:\\foldername\\adduser.bat";
proc.Start();

If you also need to create the user, you can add that command to your batch
file using the proper syntax for the addusers utility.

Chris

--------------------
 
Back
Top