Пример #1
0
        private void ButtonUnRegister_Click(object sender, EventArgs e)
        {
            if (!UacHelper.IsRunAsAdmin())
            {
                MessageBox.Show("You need administrator rights to unregister a DLL!", "Administrator ?", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            labelResult.BorderStyle = BorderStyle.None;
            labelResult.BackColor   = this.BackColor;
            labelResult.Text        = string.Empty;
            fct_box.Text            = string.Empty;
            SetToViewRegFile();

            Logger.Instance.AdddLog(LogType.Debug, "Start to unregister DLLs!", this);
            GetUiInput();

            if (comboBoxNetLink.SelectedItem == null || string.IsNullOrWhiteSpace((comboBoxNetLink.SelectedItem as NetItem).FullPath) || !System.IO.File.Exists((comboBoxNetLink.SelectedItem as NetItem).FullPath))
            {
                Logger.Instance.AdddLog(LogType.Error, "Framework link ?", this);
                return;
            }
            if (Setting.FileItems == null || Setting.FileItems.Count == 0)
            {
                Logger.Instance.AdddLog(LogType.Error, "Missing DLL file link ?", this);
                return;
            }

            Cursor.Current          = Cursors.WaitCursor;
            labelResult.BorderStyle = BorderStyle.FixedSingle;
            if (DllRegister.UnRegister(Setting, timeId))
            {
                labelResult.Text      = "OK!";
                labelResult.BackColor = Color.ForestGreen;
            }

            else
            {
                labelResult.Text      = "ERROR";
                labelResult.BackColor = Color.Red;
            }

            Cursor.Current = Cursors.Default;
        }
Пример #2
0
        private void GetInfo()
        {
            string message = string.Empty;

            // Get and display whether the primary access token of the process belongs
            // to user account that is a member of the local Administrators group even
            // if it currently is not elevated (IsUserInAdminGroup).
            try
            {
                message += "Is user in admin group:" + UacHelper.IsUserInAdminGroup().ToString();
            }
            catch
            {
                message += "Is user in admin group:N/A";
            }

            // Get and display whether the process is run as administrator or not
            // (IsRunAsAdmin).
            try
            {
                message += " |Run as admin:" + UacHelper.IsRunAsAdmin().ToString();
            }
            catch
            {
                message += " |Run as admin:N/A";
            }


            // Get and display the process elevation information (IsProcessElevated)
            // and integrity level (GetProcessIntegrityLevel). The information is not
            // available on operating systems prior to Windows Vista.
            if (Environment.OSVersion.Version.Major >= 6)
            {
                // Running Windows Vista or later (major version >= 6).

                try
                {
                    message += " |Is process elevated:" + UacHelper.IsProcessElevated().ToString();
                }
                catch
                {
                    message += " |Is process elevated:N/A";
                }

                try
                {
                    // Get and display the process integrity level.
                    int IL = UacHelper.GetProcessIntegrityLevel();
                    message += " |Integrity level:";

                    switch (IL)
                    {
                    case NativeMethods.SECURITY_MANDATORY_UNTRUSTED_RID:
                        message += "Untrusted"; break;

                    case NativeMethods.SECURITY_MANDATORY_LOW_RID:
                        message += "Low"; break;

                    case NativeMethods.SECURITY_MANDATORY_MEDIUM_RID:
                        message += "Medium"; break;

                    case NativeMethods.SECURITY_MANDATORY_HIGH_RID:
                        message += "High"; break;

                    case NativeMethods.SECURITY_MANDATORY_SYSTEM_RID:
                        message += "System"; break;

                    default:
                        message += "Unknown"; break;
                    }
                }
                catch
                {
                    message += "|Integrity level:N/A";
                }
            }
            else
            {
                message += " |Is process elevated:N/A |Integrity level:N/A";
            }
            Logger.Instance.AdddLog(LogType.Warn, message, this);
        }
Пример #3
0
        private void ButtonRegister_Click(object sender, EventArgs e)
        {
            if ((checkBoxInstallinGAC.Checked || !checkBoxRegistry.Checked) && !UacHelper.IsRunAsAdmin())
            {
                MessageBox.Show("You need administrator rights to register a DLL!", "Administrator ?", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            labelResult.BorderStyle = BorderStyle.None;
            labelResult.BackColor   = this.BackColor;
            labelResult.Text        = string.Empty;
            fct_box.Text            = string.Empty;
            SetToViewRegFile();

            Logger.Instance.AdddLog(LogType.Debug, "Start to register DLLs!", this);

            GetUiInput();

            #region project name
            //test project name --set to default?
            if (string.IsNullOrWhiteSpace(Setting.ProjectName) &&
                FileListcomboBox.SelectedItem != null &&
                !string.IsNullOrWhiteSpace((FileListcomboBox.SelectedItem as FileItem).FullPath))
            {
                textBoxPName.Text = "Register_" + System.IO.Path.GetFileNameWithoutExtension((FileListcomboBox.SelectedItem as FileItem).FullPath);
            }
            else
            {
                textBoxPName.Text = "Register_DLL";
            }
            Setting.ProjectName = textBoxPName.Text;
            #endregion

            #region Regasm.exe & file links ?
            if (Setting.FileItems == null || Setting.FileItems.Count == 0)
            {
                Logger.Instance.AdddLog(LogType.Error, "Missing DLL file link ?", this);
                MessageBox.Show("Please select DLL files (add button)!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (comboBoxNetLink.SelectedItem == null || string.IsNullOrWhiteSpace((comboBoxNetLink.SelectedItem as NetItem).FullPath) || !System.IO.File.Exists((comboBoxNetLink.SelectedItem as NetItem).FullPath))
            {
                Logger.Instance.AdddLog(LogType.Error, "Framework link ?", this);
                MessageBox.Show("Regasm.exe link is not set?", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            #endregion

            Cursor.Current = Cursors.WaitCursor;


            #region Register DLL
            if (DllRegister.Register(Setting, timeId))
            {
                labelResult.Text      = "OK!";
                labelResult.BackColor = Color.ForestGreen;
            }
            else
            {
                labelResult.Text      = "ERROR";
                labelResult.BackColor = Color.Red;
            }

            #endregion

            labelResult.BorderStyle = BorderStyle.FixedSingle;
            Cursor.Current          = Cursors.Default;
        }