Support Forums
C# Monitor new startup programs - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: C# Monitor new startup programs (/showthread.php?tid=20207)



C# Monitor new startup programs - t0fxREAL - 07-04-2011

An interesting function if you want to avoid new programs to be added to windows startup :

Code:
public void FillStartUpList()
        {
            var mangnmt = new ManagementClass("Win32_StartupCommand");
            ManagementObjectCollection mcol = mangnmt.GetInstances();
            foreach (ManagementObject strt in mcol)
            {
                StartUpList.Add(strt["Command"] + " Method : " + strt["Location"]);
            }
        }

        public void StartUpTimer()
        {
            MyTimer.Tick += CheckStartUpList;
            // Sets the timer interval to 5 seconds.
            MyTimer.Interval = 5000;
            MyTimer.Start();
        }

        public void CheckStartUpList(Object myObject, EventArgs myEventArgs)
        {
            var mangnmt = new ManagementClass("Win32_StartupCommand");
            var mcol = mangnmt.GetInstances();
            foreach (ManagementObject strt in mcol)
            {
                NewStartUpList.Add(strt["Command"] + " Method : " + strt["Location"]);
            }

            var diff = NewStartUpList.Except(StartUpList).ToList();
            foreach (var added in diff)
            {
                MessageBox.Show(added);
            }

            StartUpList.Clear();
            StartUpList.AddRange(NewStartUpList);
        }

Code:
StartUpTimer();

In the exemple it just shows a messagebox with the infos of the program added to startup (path and method). You can do what you want with the results (delete registry key, delete binary...).


RE: C# Monitor new startup programs - AceInfinity - 07-04-2011

But then you need to add a program like this to startup, and why would you use a timer? It would have been better to look for windows messages and changes.