在C#中的远程访问返回“无效的命名空间”

问题描述:

我试图访问服务器中的远程文件,但是当我执行下面的代码打开连接时,它返回“Invalid Namespace”。在C#中的远程访问返回“无效的命名空间”

我错过了什么?

public static void NetworkAuthentication() 
{ 
    ManagementScope scope = 
      new ManagementScope("\\\\192.168.1.12\\Files"); 
    scope.Options.Username = "ABCDE"; 
    scope.Options.Password = "12345"; 
    scope.Connect(); 
} 
+0

那么'\\ 192.168.1.12 \ Files'是一个UNC路径,而不是命名空间路径。 – DavidG

+0

'文件'不是WMI命名空间。 [这个问题](http://stackoverflow.com/questions/659013/accessing-a-shared-file-unc-from-a-remote-non-trusted-domain-with-credentials/684040#684040)可能有帮助吗? – stuartd

MSDN说,你应该使用根\ CIMV2的命名空间。所以试试

ManagementScope scope = new ManagementScope("\\\\192.168.1.12\\root\\cimv2"); 
+0

你说得对。我可能错过了解释我需要访问服务器内的文件。 –