コード例 #1
0
        static void Main(string[] args)
        {
            Program.args = args;

            mConsole = WinConsole.Initialize(TestArg("-console"));

            if (TestArg("-help") || TestArg("/?"))
            {
                ShowHelp();
                return;
            }

            if (TestArg("-dbg_wait"))
            {
                MessageBox.Show("Waiting for debugger. (press ok when attached)");
            }

            Console.WriteLine("Starting...");

            appPath = Path.GetDirectoryName(Application.ExecutablePath);
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            FileVersionInfo            fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);

            mVersion = fvi.FileMajorPart + "." + fvi.FileMinorPart;
            if (fvi.FileBuildPart != 0)
            {
                mVersion += (char)('a' + (fvi.FileBuildPart - 1));
            }

            Translate.Load();

            AppLog Log = new AppLog();

            AppLog.Line("{0}, Version v{1} by David Xanatos", mName, mVersion);
            AppLog.Line("This Tool is Open Source under the GNU General Public License, Version 3\r\n");

            ipc = new PipeIPC("wumgr_pipe");

            var client = ipc.Connect(100);

            if (client != null)
            {
                AppLog.Line("Application is already running.");
                client.Send("show");
                string ret = client.Read(1000);
                if (!ret.Equals("ok", StringComparison.CurrentCultureIgnoreCase))
                {
                    MessageBox.Show(Translate.fmt("msg_running"));
                }
                return;
            }

            if (!MiscFunc.IsAdministrator() && !MiscFunc.IsDebugging())
            {
                Console.WriteLine("Trying to get admin privileges...");

                if (SkipUacRun())
                {
                    Application.Exit();
                    return;
                }

                if (!MiscFunc.IsRunningAsUwp())
                {
                    Console.WriteLine("Trying to start with 'runas'...");
                    // Restart program and run as admin
                    var              exeName   = Process.GetCurrentProcess().MainModule.FileName;
                    string           arguments = "\"" + string.Join("\" \"", args) + "\"";
                    ProcessStartInfo startInfo = new ProcessStartInfo(exeName, arguments);
                    startInfo.UseShellExecute = true;
                    startInfo.Verb            = "runas";
                    try
                    {
                        Process.Start(startInfo);
                        Application.Exit();
                        return;
                    }
                    catch
                    {
                        //MessageBox.Show(Translate.fmt("msg_admin_req", mName), mName);
                        AppLog.Line("Administrator privileges are required in order to install updates.");
                    }
                }
            }

            wrkPath = appPath;

            if (!FileOps.TestWrite(GetINIPath()))
            {
                Console.WriteLine("Can't write to default working directory.");

                string downloadFolder = KnownFolders.GetPath(KnownFolder.Downloads);
                if (downloadFolder == null)
                {
                    downloadFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads";
                }

                wrkPath = downloadFolder + @"\WuMgr";
                try
                {
                    if (!Directory.Exists(wrkPath))
                    {
                        Directory.CreateDirectory(wrkPath);
                    }
                }
                catch
                {
                    MessageBox.Show(Translate.fmt("msg_ro_wrk_dir", wrkPath), mName);
                }
            }

            /*switch(FileOps.TestFileAdminSec(mINIPath))
             * {
             *  case 0:
             *      AppLog.Line("Warning wumgr.ini was writable by non administrative users, it was renamed to wumgr.ini.old and replaced with a empty one.\r\n");
             *      if (!FileOps.MoveFile(mINIPath, mINIPath + ".old", true))
             *          return;
             *      goto case 2;
             *  case 2: // file missing, create
             *      FileOps.SetFileAdminSec(mINIPath);
             *      break;
             *  case 1: // every thign's fine ini file is only writable by admins
             *      break;
             * }*/

            AppLog.Line("Working Directory: {0}", wrkPath);

            Agent = new WuAgent();

            ExecOnStart();

            Agent.Init();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new WuMgr());

            Agent.UnInit();

            ExecOnClose();
        }
コード例 #2
0
ファイル: WuMgr.cs プロジェクト: hobbit19/wumgr
        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();
        }
コード例 #3
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;
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Program.args = args;

            mConsole = WinConsole.Initialize(TestArg("-console"));

            if (TestArg("-help") || TestArg("/?"))
            {
                ShowHelp();
                return;
            }

            if (TestArg("-dbg_wait"))
            {
                MessageBox.Show("Waiting for debugger. (press ok when attached)");
            }

            Console.WriteLine("Starting...");

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            FileVersionInfo            fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);

            mVersion = fvi.FileMajorPart + "." + fvi.FileMinorPart;
            if (fvi.FileBuildPart != 0)
            {
                mVersion += (char)('a' + (fvi.FileBuildPart - 1));
            }

            AppLog Log = new AppLog();

            AppLog.Line("{0}, Version v{1} by David Xanatos", mName, mVersion);
            AppLog.Line("This Tool is Open Source under the GNU General Public License, Version 3\r\n");

            appPath = Path.GetDirectoryName(Application.ExecutablePath);

            ipc = new PipeIPC("wumgr_pipe");

            var client = ipc.Connect(100);

            if (client != null)
            {
                AppLog.Line("Application is already running.");
                client.Send("show");
                string ret = client.Read(1000);
                if (!ret.Equals("ok", StringComparison.CurrentCultureIgnoreCase))
                {
                    MessageBox.Show(MiscFunc.fmt("Application is already running."));
                }
                return;
            }

            if (IsAdministrator() == false)
            {
                Console.WriteLine("Trying to get admin privilegs...");
                if (!SkipUacRun())
                {
                    Console.WriteLine("Trying to start with 'runas'...");
                    // Restart program and run as admin
                    var              exeName   = Process.GetCurrentProcess().MainModule.FileName;
                    string           arguments = "\"" + string.Join("\" \"", args) + "\"";
                    ProcessStartInfo startInfo = new ProcessStartInfo(exeName, arguments);
                    startInfo.UseShellExecute = true;
                    startInfo.Verb            = "runas";
                    try
                    {
                        Process.Start(startInfo);
                    }
                    catch
                    {
                        MessageBox.Show(MiscFunc.fmt("The {0} requirers Administrator privilegs.\r\nPlease restart the application as Administrator.\r\n\r\nYou can use the option Start->'Bypass User Account Control' to solve this issue for future startsups.", mName), mName);
                    }
                }
                Application.Exit();
                return;
            }

            mINIPath = appPath + @"\wumgr.ini";

            /*switch(FileOps.TestFileAdminSec(mINIPath))
             * {
             *  case 0:
             *      AppLog.Line("Warning wumgr.ini was writable by non administrative users, it was renamed to wumgr.ini.old and replaced with a empty one.\r\n");
             *      if (!FileOps.MoveFile(mINIPath, mINIPath + ".old", true))
             *          return;
             *      goto case 2;
             *  case 2: // file missing, create
             *      FileOps.SetFileAdminSec(mINIPath);
             *      break;
             *  case 1: // every thign's fine ini file is only writable by admins
             *      break;
             * }*/

            Agent = new WuAgent();

            ExecOnStart();

            Agent.Init();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new WuMgr());

            Agent.UnInit();

            ExecOnClose();
        }