English 中文(简体)
利用WMI和C#连接远程计算机
原标题:Connect to remote computer using WMI and C#
  • 时间:2011-03-24 23:39:08
  •  标签:
  • c#
  • wmi

Hy... I am trying to connect to a remote computer using WMI and C#. I get an error: The RPC server is unavailable. (Exception result HRESULT: 0x800706BA). I don t know if that is code related so this is what I m using:

serverN = InputText.Text;//serverN=IPAddress
userN = userName.Text;
passN = passName.Text;
if (String.IsNullOrEmpty(serverN))
                serverN = ".";
ManagementClass manC = new ManagementClass("Win32_LogicalDisk");
string strScope = string.Format(@"\{0}
ootcimv2", serverN);
ConnectionOptions conOpt = new ConnectionOptions();
conOpt.Username = userN;
conOpt.Password = passN;
manC.Scope = new ManagementScope(strScope, conOpt);

When I try to get instances from manC I catch the exception with the RPC being unavailable. Locally it works so I m guessing that I have to make some settings on the remote machine (OS: Windows XP sp2). I have checked so that it allows remote connections and I have inserted command netsh firewall set service RemoteAdmin into command prompt. Do I need to set a domain name or a networkid? Or it is something else I m missing?

问题回答

I know it might be late for you, but for others who might stumble on this post: If you re sure it is not a user rights issue (you know the folder has the permissions) Check what you re giving as AuthenticationLevel to the ConnectionOptions object. I iterated through every one of them and for me the only that works is the PacketPrivacy option.

ConnectionOptions conOp = new ConnectionOptions();
conOp.Authentication = System.Management.AuthenticationLevel.PacketPrivacy;

也许需要更多关于你成立的信息。 计算机是否在同一领域?

You could start by testing if the WMI is working before trying it in C#. Try the following from a command prompt to see if that works.

wmic /node: path Win32_logicaldisk

wmic also has a /user option you can use to test with your username and password.

您可尝试在ConnectionOptions上修改Ausentication and Impersonation property。 这往往从环境变化到环境,并可能导致联系失败。

Not to seem rude but: are you sure the value in InputText.Text is correct? One easy way to get "The RPC server is unavailable" is to supply a bad name for the server. It might be worth examining the value of scope in the debugger after the string.Format call.

BTW 我假定,这只是你创造和启动一个称为范围,但通过一个称为“范围”的变数,供管理范围建筑商使用?

象许可这样的声音是IMHO。 根据我的经验,你需要建立一些明确的安全许可,以发出遥远的海事委员会电话。

http://technet.microsoft.com/en-us/library/cc78753328WS.10%29.aspx”rel=“nofollow” 您是否制定了适当的许可?

The code works locally because you re already logged on. Remote WMI connections always require additional security rights. Your first code update should include impersonationLevel: http://msdn.microsoft.com/en-us/library/windows/desktop/aa389288%28v=vs.85%29.aspx

如果人才充裕,那么下一步应该是明确全权证书。 这将发挥作用。 还有一种选择,但我不建议“授权”,允许这种账户成为该领域的任何账户。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签