Add users to the IIS_WPG group using C#.Net

The following function adds a user to the IIS_WPG group using the ntrights.exe utility by Microsoft. Note that in order for this function to work you have to have the ntrights utility downloaded. To download it check Microsoft’s wensite:

http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en

public static void AddUserToWPG(string currentFolderPath, string user)
{
  try
  {
    Process process = new Process();
    //run the script
    process.StartInfo.FileName = System.Environment.SystemDirectory + @"\net.exe";
    process.StartInfo.Arguments = string.Format(" localgroup \"{0}\" {1} /add",     wpgGroup, user);
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.UseShellExecute = true;
    process.Start();
    process.WaitForExit();

    process.StartInfo.FileName = Path.Combine(currentFolderPath, "ntrights.exe");
    process.StartInfo.Arguments = string.Format(" +r \"seTcbPrivilege\" -u \"{0}\"",     user);
    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.UseShellExecute = true;
    process.Start();
    process.WaitForExit();
  }
  catch
  {
     throw new Exception("your message");

  }

}

Advertisements

One Response to Add users to the IIS_WPG group using C#.Net

  1. peterriad says:

    Actually, adding a user to IIS_WPG is done using net.exe not ntright.exe where net.exe comes with the Windows.

    ntrights is used to give a user permission on a folder.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: