XWidgetSoft Forum
https://bbs.xwidget.com/

Help with Timed Shutdown
https://bbs.xwidget.com/viewtopic.php?f=7&t=34
Page 1 of 1

Author:  meme [ June 21st, 2012, 2:58 pm ]
Post subject:  Help with Timed Shutdown

Hi, I am trying to create a widget that will allow the user to set a time that the computer will shutdown every night.
This code works, shutting down at the set time and asking the user to abort the shutdown if required.
But if the user does not respond to the "Confirm" abort shutdown request it will remain active, while the system is shutting down.
Is there a way to dismiss the confirm request with a setTimeout? or another method all together ?
Thank you for your help :)

function TimedShutdown()
{
var NowDate = new Date();
var NowHour = NowDate.getHours();
var NowMin = NowDate.getMinutes();
var OffHour = NowHour; //OffHour will be set by user
var OffMin = NowMin; //OffMin will be set by user

if(NowHour == OffHour && NowMin == OffMin) //shutdown if time match
run("shutdown.exe -s -t 60");

//setTimeout("doSomething()",10000); //can it be used to dismiss the confirm ?

var answer = Confirm("Abort Shutdown ?") // ask user to abort shutdown
if (answer)
run("shutdown.exe -a");
}

Author:  qiancang [ June 21st, 2012, 9:55 pm ]
Post subject:  Re: Help with Timed Shutdown

hi,meme,nice to meet you
some main code:
function timercore1OnUpdate(Sender)
{
var NowDate = new Date();
var NowHour = NowDate.getHours();
var NowMin = NowDate.getMinutes();
var OffHour = parseInt(edit1.text);
var OffMin = parseInt(edit2.text);
if(NowHour == OffHour && NowMin == OffMin)
{
timercore1.Enabled=false;
if(confirm("shutdown"))run("shutdown.exe -s -t 60");
else setTimeout('dosomething',10000);
}
}

function dosomething()
{
if(confirm("shutdown")) run("shutdown.exe -s -t 60");
else setTimeout('dosomething',10000);
}

Attachments:
shutdown.rar [8.14 KiB]
Downloaded 303 times

Author:  meme [ June 22nd, 2012, 2:38 am ]
Post subject:  Re: Help with Timed Shutdown

Thanks again qiancang for your assistance, very helpful.

Greatly appreciated :D

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/