예제 #1
0
        public void UpdateList()
        {
            var l = WindowsManagerAPI.GetAllWindowsText();

            windowsList1.listView1.Items.Clear();

            foreach (var item in l)
            {
                windowsList1.listView1.Items.Add(new MyWindow(item));
            }

            label1.Text = "Окон: " + l.Count;
        }
예제 #2
0
        public void Do()
        {
            if (!isUsed)
            {
                isUsed = true;
                try
                {
                    if (PlaySound && ShowMessage)
                    {
                        Thread t = new Thread(new ParameterizedThreadStart(twiceMsg));
                        t.Start();
                    }
                    else
                    {
                        try
                        {
                            if (PlaySound)
                            {
                                try
                                {
                                    MainForm.mp.Stop();
                                }
                                catch { }

                                MainForm.mp = new System.Windows.Media.MediaPlayer();
                                MainForm.mp.Open(new Uri(SoundFilename));
                                MainForm.mp.Play();
                            }
                        }
                        catch { }

                        try
                        {
                            if (ShowMessage)
                            {
                                Thread t = new Thread(new ParameterizedThreadStart(msg));
                                t.Start();
                            }
                        }
                        catch { }
                    }
                }
                catch { }

                try
                {
                    if (KillProcess)
                    {
                        if (KillByName)
                        {
                            var p = Process.GetProcessesByName(KillProcessName);
                            foreach (var item in p)
                            {
                                item.Kill();
                            }
                        }
                        else
                        {
                            WindowsManagerAPI.KillWindowsByName(KillWindowName);
                        }
                    }
                }
                catch { }

                try
                {
                    if (LaunchProgram)
                    {
                        System.Diagnostics.Process.Start(LaunchString, LaunchParametrsString);
                    }
                }
                catch { }

                try
                {
                    if (TurnComputerOff)
                    {
                        switch (PowerMode)
                        {
                        case PowerMode.TurnOff:
                            PowerAPI.Shutdown(ForceShutdown);
                            break;

                        case PowerMode.Restart:
                            PowerAPI.Restart(ForceShutdown);
                            break;

                        case PowerMode.Lock:
                            PowerAPI.Lock();
                            break;

                        case PowerMode.Sleep:
                            Application.SetSuspendState(PowerState.Suspend, ForceShutdown, false);
                            break;

                        case PowerMode.Hibernate:
                            Application.SetSuspendState(PowerState.Hibernate, ForceShutdown, false);
                            break;

                        default:
                            break;
                        }
                    }
                }
                catch { }
            }
        }