bool flag = false;
Process pro = new Process();
try
{
pro.StartInfo.FileName = "cmd.exe";
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.RedirectStandardInput = true;
pro.StartInfo.RedirectStandardError = true;
pro.StartInfo.RedirectStandardOutput = true;
pro.StartInfo.CreateNoWindow = true;
pro.Start();
string docline = @"net use " + "" + path + " " + "/user:" + username + " " + pwd;
// MessageBox.Show(docline);
pro.StandardInput.WriteLine(docline);
pro.StandardInput.WriteLine("exit");
while (!pro.HasExited)
{
pro.WaitForExit(1000);
}
string errormsg = pro.StandardError.ReadToEnd();
pro.StandardError.Close();
if (string.IsNullOrEmpty(errormsg))
{
flag = true;
}
else
{
throw new Exception(errormsg);

}
;
}
catch (System.Exception ex)
{
throw ex;

}
finally
{
pro.Close();
pro.Dispose();
}

return flag;
}
}

posted on 2019-12-29 14:48  Lionever  阅读(1959)  评论(0编辑  收藏  举报