Hi I am very new to .NET and I am programmatically trying to create a windows
users (not using AD) and am having a little trouble. The OS is 2003 Server
and I am trying to use System.Diagnostics.Process with "net.exe". The
argument does not seem to take, here is the code (this is my first crack at
web services or any real .net project so not sure if this the best way to do
this either - also please do not bash my code again it is my first try):
[WebMethod(Description = "Create Windows User and Custom Group.")]
public string CreateLocalUser(string username, string password)
{
Process MyProc = new Process();
MyProc.StartInfo.FileName = "net.exe";
MyProc.StartInfo.UseShellExecute = false;
MyProc.StartInfo.RedirectStandardError = true;
MyProc.StartInfo.RedirectStandardInput = true;
MyProc.StartInfo.RedirectStandardOutput = true;
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
try
{
//this is the part that does not work
MyProc.StartInfo.Arguments = @"net.exe user " + username + @" " + password
+ @" /ADD /ACTIVE:YES " +@"/EXPIRES:NEVER /FULLNAME:" + username + @"
/PASSWORDCHG:NO /PASSWORDREQ:YES";
//
MyProc.Start();
MyProc.WaitForExit();
MyProc.Close();
}
catch(Exception e)
{
Console.WriteLine(e.GetType());
Console.WriteLine(e.Message);
}
return "completed";
}