Пример #1
0
        /// <summary>
        /// This functions sets the privilege of our target process
        /// </summary>
        public bool SetPrivilege(string lpszPrivilege, bool bEnablePrivilege)
        {
            bool Status = true;

            DeepDarkWin32Fantasy.TOKEN_PRIVILEGES priv = new DeepDarkWin32Fantasy.TOKEN_PRIVILEGES();
            IntPtr hToken = IntPtr.Zero;

            DeepDarkWin32Fantasy.LUID luid = new DeepDarkWin32Fantasy.LUID();
            int RetLength = 0;

            if (!Kernel32.OpenProcessToken(this.m_hProcess, 0x0020, ref hToken))
            {
                Status = false;
                goto EXIT;
            }

            if (!Advapi32.LookupPrivilegeValueA(null, lpszPrivilege, ref luid))
            {
                Status = false;
                goto EXIT;
            }

            priv.PrivilegeCount = 1;
            priv.Privileges     = new DeepDarkWin32Fantasy.LUID_AND_ATTRIBUTES
            {
                Luid = luid, Attributes = (int)((bEnablePrivilege == true) ? 0x00000002L : 0x00000004L)
            };

            if (!Kernel32.AdjustTokenPrivileges(hToken, false, ref priv, 0, IntPtr.Zero, ref RetLength))
            {
                Status = false;
                goto EXIT;
            }

EXIT:
            if (hToken != IntPtr.Zero)
            {
                Kernel32.CloseHandle(hToken);
            }
            return(Status);
        }
Пример #2
0
 public static extern bool LookupPrivilegeValueA(string lpSystemName, string lpName, ref DeepDarkWin32Fantasy.LUID lpLuid);