ConnectionOptions co = new ConnectionOptions();
co.Username = "Administrator";
co.Password = "xxxxxxxxxxxxxxxxxxxx";
System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\218.241.42.116\\root\\cimv2", co);
co.Username = "Administrator";
co.Password = "xxxxxxxxxxxxxxxxxxxx";
System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\218.241.42.116\\root\\cimv2", co);
co.Username = "alex" ;
co.Password = "";
System.Management.ManagementScope ms = new ManagementScope(@"\\server",co) ;
try
{ ms.Connect() ; }
catch (Exception ex)
{ MessageBox.Show(ex.Message.ToString()) ; }当这个连接成功后,我需要用 "\\server\tp"中的内容
{
Process p;
p=new Process();
p.StartInfo.FileName="cmd.exe";
// 这里是关键点,不用Shell启动/重定向输入/重定向输出/不显示窗口
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true; p.Start();
p.StandardInput.WriteLine("net use \\\\Nt02 密码 /user:用户名");// 向cmd.exe输入command
p.StandardInput.WriteLine("exit");
p.WaitForExit();
string s = p.StandardOutput.ReadToEnd();// 得到cmd.exe的输出
p.Close();
return s;
}