【发布时间】:2011-12-30 06:46:53
【问题描述】:
我想从同一域中的远程计算机复制文件。所以我正在使用模仿来做到这一点。
我正在使用 advapi32.dll 的 DLLImport,它正确地模拟了用户。
现在执行下面的代码行时出现以下错误。
\\line
File.Copy(@"\\sins00048178\D$\BNCustody\Swift\Received_from_SWIFT\Error_files\E03248681_error.out", @"C:\E03248681_error.out", true);
\\Error
"Logon failure: user not allowed to log on to this computer."
按要求完成代码
[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
out IntPtr phToken
);
IntPtr userHandle = IntPtr.Zero;
bool loggedOn = LogonUser(userid, domain, pass, 9, 0, out userHandle);
if (loggedOn)
{
WindowsImpersonationContext context = WindowsIdentity.Impersonate(userHandle);
File.Copy(@"\\sins00048178\D$\BNCustody\Swift\Received_from_SWIFT\Error_files\E03248681_error.out", @"C:\E03248681_error.out", true);
context.Undo();
}
提前谢谢....
【问题讨论】:
-
请向我们展示您的 dll 导入和实际调用。
-
您是否使用 runas 命令测试过凭据?
-
@Denish 这部分属于哪种应用程序?一些 Windows 服务/IIS?
-
我想用窗口应用来做。
-
@Denish 你在 Windows 2000 下运行吗?
标签: c# impersonation