根据进程令牌来完成计算机之间文件拷贝
来源:互联网 发布:手机美发软件 编辑:程序博客网 时间:2024/04/30 09:46
using System.Runtime.InteropServices; //添加引用
//引用系统win32 Api
//http://msdn.microsoft.com/zh-cn/library/aa378184(v=VS.85) public class IdentityScope : IDisposable { private bool disposed; [DllImport("Advapi32.dll")] private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, LogonType dwLogonType, LogonProvider dwLogonProvider, out IntPtr phToken); [DllImport("Advapi32.DLL")] private static extern bool ImpersonateLoggedOnUser(IntPtr hToken); [DllImport("Advapi32.DLL")] private static extern bool RevertToSelf(); [DllImport("Kernel32.dll")] private static extern int GetLastError(); public IdentityScope(string domain, string userName, string password) : this(domain, userName, password, LogonType.Interactive, LogonProvider.Default) { } public IdentityScope(string domain, string userName, string password, LogonType logonType, LogonProvider logonProvider) { if (string.IsNullOrEmpty(userName)) throw new ArgumentNullException("userName"); if (string.IsNullOrEmpty(domain)) domain = "."; IntPtr token; int errorCode = 0; if (LogonUser(userName, domain, password, logonType, logonProvider, out token)) { if (!ImpersonateLoggedOnUser(token)) errorCode = GetLastError(); } else errorCode = GetLastError(); if (errorCode != 0) throw new System.ComponentModel.Win32Exception(errorCode); } ~IdentityScope() { Dispose(false); } protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { } RevertToSelf(); disposed = true; } } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } } public enum LogonType : uint { Interactive = 2, Network = 3, Batch = 4, Service = 5, Unlock = 7, NetworkClearText = 8, NewCredentials = 9 } public enum LogonProvider : uint { Default = 0, WinNT35 = 1, WinNT40 = 2, WinNT50 = 3, } public enum ProcessCode : uint { Result = 1, Success = 2, Failure = 4 }
public class Program { static void Main() { try { string IpAddr = "192.168.1.23"; string souceFileName = "D:\\abc.txt"; string targetFileName = "\\192.168.1.23\\D$\\abc.txt"; string UserName = "Administrator"; string Password = "123456"; //信令拷beike using (new IdentityScope(IpAddr , UserName , Password , LogonType.NewCredentials , LogonProvider.WinNT50)) { System.IO.File.Copy(souceFileName, targetFileName, true); } } catch (Exception e) { } } }
更多信息参见:http://msdn.microsoft.com/zh-cn/library/aa378184(v=VS.85)
- 根据进程令牌来完成计算机之间文件拷贝
- Linux rcp --计算机之间拷贝文件
- 完成内存之间的拷贝
- 计算机间拷贝文件
- 文件之间的拷贝
- 服务器之间拷贝文件
- 使用IO完成文件拷贝
- 多进程拷贝文件
- 根据名称来kill进程
- 使用JAXB来完成Javabean与XML文件(字符串)之间的相互转换
- linux 服务器之间拷贝文件
- 不同系统之间拷贝文件
- linux 服务器之间拷贝文件
- linux 服务器之间拷贝文件
- SCP--服务器之间拷贝文件
- linux 服务器之间文件拷贝
- 通过父子进程完成文件io对文件的拷贝,父进程从文件开始到文件 的一半开始拷贝,子进程从文件的一半到文件末尾。
- linux中根据进程的PID值来查找执行文件的及其路径
- amplxe-cl -help command
- JSP 中的消息框:警告框、确认框、提示框
- How to properly increase ulimit -n on Lion?
- xhprof管理
- MSSOAP30.DLL VC 报错问题 MSSOAP30.DLL 3.0下载 MSSOAP30.DLL 3.0.1325.0 vc xp
- 根据进程令牌来完成计算机之间文件拷贝
- Vtune how to use?
- 无
- 史前被踩之最→貼子! ~...~
- Attributes Layout
- 关于学习Linux的经典书籍 (深入理解Linux内核、Linux设备驱动程序等)
- amplxe-cl -finalize:用的不多.
- 面向对象的设计原则-类设计原则
- MyGUI 功能与架构