Jump to content

[Help] Countdown to shut down script


Recommended Posts

You may find the following fun!

@MODE CON: COLS=32 LINES=1
@COLOR E5
@TITLE Countdown
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /F %%# IN ('COPY /Z "%~dpf0" NUL') DO SET "CR=%%#"
FOR /L %%# IN (10,-1,1) DO (SET/P "=Script will end in %%# seconds. !CR!"<NUL:
PING -n 2 127.0.0.1 >NUL:)

The first three lines are pointless additions which can be removed, change the 10 in the second 'FOR loop' to the number of seconds you wish to count down from.

I have been playing with this to get it to work for me. What I need is a batch file that I will put into the windows scheduler to shutdown the computer on a daily basis.

So far, I have made some piecemeal changes to the above code to set it for 60 seconds and to lengthen the countdown line. I am doing something wrong because it does not act like I planned. I also wish to put an opt out in case a user still would like the computer to not shutdown. This latest should occur while the countdown is in progress. I am attaching what I have done so far.

Bill

OOP's I am unable to attach a file. So I will copy and paste.

@MODE CON: COLS=66 LINES=1

@COLOR E5

@TITLE Countdown

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

FOR /F %%# IN ('COPY /Z "%~dpf0" NUL') DO SET "CR=%%#"

FOR /L %%# IN (60,-1,1) DO (SET/P "=Computer will shutdown in %%# seconds.Press Y to continue working. !CR!"<NUL:

PING -n 2 127.0.0.1 >NUL:)

Edited by blockie
Link to comment
Share on other sites


Perhaps a HTA using VBS scripting would be better for what you want. I have

made this HTA Demo of a count down, you can cancel the count down and close

the HTA.

<!--June-22-13 Hta And Script By Gunsmokingman Aka Jake1Eye This code is property of Gunsmokingman and Or Jake1Eye and you must have his permission to use. This is only posted as example code and meant only to used as such.--><TITLE>Demo Count Down</TITLE><HTA:APPLICATION ID="D_C_Down"SCROLL="No"SCROLLFLAT ="No"SingleInstance="Yes"ShowInTaskbar="No"SysMenu="No"MaximizeButton="No"MinimizeButton="No"Border="Thin"BORDERSTYLE ="complex"INNERBORDER ="No"Caption="Yes"WindowState="Normal"APPLICATIONNAME="DCDown"Icon="%SystemRoot%\explorer.exe"><STYLE type="text/css">Body{Padding-Left:3pt;Padding-Right:3pt;Padding-Top:1pt;Padding-Bottom:1pt;Margin:1pt;Font-Size:9.25pt;Font-Weight:Bold;Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;Color:Black;BackGround-Color:#EFE9E3;Text-Align:Center;Vertical-Align:Top;}TD{Font-Size:9.25pt;Font-Weight:Bold;}BUTTON{Height:15pt;width:51pt;Cursor:Hand;Font:9.25pt;Font-weight:bold;Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;Color:#404040;Text-Align:Center;Vertical-Align:Middle;filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#E5E5E5',EndColorStr='#7D7D7D');Margin:1;Padding:2;Border-Left: 1px Transparent;Border-Right: 2px Transparent;Border-Top: 1px Transparent;Border-Bottom: 2px Transparent;}</STYLE><script LANGUAGE='VBScript'>'-> Resize And Place In Approx Center Of ScreenDim Wth, Hht :Wth = int(401) :Hht = int(155)window.ResizeTo Wth, HhtMoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))'-> Varibles For RuntimeDim S1, Tm1'-> Window OnloadFunction Window_OnLoad()'-> Set The Timer At 90S1 = 90Counter()End Function'-> Counter For Count DownFunction Counter()If S1 = 0 Then'-> Code Here For Action When Timer Reaches Zerowindow.clearTimeout(Tm1)Tx1.innerHTML="000"Exit FunctionEnd If'-> Add Zero To Count DownIf Len(S1) = 1 Then S1 = "00" & S1If Len(S1) = 2 Then S1 = "0" & S1Tx1.style.color="#9A0000" :Tx1.innerHTML=S1S1 = S1 - 1Tm1=window.setTimeout("Counter()",1000,"VBScript")End Function</SCRIPT><BODY><!-- Text Display --><P Style='Text-Align:Left;Margin-Bottom:1pt;Padding:3pt;'>When the timer reaches zero, it will then do some type of action. To Cancelpress the Close button to stop and close this window.</P><!-- Display The Count Down --><TABLE Style='Margin-Top:2pt;Margin-Bottom:3pt;'><TD><TD>Time Remaining »</TD><TD><DIV ID='Tx1'>000</DIV></TD></TD></TABLE><!-- Button Container --><TABLE><BUTTON ID='Bn1' OnClick="window.clearTimeout(Tm1): window.close()">Close</BUTTON></TABLE></BODY>
Link to comment
Share on other sites

GunSmokingMan,

Thanks for your idea. It's just what I need. When I edit the command where the timer reaches zero I replaced the line you identified as the place to put the action code. I put in the following.....C:\windows\system32\shutdown.exe -s -f -t 00

Did not work here although it works in the windows scheduler.

I am not versed in HPA or VBS so it is very difficult for me to edit your script. I'm also 83 years old and a bit slow. So please bear with me..

Also when I run the attached file the Close Button is not to be seen.

Bill

Link to comment
Share on other sites

To run the exe change to this


'-> Code Here For Action When Timer Reaches Zero
window.clearTimeout(Tm1)
Tx1.innerHTML="000"
CreateObject("Wscript.Shell").Run("shutdown.exe -s -f -t 00"),0,False
window.close()

Sound like you need to resize the HTA to fit any text changes that you may of made.

This controls the size of the window so change it until it fits what you need.

Wth=Width

Hht=Height


'-> Resize And Place In Approx Center Of Screen
Dim Wth, Hht :Wth = int(401) :Hht = int(155)

Link to comment
Share on other sites

@blockie

Why can you not just use the shutdown command alone?

At 22:30 /every:M,T,W,Th,F Cmd /c Shutdown -s -t 60

shutdown the PC at 10:30 PM on each weekday with a 60 second countdown.

Link to comment
Share on other sites

To run the exe change to this


'-> Code Here For Action When Timer Reaches Zero
window.clearTimeout(Tm1)
Tx1.innerHTML="000"
CreateObject("Wscript.Shell").Run("shutdown.exe -s -f -t 00"),0,False
window.close()

Sound like you need to resize the HTA to fit any text changes that you may of made.

This controls the size of the window so change it until it fits what you need.

Wth=Width

Hht=Height


'-> Resize And Place In Approx Center Of Screen
Dim Wth, Hht :Wth = int(401) :Hht = int(155)

Works perfectly now. All I need to do is put it in the scheduler. Thanks a bunch.

Link to comment
Share on other sites

@blockie

Why can you not just use the shutdown command alone?

At 22:30 /every:M,T,W,Th,F Cmd /c Shutdown -s -t 60

shutdown the PC at 10:30 PM on each weekday with a 60 second countdown.

I've had it this way for several months and it worked fine, however I wanted to put a way out for the user and pretty it up some. Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...