Exemple #1
0
        protected override void OnClick(EventArgs e)
        {
            if (UACUtilities.HasAdminPrivileges())
            {
                base.OnClick(e);  // this can only be called if we're an admin, we are assuming it contains admin-only stuff
            }
            else
            {
                UACUtilities.AttemptPrivilegeEscalation(
                    EscalationProcessPath(),
                    delegate()
                {
                    OnEscalationStarting(escalationGoal, this, new EventArgs());
                },
                    delegate()
                {
                    OnEscalationCancelled(escalationGoal, this, new EventArgs());
                },
                    delegate()
                {
                    OnEscalationSuccessful(escalationGoal, this, new EventArgs());

                    if (escalationGoal == EscalationGoal.RestartThisApplication)
                    {
                        Application.Exit();
                    }
                });
            }
        }
Exemple #2
0
        /// <summary>
        /// Resets AlwaysShowShield property.
        /// </summary>
        private void ResetAlwaysShowShield()
        {
            alwaysShowShield = false;

            if (UACUtilities.HasAdminPrivileges()) // then show the shield on the button
            {
                // Show the shield
                SendMessage(new HandleRef(this, this.Handle), BCM_SETSHIELD, new IntPtr(0), new IntPtr(1)); // the (1) for true
            }

            else
            {
                // Hide the shield
                SendMessage(new HandleRef(this, this.Handle), BCM_SETSHIELD, new IntPtr(0), new IntPtr(0)); // the (0) for false
            }
        }