第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

以其他用戶身份啟動(dòng).Net進(jìn)程

以其他用戶身份啟動(dòng).Net進(jìn)程

C#
慕妹3242003 2019-09-26 10:37:52
我想啟動(dòng)一個(gè)具有管理員權(quán)限的進(jìn)程。當(dāng)我在下面運(yùn)行代碼時(shí),Process抱怨說它需要管理員權(quán)限:public class ImpersonationHelper : IDisposable{     IntPtr m_tokenHandle = new IntPtr(0);     WindowsImpersonationContext m_impersonatedUser;     #region Win32 API Declarations     const int LOGON32_PROVIDER_DEFAULT = 0;     const int LOGON32_LOGON_INTERACTIVE = 2;    //This parameter causes LogonUser to create a primary token.     [DllImport("advapi32.dll", SetLastError = true)]     public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,     int dwLogonType, int dwLogonProvider, ref IntPtr phToken);     [DllImport("kernel32.dll", CharSet = CharSet.Auto)]     public extern static bool CloseHandle(IntPtr handle);     [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]     public extern static bool DuplicateToken(IntPtr ExistingTokenHandle,     int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle);     #endregion     /// <summary>     /// Constructor. Impersonates the requested user. Impersonation lasts until     /// the instance is disposed.     /// </summary>     public ImpersonationHelper(string domain, string user, string password)     {         // Call LogonUser to obtain a handle to an access token.         bool returnValue = LogonUser(user, domain, password,             LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,             ref m_tokenHandle);         if (false == returnValue)         {             int ret = Marshal.GetLastWin32Error();             throw new System.ComponentModel.Win32Exception(ret);         }         // Impersonate         m_impersonatedUser = new WindowsIdentity(m_tokenHandle).Impersonate();     }     #region IDisposable Pattern     /// <summary>     /// Revert to original user and cleanup.     /// </summary>     protected virtual void Dispose(bool disposing)     {         if (disposing)         {             // Revert to original user identity             if (m_impersonatedUser != null)                 m_impersonatedUser.Undo();         }
查看完整描述

3 回答

  • 3 回答
  • 0 關(guān)注
  • 459 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)