I use Shutdown.exe in my application because it offers some interesting features, such as it can delay the shutdown and add a comment on why it should be disabled.
Application specifications may include shutdown, reboot, logout, hibernation, hybrid shutdown file, add comment and delay shutdown, and interrupt scheduled shutdown.
The application was nice and dandy, and I created the installation file. Now I tried to install it locally and use it. But when I tried, for example, clicked on hybernate, it just stopped ... I clicked on restart, it turned off, and the same thing with others.
I'm sure I'm using the right combination of parameters
this is the parameter i used
void PowerButtonsClick(object sender, RoutedEventArgs e) { string p = string.Empty; if (sender == btnShutdown) { p += "-s"; } else if (sender == btnRestart) { p += "-r"; } else if (sender == btnSignoff) { p += "-l"; } else if (sender == btnHibernate) { p += "-h"; } else if (sender == btnHybridShutdown) { p += "-hybrid -s"; } else if (sender == btnAbortShutdown) { p += "-a"; } if (sender != btnAbortShutdown) { if (sender != btnSignoff || sender != btnHibernate) { if (isForced) { p += " -f"; } double seconds = TimeSpan.FromTicks(timePicker.Value.Value.Subtract(DateTime.Now).Ticks).TotalSeconds; p += " -t " + Convert.ToInt32(seconds); if (hasComment) { p += string.Format(" -c \"{0}\"", borderComment_txComment.Text); } } } System.Diagnostics.Debug.WriteLine("param: " + p); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { Arguments = p, FileName = "shutdown.exe" }); }
and this is the application that I created 3 days ago. It was intended for Windows 8, and now I have disabled the download link due to the problem http://wall.jaysonragasa.net/wall/post/2012/06/17/Windows-8-System-Power-Shortcuts.aspx
to tell you honestly, everything works well when working with the IDE .. but during installation .. I had a problem. I even tried to parse a deployed application using ILSpy, and it looks fine and nothing bad.
- UPDATE - just update my code in
if (sender != btnSignoff || sender != btnHibernate) { ~~ }
he should be
if (sender != btnSignoff && sender != btnHibernate) { ~~ }
log result in case you requested
param: -s -f -t 0 param: -l param: -r -f -t 0 param: -h param: -a param: -hybrid -s -f -t 0 param: -s -f -t 0 -c "my comment" param: -s -f -t 5 -c "my comment" param: -s -f -t 12118 -c "my comment" param: -s -t 12110 -c "my comment"
- UPDATE -
I decided to use API calls, but I lost the Abort functionality, which is so important. If you can share how to interrupt a scheduled shutdown, even if you are using WMI or the API, please share it.
Applies to all