如何连接到工作组中的计算机



我正试图通过工作组连接到计算机。我的代码如下:

ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
options.Username = "testusername";
options.Password = "testpwd";
ManagementScope scope = new ManagementScope(@"\19x.16x.x.xxC$TestFolder", options);
scope.Connect();
if (scope.IsConnected == true)
{ 
    MessageBox.Show("Connection Succeeded", "Alert"); 
} 
else 
{
    MessageBox.Show("Connection Failed", "Alert");
}

当我运行这个时,我得到了异常:"无效参数">

如何解决这个问题?

编辑:

错误在下面的这一行:

ManagementScope scope = new ManagementScope(@"\19x.16x.x.xxC$TestFolder", options);

我们如何指定驱动器?我认为$导致了问题

更新

根据用户的评论,OP试图做一些与问题所暗示的完全不同的事情。要以编程方式将文件从一个位置复制到另一个位置,可以使用file.copy:

File.Copy(sourcePath, destinationPath)

其中destinationPath是有效的网络路径。在网络上,我建议使用machineName而不是IP地址。尤其是在IP地址更改的可能性很高的VPN上。

\machineNamepathfilename.csv

最新更新