Exemple #1
0
        public WuMgr()
        {
            InitializeComponent();

            this.Text = Program.fmt("Windows Update Manager by David Xanatos");

            toolTip.SetToolTip(btnSearch, "Search");
            toolTip.SetToolTip(btnInstall, "Install");
            toolTip.SetToolTip(btnDownload, "Download");
            toolTip.SetToolTip(btnHide, "Hide");
            toolTip.SetToolTip(btnGetLink, "Get Links");
            toolTip.SetToolTip(btnUnInstall, "Uninstall");
            toolTip.SetToolTip(btnCancel, "Cancel");

            AppLog.Logger  += LineLogger;
            agent           = WuAgent.GetInstance();
            agent.Found    += FoundUpdates;
            agent.Progress += OnProgress;
            agent.Init();

            updateView.ShowGroups            = true;
            updateView.ShowItemCountOnGroups = true;
            updateView.AlwaysGroupByColumn   = updateView.ColumnsInDisplayOrder[1];
            updateView.Sort();

            for (int i = 0; i < agent.mServiceList.Count; i++)
            {
                string service = agent.mServiceList[i];
                dlSource.Items.Add(service);
                if (service.Equals("Windows Update", StringComparison.CurrentCultureIgnoreCase))
                {
                    dlSource.SelectedIndex = i;
                }
            }

            mSuspendGPO = true;

            {
                var    subKey    = Registry.LocalMachine.CreateSubKey(mWuGPO, false);
                object value_drv = subKey.GetValue("ExcludeWUDriversInQualityUpdate");

                if (value_drv == null)
                {
                    chkDrivers.CheckState = CheckState.Indeterminate;
                }
                else if ((int)value_drv == 1)
                {
                    chkDrivers.CheckState = CheckState.Unchecked;
                }
                else if ((int)value_drv == 0)
                {
                    chkDrivers.CheckState = CheckState.Checked;
                }
            }

            {
                var    subKey   = Registry.LocalMachine.CreateSubKey(mWuGPO + @"\AU", true);
                object value_no = subKey.GetValue("NoAutoUpdate");
                if (value_no == null || (int)value_no == 0)
                {
                    object value_au = subKey.GetValue("AUOptions");
                    switch (value_au == null ? 0 : (int)value_au)
                    {
                    case 2:
                        dlPolMode.SelectedIndex = 2;
                        break;

                    case 3:
                        dlPolMode.SelectedIndex = 3;
                        break;

                    case 4:
                        dlPolMode.SelectedIndex = 4;
                        dlShDay.Enabled         = dlShTime.Enabled = true;
                        break;

                    case 5:
                        dlPolMode.SelectedIndex = 5;
                        break;
                    }
                }
                else
                {
                    dlPolMode.SelectedIndex = 1;
                }

                object value_day = subKey.GetValue("ScheduledInstallDay");
                if (value_day != null)
                {
                    dlShDay.SelectedIndex = (int)value_day;
                }
                object value_time = subKey.GetValue("ScheduledInstallTime");
                if (value_time != null)
                {
                    dlShTime.SelectedIndex = (int)value_time;
                }
            }
            mSuspendGPO = false;

            UpdateCounts();
            SwitchList(UpdateLists.UpdateHistory);

            bool doUpdate = false;

            for (int i = 0; i < Program.args.Length; i++)
            {
                if (Program.args[i].Equals("-update", StringComparison.CurrentCultureIgnoreCase))
                {
                    doUpdate = true;
                }
            }

            if (doUpdate)
            {
                aTimer          = new Timer();
                aTimer.Interval = 1000;
                // Hook up the Elapsed event for the timer.
                aTimer.Tick   += OnTimedEvent;
                aTimer.Enabled = true;
            }
        }
