访问远程机器进程

时间:2013-06-12 08:43:57

标签: c# asp.net

我正在尝试访问远程计算机但它出错了。我尝试使用远程机器的ip来ping以检查PC是否已连接但工作正常。但是当我在cmd提示符中尝试使用任务列表来访问远程机器时,它会提供“RPC不可用”。并且所有PC都通过LAN连接

代码:

connOptions = new ConnectionOptions();
//   connOptions.Authority = "ntlmdomain:domain";
string MyComputerName = sName.ToString();
string machineName = MyComputerName;
connOptions.Username = machineName + "\\" + MyComputerName;
//  connOptions.Username = MyComputerName;
                    connOptions.Password = "";
                    if (MyComputerName.ToUpper() == Environment.MachineName.ToUpper())
                    {
                        // Create the management scope with given credentials
                        myScope = new ManagementScope(@"\ROOT\CIMV2", connOptions);

                    }

                   else { 
                     myScope = new ManagementScope(@"\\" + MyComputerName + @"\ROOT\CIMV2",connOptions);
                    myScope.Connect();
                    }


                }
                catch (SocketException ex3)
                {
                    Console.WriteLine("FormatException caught!!!");
                }
                catch (Exception ex4)
                {
                    Console.WriteLine("Exception caught!!!");

                }

myScope.Connect();给出“UNAuthorizedAccessException”

我是否需要在web.config文件中进行任何设置,或者我是否必须进行任何类型的设置才能使此代码生效?

0 个答案:

没有答案