Esempio n. 1
0
        public WuAgent()
        {
            mInstance   = this;
            mDispatcher = Dispatcher.CurrentDispatcher;

            mUpdateDownloader           = new UpdateDownloader();
            mUpdateDownloader.Finished += DownloadsFinished;
            mUpdateDownloader.Progress += DownloadProgress;


            mUpdateInstaller           = new UpdateInstaller();
            mUpdateInstaller.Finished += InstallFinished;
            mUpdateInstaller.Progress += InstallProgress;

            dlPath = Program.appPath + @"\Downloads";

            WindowsUpdateAgentInfo info = new WindowsUpdateAgentInfo();
            var currentVersion          = info.GetInfo("ApiMajorVersion").ToString().Trim() + "." + info.GetInfo("ApiMinorVersion").ToString().Trim() + " (" + info.GetInfo("ProductVersionString").ToString().Trim() + ")";

            AppLog.Line("Windows Update Agent Version: {0}", currentVersion);

            mUpdateSession = new UpdateSession();
            mUpdateSession.ClientApplicationID = Program.mName;
            //mUpdateSession.UserLocale = 1033; // alwys show strings in englisch

            mUpdateServiceManager = new UpdateServiceManager();

            if (MiscFunc.parseInt(Program.IniReadValue("Options", "LoadLists", "0")) != 0)
            {
                LoadUpdates();
            }
        }
Esempio n. 2
0
        public Update(IUpdate update)
        {
            Entry = update;

            Title       = update.Title;
            Category    = GetCategory(update);
            Description = update.Description;
            Size        = GetSizeStr(update);
            Date        = update.LastDeploymentChangeTime.ToString("dd.MM.yyyy");
            KB          = GetKB(update);

            try
            {
                if (update.IsBeta)
                {
                    State = "Beta ";
                }

                if (update.IsInstalled)
                {
                    State += "Installed";
                    if (update.IsUninstallable)
                    {
                        State += " Removable";
                    }
                }
                else if (WuAgent.safe_IsHidden(update))
                {
                    State += "Hidden";
                    if (WuAgent.safe_IsDownloaded(update))
                    {
                        State += " Downloaded";
                    }
                }
                else
                {
                    if (WuAgent.safe_IsDownloaded(update))
                    {
                        State += "Downloaded";
                    }
                    else
                    {
                        State += "Pending";
                    }
                    if (update.AutoSelectOnWebSites) //update.DeploymentAction
                    {
                        State += " (!)";
                    }
                    if (update.IsMandatory)
                    {
                        State += " Manatory";
                    }
                }
            }
            catch (Exception err) {}
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Program.args = args;

            AppLog Log = new AppLog();

            WuAgent Agent = new WuAgent();

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

            for (int i = 0; i < Program.args.Length; i++)
            {
                if (Program.args[i].Equals("-onclose", StringComparison.CurrentCultureIgnoreCase))
                {
                    Process.Start(Program.args[++i]);
                }
            }
        }
Esempio n. 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...");

            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();
        }
Esempio n. 5
0
 public UpdateCallback(WuAgent agent)
 {
     this.agent = agent;
 }
Esempio n. 6
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;
            }
        }
Esempio n. 7
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();
        }
Esempio n. 8
0
 public WuAgent()
 {
     mInstance   = this;
     mDispatcher = Dispatcher.CurrentDispatcher;
 }
Esempio n. 9
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();
        }