Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

[Help] Countdown to shut down script

- - - - -

  • Please log in to reply
7 replies to this topic

#1
blockie

blockie
  • Member
  • 6 posts
  • Joined 21-June 13
  • OS:Windows 7 x86
  • Country: Country Flag

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, 21 June 2013 - 03:47 PM.



How to remove advertisement from MSFN

#2
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,419 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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 Screen
Dim Wth, Hht :Wth = int(401) :Hht = int(155)
window.ResizeTo Wth, Hht
MoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))
'-> Varibles For Runtime
Dim S1, Tm1
'-> Window Onload
Function Window_OnLoad()
'-> Set The Timer At 90
S1 = 90
Counter()
End Function
'-> Counter For Count Down
Function Counter()
If S1 = 0 Then
'-> Code Here For Action When Timer Reaches Zero
window.clearTimeout(Tm1)
Tx1.innerHTML="000"
Exit Function
End If
'-> Add Zero To Count Down
If Len(S1) = 1 Then S1 = "00" & S1
If Len(S1) = 2 Then S1 = "0" & S1
Tx1.style.color="#9A0000" :Tx1.innerHTML=S1
S1 = S1 - 1
Tm1=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 Cancel
press 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>



GunSmokingMan



#3
blockie

blockie
  • Member
  • 6 posts
  • Joined 21-June 13
  • OS:Windows 7 x86
  • Country: Country Flag
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

#4
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,419 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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)



GunSmokingMan



#5
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,546 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

@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.

#6
blockie

blockie
  • Member
  • 6 posts
  • Joined 21-June 13
  • OS:Windows 7 x86
  • Country: Country Flag

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.

#7
blockie

blockie
  • Member
  • 6 posts
  • Joined 21-June 13
  • OS:Windows 7 x86
  • Country: Country Flag

@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.

#8
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,546 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Topic moved/split, as a result of your acceptance of a non batch related solution.

Incidentally there is already a way out for the user using the shutdown command!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users