1
bool Flag = true;
2
Process proc = new Process();
3
try
4
{
5
proc.StartInfo.FileName = "cmd.exe";
6
proc.StartInfo.UseShellExecute = false;
7
proc.StartInfo.RedirectStandardInput = true;
8
proc.StartInfo.RedirectStandardOutput = true;
9
proc.StartInfo.RedirectStandardError = true;
10
proc.StartInfo.CreateNoWindow = true;
11
proc.Start();
12
string dosLine = @"net use \\" + remoteHost + " " + passWord + " " + " /user:" + userName + ">NUL";
13
proc.StandardInput.WriteLine(dosLine);
14
proc.StandardInput.WriteLine("exit");
15
while (proc.HasExited == false)
16
{
17
proc.WaitForExit(1000);
18
}
19
string errormsg = proc.StandardError.ReadToEnd();
20
if (errormsg != "")
21
{
22
log.Debug(errormsg);
23
Flag = false;
24
}
25
proc.StandardError.Close() ;
26
}
27
catch (Exception ex)
28
{
29
log.Debug(ex.Message, ex);
30
Flag = false;
31
}
32
finally
33
{
34
try
35
{
36
proc.Close();
37
proc.Dispose();
38
}
39
catch
40
{
41
}
42
}
43
return Flag;
bool Flag = true;2
Process proc = new Process();3
try4
{5
proc.StartInfo.FileName = "cmd.exe";6
proc.StartInfo.UseShellExecute = false;7
proc.StartInfo.RedirectStandardInput = true;8
proc.StartInfo.RedirectStandardOutput = true;9
proc.StartInfo.RedirectStandardError = true;10
proc.StartInfo.CreateNoWindow = true;11
proc.Start();12
string dosLine = @"net use \\" + remoteHost + " " + passWord + " " + " /user:" + userName + ">NUL";13
proc.StandardInput.WriteLine(dosLine);14
proc.StandardInput.WriteLine("exit");15
while (proc.HasExited == false)16
{17
proc.WaitForExit(1000);18
}19
string errormsg = proc.StandardError.ReadToEnd();20
if (errormsg != "")21
{22
log.Debug(errormsg);23
Flag = false;24
}25
proc.StandardError.Close() ;26
}27
catch (Exception ex)28
{29
log.Debug(ex.Message, ex);30
Flag = false;31
}32
finally33
{34
try35
{36
proc.Close();37
proc.Dispose();38
}39
catch40
{41
}42
}43
return Flag;


浙公网安备 33010602011771号