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);

解决方案 »

  1.   

    我在使用楼上的 ManagementScope 后出现下面的提示:无法为本地连接使用用户凭证楼上的好相差一句 "ms.Connect()"我联接的服务器为 server ,所以我用下面的代码ConnectionOptions co = new ConnectionOptions();
      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"中的内容
      

  2.   

    public  string  ConnectLan()
    {
    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;

    }