Beispiel #1
0
    private void UxRefresh()
    {
        uxlblEnabled.Text = @"Hosts file is " + (HostsFile.IsEnabled()
            ? "enabled."
            : "disabled.");

        uxlblHostsFileSize.Text = HostsFile
                                  .HostsFileSize()
                                  .ToString("##,###0") + @" byte(s)";

        uxlblHostsCount.Text =
            HostsFile
            .HostsCount()
            .ToString("##,###0");

        var hostsEnabled = HostsFile.IsEnabled();

        uxMenuEnableHostsFile.Checked = hostsEnabled;

        var hostOrHosts = HostsFile
                          .HostsCount() > 1
            ? "hosts"
            : "host";

        uxNotifyIcon.Text = @"Hosts Manager" + (hostsEnabled
            ? " (" + uxlblHostsCount.Text + " " + hostOrHosts + " enabled)"
            : " (disabled)");

        // button state
        if (Elevated.IsElevated())
        {
            // Elevated, set button state appropriately
            uxbtnRunAsAdmin.Enabled     =
                uxbtnRunAsAdmin.Visible =
                    uxlblSep.Visible    = false;

            uxbtnEdit.Enabled =
                uxbtnDisableHostsFile.Enabled = hostsEnabled;

            uxbtnEnableHostsFile.Enabled = !hostsEnabled;

            uxbtnFlushDNS.Enabled = true;

            // Indicate that we are running as admin.
            if (!Text.Contains("[Administrator]"))
            {
                Text += @" [Administrator]";
            }
        }
        else
        {
            // Not elevated, disable all except Run As Admin
            uxbtnDisableHostsFile.Enabled         =
                uxbtnEnableHostsFile.Enabled      =
                    uxMenuEnableHostsFile.Enabled =
                        uxbtnFlushDNS.Enabled     = false;

            // When Not elevated "edit/open" should only be available when the hosts file itself is enabled
            uxbtnEdit.Enabled = hostsEnabled;

            Elevated.AddShieldToButton(uxbtnRunAsAdmin);
        }
    }