日期:2014-05-20  浏览次数:20764 次

求助:访问共享文件
我用C#做一个本地服务器读取其他服务器上共享日志的服务,需要用户密码,用到哪些类?
网上很多那种映射的方式就不要帖出来了.
我要的说白了就是简单的访问别人的机器上的文件的方法,带权限,不要太复杂,
谢谢~

------解决方案--------------------
sdk中的例子。
先使用Wmi开通连接,再Copy文件
using System;
using System.Management;

// This example demonstrates how to connect to remote machine
// using supplied credentials.
class Sample_ConnectionOptions
{
public static int Main(string[] args) {
ConnectionOptions options = new ConnectionOptions();
options.Username = UserName; //could be in domain\user format
options.Password = SecurelyStoredPassword;
ManagementScope scope = new ManagementScope(
"\\\\servername\\root\\cimv2 ",
options);
try {
scope.Connect();
ManagementObject disk = new ManagementObject(
scope,
new ManagementPath( "Win32_logicaldisk= 'c: ' "),
null);
disk.Get();
}
catch (Exception e) {
Console.WriteLine( "Failed to connect: " + e.Message);
}
return 0;
}
}
------解决方案--------------------
mark
------解决方案--------------------
root呢?cimv2是服务器上共享日志的目录