我已经创build了包括WindowsIdentity和WindowsImpersonationContext的模拟类,并且在服务运行了一段时间之后,我的身份validation应用程序中添加了模拟lsass.exe进程占用大量内存和cpu请问如何帮助我解决这个问题?
public class Impersonation : Idisposable { #region external // Declare signatures for Win32 logonUser and CloseHandle APIs [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)] public static extern bool CloseHandle(IntPtr handle); enum logonSessionType : uint { Interactive = 2,Network,Batch,Service,NetworkCleartext = 8,NewCredentials } enum logonProvider : uint { Default = 0,// default for platform (use this!) WinNT35,// sends smoke signals to authority WinNT40,// uses NTLM WinNT50 // negotiates Kerb or NTLM } #endregion #region variables private WindowsIdentity m_userWindowsID; private WindowsImpersonationContext m_userImpersonationContext; #endregion public void logonWindowsUser(string domain,string userLogin,string password) { IntPtr token; // Create a token for DomainNameBob // Note: Credentials should be encrypted in configuration file bool result = logonUser(userLogin,domain,password,logonSessionType.NewCredentials,logonProvider.Default,out token); if (result) { m_userWindowsID = new WindowsIdentity(token); } } public void ImpersonateUser() { if (m_userWindowsID == null) { throw new Exception("User is not loged on"); } m_userImpersonationContext = m_userWindowsID.Impersonate(); } #region Idisposable Members public void dispose() { if (m_userImpersonationContext != null) { m_userImpersonationContext.Undo(); m_userImpersonationContext.dispose(); } if (m_userWindowsID != null) { CloseHandle(m_userWindowsID.Token); m_userWindowsID.dispose(); //m_userWindowsID.Token = IntPtr.Zero; } } #endregion }
使用Python for Linux模拟Key Press事件
调整Windroy窗口的大小
使用标准VGAgraphics在机器上模拟OpenGL
MS-Windows调度程序控制(否则) – 在较慢的cpu上testing应用程序的性能?
为什么SendMessage()函数不起作用?
我不知道你是否还有这个问题,但是我遇到了一个非常类似的问题,并且没有在适当的时候调用CloseHandle(…)。
尝试移动m_userWindowsID = new WindowsIdentity(token)后的CloseHandle(…); logonWindowsUser方法中的行。
例:
public void logonWindowsUser(string domain,out token); if (result) { m_userWindowsID = new WindowsIdentity(token); CloseHandle(token); } }
希望这可以帮助!
克里斯
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。