От: | Lloyd | ||
Дата: | 09.09.10 16:35 | ||
Оценка: |
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_INTERACTIVE = 2;
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool LogonUser(string username, string domain, string password, int logonType, int logonProvider, ref IntPtr token);
public static WindowsImpersonationContext Logon(string domainName, string userName, string password) {
IntPtr tokenHandle = IntPtr.Zero;
LogonUser(userName, domainName, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref tokenHandle);
var windowsIdentity = new WindowsIdentity(tokenHandle);
return windowsIdentity.Impersonate();
}
static void Main() {
using (Logon(_DOMAIN_NAME, _USER_NAME, _PASSWORD)) {
Test();
}
}
private static void Test() {
Console.WriteLine(typeof(DataSet));
Class1.Test();
}
Как он может System.Data.dll не находить? Она же в GAC-е и должен быть видна всем.Unhandled Exception: System.IO.FileLoadException: Could not load file or assembl
y 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e08
9' or one of its dependencies. Access is denied.
at ConsoleApplication1.Program.Test()
at ConsoleApplication1.Program.Main()
Press any key to continue . . .