Processus de Shutdown.exe avec plusieurs arguments, ne fonctionnant pas
-
29-10-2019 - |
Question
Je souhaite créer un processus qui utilise Shutdown.exe pour arrêter l'ordinateur après une heure donnée.
Voici mon code:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "shutdown.exe";
startInfo.Arguments = "–s –f –t " + seconds;
Process.Start(startInfo);
Où secondes est une variable locale int, l'utilisateur décide.
Quand j'exécute mon code, rien ne se passe. Mais quand je vais manuellement dans une invite CMD et Type:
shutdown.exe - s -f -t 999
Ensuite, Windows fera une fenêtre contextuelle et me dira que le système s'arrêtera en 16 minutes.
La raison pour laquelle je pense que c'est à cause des arguments multiples, c'est que ma méthode pour interrompre l'arrêt du système en cours fonctionne (où j'ai créé le système Systemshutdown à partir de l'invite CMD). C'est presque le même, sauf à startInfo.argument:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "shutdown.exe";
startInfo.Arguments = "-a";
Process.Start(startInfo);
Pas de solution correcte
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow