Это зависит от того, можете ли вы получить указатель, например,
[DllImport("advapi32.dll", SetLastError = true)]
static extern bool LogonUser(string principal, string authority, string password, LogonSessionType logonType, LogonProvider logonProvider, out IntPtr token);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool CloseHandle(IntPtr handle);
public void DoSomething() {
IntPtr token = IntPtr.Zero;
WindowsImpersonationContext user = null;
try {
bool loggedin = LogonUser((string)parameters[1], (string)parameters[2], (string)parameters[3], LogonSessionType.Interactive, LogonProvider.Default, out token);
if (loggedin) {
WindowsIdentity id = new WindowsIdentity(token);
user = id.Impersonate();
}
} catch (Exception ex) {
} finally {
if (user != null) {
user.Undo();
}
if (token != IntPtr.Zero) {
CloseHandle(token);
}
}
}