c#创建操作系统用户并加入组

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!");
            }
posted @ 2011-05-26 15:46  94cool  阅读(262)  评论(0)    收藏  举报