Exemple #2
0
        public WuMgr()
        {
            InitializeComponent();

            //notifyIcon1.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location);
            notifyIcon.Text = Program.mName;

            if (Program.TestArg("-tray"))
            {
                allowshowdisplay   = false;
                notifyIcon.Visible = true;
            }

            this.Text = MiscFunc.fmt("{0} v{1} by David Xanatos", Program.mName, Program.mVersion);

            toolTip.SetToolTip(btnSearch, "Search");
            toolTip.SetToolTip(btnInstall, "Install");
            toolTip.SetToolTip(btnDownload, "Download");
            toolTip.SetToolTip(btnHide, "Hide");
            toolTip.SetToolTip(btnGetLink, "Get Links");
            toolTip.SetToolTip(btnUnInstall, "Uninstall");
            toolTip.SetToolTip(btnCancel, "Cancel");

            btnSearch.Image    = (Image)(new Bitmap(global::wumgr.Properties.Resources.icons8_available_updates_32, new Size(25, 25)));
            btnInstall.Image   = (Image)(new Bitmap(global::wumgr.Properties.Resources.icons8_software_installer_32, new Size(25, 25)));
            btnDownload.Image  = (Image)(new Bitmap(global::wumgr.Properties.Resources.icons8_downloading_updates_32, new Size(25, 25)));
            btnUnInstall.Image = (Image)(new Bitmap(global::wumgr.Properties.Resources.icons8_trash_32, new Size(25, 25)));
            btnHide.Image      = (Image)(new Bitmap(global::wumgr.Properties.Resources.icons8_hide_32, new Size(25, 25)));
            btnGetLink.Image   = (Image)(new Bitmap(global::wumgr.Properties.Resources.icons8_link_32, new Size(25, 25)));
            btnCancel.Image    = (Image)(new Bitmap(global::wumgr.Properties.Resources.icons8_cancel_32, new Size(25, 25)));

            AppLog.Logger += LineLogger;

            foreach (string line in AppLog.GetLog())
            {
                logBox.AppendText(line + Environment.NewLine);
            }
            logBox.ScrollToCaret();


            agent                = WuAgent.GetInstance();
            agent.Progress      += OnProgress;
            agent.UpdatesChaged += OnUpdates;
            agent.Finished      += OnFinished;

            if (!agent.IsActive())
            {
                if (MessageBox.Show("Windows Update Service is not available, try to start it?", Program.mName, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    agent.EnableWuAuServ();
                    agent.Init();
                }
            }

            mSuspendUpdate        = true;
            chkDrivers.CheckState = (CheckState)GPO.GetDriverAU();
            int day, time;

            dlPolMode.SelectedIndex   = GPO.GetAU(out day, out time);
            dlShDay.SelectedIndex     = day; dlShTime.SelectedIndex = time;
            chkBlockMS.CheckState     = (CheckState)GPO.GetBlockMS();
            dlAutoCheck.SelectedIndex = MiscFunc.parseInt(GetConfig("AutoUpdate", "0"));
            chkAutoRun.Checked        = Program.IsAutoStart();
            IdleDelay        = MiscFunc.parseInt(GetConfig("IdleDelay", "20"));
            chkNoUAC.Checked = Program.IsSkipUacRun();


            chkOffline.Checked  = MiscFunc.parseInt(GetConfig("Offline", "1")) != 0;
            chkDownload.Checked = MiscFunc.parseInt(GetConfig("Download", "1")) != 0;
            chkManual.Checked   = MiscFunc.parseInt(GetConfig("Manual", "0")) != 0;
            chkOld.Checked      = MiscFunc.parseInt(GetConfig("IncludeOld", "0")) != 0;
            string source = GetConfig("Source", "Windows Update");

            string Online = Program.GetArg("-online");

            if (Online != null)
            {
                chkOffline.Checked = false;
                if (Online.Length > 0)
                {
                    source = agent.GetServiceName(Online, true);
                }
            }

            string Offline = Program.GetArg("-offline");

            if (Offline != null)
            {
                chkOffline.Checked = true;
                if (Offline.Equals("download", StringComparison.CurrentCultureIgnoreCase))
                {
                    chkDownload.Checked = true;
                }
                else if (Offline.Equals("no_download", StringComparison.CurrentCultureIgnoreCase))
                {
                    chkDownload.Checked = false;
                }
            }

            if (Program.TestArg("-manual"))
            {
                chkManual.Checked = true;
            }

            try {
                LastCheck = DateTime.Parse(GetConfig("LastCheck", ""));
                AppLog.Line("Last Checked for updates: {0}", LastCheck.ToString());
            } catch { }

            LoadProviders(source);

            chkMsUpd.Checked = agent.IsActive() && agent.TestService(WuAgent.MsUpdGUID);

            if (GPO.IsRespected() == 0)
            {
                dlPolMode.Enabled = false;
                //toolTip.SetToolTip(dlPolMode, "Windows 10 Pro and Home do not respect this GPO setting");
            }

            chkHideWU.Enabled = GPO.IsRespected() != 2;
            chkHideWU.Checked = GPO.IsUpdatePageHidden();

            mSuspendUpdate = false;

            mToolsMenu      = new MenuItem();
            mToolsMenu.Text = "&Tools";

            BuildToolsMenu();

            notifyIcon.ContextMenu = new ContextMenu();

            MenuItem menuAbout = new MenuItem();

            menuAbout.Text   = "&About";
            menuAbout.Click += new System.EventHandler(menuAbout_Click);

            MenuItem menuExit = new MenuItem();

            menuExit.Text   = "E&xit";
            menuExit.Click += new System.EventHandler(menuExit_Click);

            notifyIcon.ContextMenu.MenuItems.AddRange(new MenuItem[] { mToolsMenu, menuAbout, new MenuItem("-"), menuExit });


            IntPtr MenuHandle = GetSystemMenu(this.Handle, false);                    // Note: to restore default set true

            InsertMenu(MenuHandle, 5, MF_BYPOSITION | MF_SEPARATOR, 0, string.Empty); // <-- Add a menu seperator
            InsertMenu(MenuHandle, 6, MF_BYPOSITION | MF_POPUP, (int)mToolsMenu.Handle, "Tools");
            InsertMenu(MenuHandle, 7, MF_BYPOSITION, MYMENU_ABOUT, "&About");


            UpdateCounts();
            SwitchList(UpdateLists.UpdateHistory);

            doUpdte = Program.TestArg("-update");

            mTimer          = new Timer();
            mTimer.Interval = 1000; // once epr second
            mTimer.Tick    += OnTimedEvent;
            mTimer.Enabled  = true;

            Program.ipc.PipeMessage += new PipeIPC.DelegateMessage(PipesMessageHandler);
            Program.ipc.Listen();
        }