谢谢你快速的回复。但我只坚持登录。我使用以下代码尝试登录:
bool success = LogonUser("username", "000.000.000.000", "#####",2 ,0 , out userToken);
但我收到失败的异常
我使用用户名和密码,通过 mstsc 登录。
我编写代码将文件从远程计算机复制到本地计算机,反之亦然。
但我不知道如何指定凭据来执行此操作。
我的代码如下:
string sourceFile = System.IO.Path.Combine(globalInfo.GlobalServerPath, sourcePath ));
string destFile = System.IO.Path.Combine(globalInfo.GlobalPath, destPath)
string[] files = System.IO.Directory.GetFiles(sourceFile);
foreach (string s in files)
{
string fileName = System.IO.Path.GetFileName(s);
fileName = System.IO.Path.Combine(destFile, fileName);
System.IO.File.Copy(s, fileName, true);
}
在这里我收到错误:无法登录..
for line
string[] 文件 = System.IO.Directory.GetFiles(sourceFile);
我正在连接到远程机器。
请帮忙
你需要模仿:
[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
out IntPtr phToken);
IntPtr userToken = IntPtr.Zero;
bool success = External.LogonUser(
"john.doe",
"domain.com",
"MyPassword",
(int) AdvApi32Utility.LogonType.LOGON32_LOGON_INTERACTIVE, //2
(int) AdvApi32Utility.LogonProvider.LOGON32_PROVIDER_DEFAULT, //0
out userToken);
if (!success)
{
throw new SecurityException("Logon user failed");
}
using (WindowsIdentity.Impersonate(userToken))
{
// do the stuff with john.doe's credentials
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)