gpt4 book ai didi

c# - 如何在 dns 或 netbios 不可用时模拟用户通过网络复制文件

转载 作者:可可西里 更新时间:2023-11-01 08:45:48 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Accessing Password Protected Network Drives in Windows in C#?

我在 DomainA 上有 ComputerA 作为 userA 运行,需要将一个非常大的文件复制到 WorkgroupB 上的 ComputerB,该文件的 IP 为 192.168.10.2 到只有 userB 具有写入权限的 Windows 共享。

没有 netbios 或 dns 解析,所以计算机必须通过 IP 引用

我第一次尝试

AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);
WindowsIdentity UserB = new WindowsIdentity("192.168.10.2\\UserB", "PasswordB"); //Execption
WindowsImpersonationContext contex = UserB.Impersonate()
File.Copy(@"d:\bigfile", @"\\192.168.10.2\bifgile");
contex.Undo();

但我收到 System.Security.SecurityException“提供的名称不是格式正确的帐户名称。”

所以我试过了

AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);
WindowsIdentity webinfinty = new WindowsIdentity("ComputerB\\UserB", "PasswordB"); //Execption

但我收到“登录失败:未知用户名或错误密码”。而是错误。

然后我试了一下

IntPtr token;
bool succeded = LogonUser("UserB", "192.168.10.2", "PasswordB", LogonTypes.Network, LogonProviders.Default, out token);
if (!succeded)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
WindowsImpersonationContext contex = WindowsIdentity.Impersonate(token);
(...)
[DllImport("advapi32.dll", SetLastError = true)]
static extern bool LogonUser(
string principal,
string authority,
string password,
LogonTypes logonType,
LogonProviders logonProvider,
out IntPtr token);

但是 LogonUser 返回 false 并出现 win32 错误“登录失败:未知的用户名或密码错误”

我知道我的用户名和密码没问题,我已经以该用户身份登录到计算机 B。

任何建议

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com