Example #1
0
        public static void HandleDoShutdownAction(DoShutdownAction command, Client client)
        {
            try
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                switch (command.Action)
                {
                case KapatmaEylemleri.Kapat:
                    startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                    startInfo.UseShellExecute = true;
                    startInfo.Arguments       = "/s /t 0"; // kapatma
                    startInfo.FileName        = "shutdown";
                    Process.Start(startInfo);
                    break;

                case KapatmaEylemleri.YenidenBaşlat:
                    startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                    startInfo.UseShellExecute = true;
                    startInfo.Arguments       = "/r /t 0"; // yeniden başlatma
                    startInfo.FileName        = "shutdown";
                    Process.Start(startInfo);
                    break;

                case KapatmaEylemleri.BeklemeyeAl:
                    Application.SetSuspendState(PowerState.Suspend, true, true);     // beklemeye alma
                    break;
                }
            }
            catch (Exception ex)
            {
                new SetStatus(string.Format("Eylem Başarısız: {0}", ex.Message)).Execute(client);
            }
        }
Example #2
0
        private void Execute(ISender client, DoShutdownAction message)
        {
            try
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                switch (message.Action)
                {
                case ShutdownAction.Shutdown:
                    startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                    startInfo.UseShellExecute = true;
                    startInfo.Arguments       = "/s /t 0"; // shutdown
                    startInfo.FileName        = "shutdown";
                    Process.Start(startInfo);
                    break;

                case ShutdownAction.Restart:
                    startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                    startInfo.UseShellExecute = true;
                    startInfo.Arguments       = "/r /t 0"; // restart
                    startInfo.FileName        = "shutdown";
                    Process.Start(startInfo);
                    break;

                case ShutdownAction.Standby:
                    Application.SetSuspendState(PowerState.Suspend, true, true);     // standby
                    break;
                }
            }
            catch (Exception ex)
            {
                client.Send(new SetStatus {
                    Message = $"Action failed: {ex.Message}"
                });
            }
        }