try
{
Process p = new Process();
p.StartInfo.FileName = " cmd.exe " ;
p.StartInfo.UseShellExecute = false ;
p.StartInfo.RedirectStandardInput = true ;
p.StartInfo.RedirectStandardOutput = true ;
p.StartInfo.RedirectStandardError = true ;
p.StartInfo.CreateNoWindow = true ;
p.Start();
string username = " test " ;
string pwd = "test" ;
string Cmdstring = string .Format( " Net user {0} {1} /delete " , username, pwd);
p.StandardInput.WriteLine(Cmdstring);
Cmdstring = string .Format( " Net user {0} {1} /add " , username, pwd);
p.StandardInput.WriteLine(Cmdstring);
Cmdstring = string .Format( " Net localgroup users {0} /add " , username);
p.StandardInput.WriteLine(Cmdstring);
Cmdstring = string .Format( " Net localgroup \"Remote Desktop Users\" {0} /add " , username);
p.StandardInput.WriteLine(Cmdstring);
p.StandardInput.WriteLine( " exit " );
Response.Write( " Create Success! " );
}
catch
{
Response.Write( " Create Failure! " );
}
{
Process p = new Process();
p.StartInfo.FileName = " cmd.exe " ;
p.StartInfo.UseShellExecute = false ;
p.StartInfo.RedirectStandardInput = true ;
p.StartInfo.RedirectStandardOutput = true ;
p.StartInfo.RedirectStandardError = true ;
p.StartInfo.CreateNoWindow = true ;
p.Start();
string username = " test " ;
string pwd = "test" ;
string Cmdstring = string .Format( " Net user {0} {1} /delete " , username, pwd);
p.StandardInput.WriteLine(Cmdstring);
Cmdstring = string .Format( " Net user {0} {1} /add " , username, pwd);
p.StandardInput.WriteLine(Cmdstring);
Cmdstring = string .Format( " Net localgroup users {0} /add " , username);
p.StandardInput.WriteLine(Cmdstring);
Cmdstring = string .Format( " Net localgroup \"Remote Desktop Users\" {0} /add " , username);
p.StandardInput.WriteLine(Cmdstring);
p.StandardInput.WriteLine( " exit " );
Response.Write( " Create Success! " );
}
catch
{
Response.Write( " Create Failure! " );
}
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2011/05/26/2058280.html,如需转载请自行联系原作者