asp.net 利用dos命令创建POP3邮箱,如不加用户则拒绝访问,如加了CMD程序挂起。
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Diagnostics;
using System.Security;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strexceotion = "";
if (Request["falg"].ToString() == "add")
strexceotion = ExeCommand("winpop add " + Request["username"] + "@" + Request["area"] + " /createuser " + Request["pwd"]);
else if (Request["falg"].ToString() == "changepwd")
strexceotion = ExeCommand("winpop changepwd " + Request["username"] + "@" + Request["area"] + " " + Request["pwd"]);
else if (Request["falg"].ToString() == "delete")
strexceotion = ExeCommand("winpop delete " + Request["username"] + "@" + Request["area"] + " /deleteuser");
else if (Request["falg"].ToString() == "lock")
strexceotion = ExeCommand("winpop lock " + Request["username"] + "@" + Request["area"]);
else if (Request["falg"].ToString() == "unlock")
strexceotion = ExeCommand("winpop lock " + Request["unlock"] + "@" + Request["area"]);
//strexceotion = ExeCommand("ipconfig");
Response.Write(strexceotion);
}
}
private string ExeCommand(string commandText)
{
Response.Write(commandText);
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.StartInfo.WorkingDirectory = "C:\\WINDOWS\\system32\\inetsrv";
p.StartInfo.UserName = "Administrator";
SecureString securePwd = new SecureString();
securePwd.AppendChar('1');
securePwd.AppendChar('1');
securePwd.AppendChar('1');
securePwd.AppendChar('1');
securePwd.AppendChar('1');
securePwd.AppendChar('1');
p.StartInfo.Password = securePwd;
string strOutput = null;
try
{
p.Start();
p.StandardInput.WriteLine(commandText);
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch (Exception e)
{
strOutput = e.Message;
}
return strOutput;
}
}
以上是我