public static void playSystemSpeaker(int repeat, int freq, int msDuration) { try { for (int i = 0; i < repeat; i++) { WinAPIHelper.Beep(freq, msDuration); } } catch (Exception ex) { throw ex; } finally { } }
public static WindowsImpersonationContext impersonateValidUser(String userName, String domain, String password) { WindowsImpersonationContext impersonationContext; WindowsIdentity tempWindowsIdentity; IntPtr token = IntPtr.Zero; IntPtr tokenDuplicate = IntPtr.Zero; if (WinAPIHelper.RevertToSelf()) { if (WinAPIHelper.LogonUserA(userName, domain, password, WinAPIHelper.LOGON32_LOGON_INTERACTIVE, WinAPIHelper.LOGON32_PROVIDER_DEFAULT, ref token) != 0) { if (WinAPIHelper.DuplicateToken(token, 2, ref tokenDuplicate) != 0) { tempWindowsIdentity = new WindowsIdentity(tokenDuplicate); impersonationContext = tempWindowsIdentity.Impersonate(); if (impersonationContext != null) { WinAPIHelper.CloseHandle(token); WinAPIHelper.CloseHandle(tokenDuplicate); return(impersonationContext); } } } } if (token != IntPtr.Zero) { WinAPIHelper.CloseHandle(token); } if (tokenDuplicate != IntPtr.Zero) { WinAPIHelper.CloseHandle(tokenDuplicate); } return(null); }