Peter Malone

Peter Malone

  • NA
  • 12
  • 61.9k

Code to hibernate PC

Jan 18 2011 4:18 PM
I have the following code under a logoff event in a Windows app I have written:
  if (e.Reason == SessionEndReasons.Logoff)

{

string command = string.Format(@"/c POWERCFG /CHANGE /hibernate-timeout-dc 1");

ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe");

cmdsi.WindowStyle = ProcessWindowStyle.Hidden;



cmdsi.Arguments = command;

Process cmd = Process.Start(cmdsi);





It changes the power options to make the PC go to hibernate one minute after the user logs off. 

If you copy and paste this part of the code into a dos window you will see the change in Windows power options

 POWERCFG /CHANGE /hibernate-timeout-dc 1

It works OK when I install the app and then log off. But if I log back on and log off after that it gives me "the application was unable to start" error and an error code.
I can only log off once for it to work. Restarting doesn't fix it.
Would appreciate any help, thanks.


Answers (5)

0
Sudheer G

Sudheer G

  • 0
  • 73
  • 10.1k
Jan 5 2016 9:29 AM
Create taxtbox, button and dropdown
 
<input type="text" id="txtno" />
<input type="button" id="btnsubmit" value="Add to List" /><br/>
<select id="Select1" multiple="multiple" style="width:10%;"></select>
<input type="button" id="btnsort" value="Sort" />
 
Button Click Function add into dropdown
 
<script type="text/javascript">
$("#btnsubmit").click(function () {
var no = $("#txtno").val();
$("#Select1").append($("<option></option>").attr("value", no).text(no));
$("#txtno").val('');
})
</script> 
 
after adding dropdown values you select the value from dropdown list or another textbox value enter,  which value multiply?
am not getting Ur Q.. Do one thing what is Ur requirement draw the paint and post it, is it possible I help you..