如何在 asp.net 中将 txt 文件复制到远程计算机
本文关键字:复制 计算机 文件 txt asp net 中将 | 更新日期: 2023-09-27 18:33:43
下面是我的代码,它是将文件复制到任何远程计算机的标准代码。
但它不断弹出此错误:
找不到网络路径。
请帮帮我!
IntPtr admin_token = default(IntPtr);
WindowsIdentity wid_admin = null;
WindowsImpersonationContext wic = null;
IntPtr duplicate_token = default(IntPtr);
if (LogonUser("Administrator", "WIN-ABC", "aaaaaaa", 9, 0, ref admin_token) != 0)
{
if (DuplicateToken(admin_token, 2, ref duplicate_token) != 0)
{
wid_admin = new WindowsIdentity(duplicate_token);
wic = wid_admin.Impersonate();
System.IO.File.Copy("E:/abc.txt", "''''WIN-ABC''Data1''abc.txt", true);
}
试试这段代码...这应该允许您访问远程路径
IntPtr admin_token = default(IntPtr);
IntPtr duplicate_token = default(IntPtr);
WindowsIdentity wid_admin = null;
WindowsImpersonationContext wic = null;
if (LogonUser("Administrator", "WIN-ABC", "ABCDEF", 9, 0, ref admin_token) != 0)
{
if (DuplicateToken(admin_token, 2, ref duplicate_token) != 0)
{
wid_admin = new WindowsIdentity(duplicate_token);
wic = wid_admin.Impersonate();
System.IO.File.Copy("E:/Temp/abc.txt", "''''WIN-ABC''TestFolder''abc.txt", true)
}
}
确保您在下面添加导入声明
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int DuplicateToken(IntPtr hToken,
int impersonationLevel, ref IntPtr hNewToken);