Jump to content

[help] How to shut down system from dos with countdown


Recommended Posts

in runonce,, i have to give reboot command,

currently i am giving

shutdown.exe -r -f -t 180 -c "UAXP will now restart in 3 minutes"

i dun like this at all,, coz it gives a popup windows which overrides any running programs hiding the messages running in MS-DOS windows, and many of user afraid of this popup {similar popup as of w32.blaster worm }

i like to use some dos command which should show the countdown for 3 minuts and restart the PC in DOS windows itself, not in additional pop up.

just in that black window !!!

example

c:\countdown -60 -restart >nul [should only give countdown number 1 2 3 4 5 6 7 ....... 60 and restart]

hope u got me...

Link to comment
Share on other sites


What I do normally is to use a zero value for the shutdown timer and use a program called "sleep.exe" to pause the system whilst programs are stopped. I know it doesn't look as cool as a timer counting down the seconds and I don't use DOS much either as I have my own Application Installer which replaces the DOS shell.

I guess you could use the "sleep.exe"program (Link is somewhere on this site. Been a while since I last downloaded it) in combination with simple echo commands in your batch to simulate a timer. For example:

@echo off
CLS
echo "Rebooting in 2 seconds..."
sleep.exe 1
CLS
echo "Rebooting in 1 second..."
sleep.exe 1
CLS
echo "Now Rebooting."
shutdown.exe -r -f -t 00

That code is a little clunky for a three minute countdown and I'm sure there are much better ways of doing it (With some sort of loop), but at least it gives you an idea. I used the CLS command to clear the screen and make it appear as though the timer is just counting down on the same line (A throwback to my old BBC Basic days at school).

Link to comment
Share on other sites

Here is a VBS script that will count down then run the reboot cmd

Dim Act : Set Act = CreateObject("Wscript.Shell")
'/-> Amount Of Time
Dim Cnt : Cnt = 180
'/-> Loop For The Timer
Do
Cnt = Cnt - 1
'/-> Messagebox With Timer
Act.Popup "There is this many Seconds Left Before Reboot : " & Cnt, 1, "Reboot CountDown", 0 + 32
Loop Until Cnt = 0
'/-> Shut Down Cmd
Act.Run("shutdown.exe -r -f -t 00"),0,true

Here is a HTA the Count Down then runs the reboot cmd

Save As Reboot.hta

<HTML><HEAD>
<HTA:APPLICATION
ID = "CountDown Demo_V1" APPLICATIONNAME = "CountDown Demo_V1"
BORDER = "thick" CAPTION = "Yes"
SHOWINTASKBAR = "Yes" SINGLEINSTANCE = "Yes"
SYSMENU = "Yes" WINDOWSTATE = "normal"
VERSION = "1.2.1" INNERBORDER = "yes"
SELECTION = "yes" MAXIMIZEBUTTON = "No"
MINIMIZEBUTTON = "Yes" NAVIGABLE = "yes"
CONTEXTMENU = "yes" BORDERSTYLE = "normal"
Icon = "%SystemRoot%\Explorer.exe">
<Title>Count Down Demo</Title>
<!-- ================== -->
<!-- BODY STYLE NORMAL-->
<STYLE type="text/css">
Body.Normal
{
font: 10.25pt Verdana;
color:#000080;
font-weight:bold;
filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=0,StartColorStr='#86cceb',endColorStr='#5589ab');
padding-top:1;
padding-bottom:1;
Text-Align:;
}
</STYLE>
<!-- TABLE STYLE NORMAL-->
<STYLE type="text/css">
Table.Normal
{
font: 8.25pt Verdana;
color:#000080;
font-weight:bold;
filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=0,StartColorStr='#E9E9E9',EndColorStr='#9E9E9E');
padding-top:1;
padding-bottom:1;
Text-Align:;
vertical-align:;
}
</STYLE>
<script language="VBScript">
'/-> RESIZE THE HTA WINDOW AND POSSITION IT
window.resizeTo 375,225 : window.moveTo 170,195
Dim Act : Set Act = Createobject("Wscript.Shell")
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim SD : SD = Act.ExpandEnvironmentStrings("%SystemDrive%")
Dim CName : CName = Act.ExpandEnvironmentStrings("%ComputerName%")
'/-> SET THE AMOUNT OF TIME YOU WANT THE SCRIPT TO RUN HERE
Dim CountDown : CountDown = 180
'/-> HTA CAN NOT USE WSCRIPT.SLEEP THIS IS A WORK AROUND
Function Rst1()
Dim Ts : Set Ts = Fso.OpenTextFile(SD & "\Rest1.vbs", 2, true)
Ts.WriteLine "Wscript.sleep 1000" : Ts.close
Act.run(SD & "\Rest1.vbs"), 0 , True : Fso.DeleteFile(SD & "\Rest1.vbs")
End Function

Function StartHta()
Do
CountDown = CountDown - 1
Text1.innerHTML = "Time Left " & chr(187) & Space(2) & CountDown
Text2.innerHTML = "Rebooting This Computer " & chr(187) & Space(2) & CName
Rst1()
Loop Until CountDown = 0
'/-> Shut Down Cmd
Act.Run("shutdown.exe -r -f -t 00"),0,true
window.close()
Exit Function
End Function
</SCRIPT><Center>
<Body Class='Normal' Scroll='No' OnLoad='StartHta'>
<Table Class=Normal Width='250' >
<TD Style='font: 8.25pt Verdana;color:#000080;' Align='Center'>
<Span ID="Text1">Time Left
</Span>
<BR>Processing the script please wait</TD></Table>
<Table Width='350'>
<TD Style='font: 8.25pt Verdana;color:#000080;' Align='Center'><Span Id=Text2> </Span></TD>
</Table>
</Center>

Link to comment
Share on other sites

Great application

but,,

HTA is perfect job,, but the sount down isn't in actual seconds,, it displays the seconds in very slow mannet,,

actual time passes 20 seconds,, but it shows just 10 -12 Sec.

For VBS

the shutdown box flickers.. ( blink blink)

is that a bug

Link to comment
Share on other sites

This code will display "Rebooting in 180 seconds" then add a period on the same line each second :

@echo off
cls
set /p dummy=Rebooting in 180 seconds<nul
for /l %%i in (180,-1,1) do (sleep 1&set /p dummy=.<nul)
shutdown -r -f -t 0

If you want to display less periods, eg. each five seconds, use (two numbers to change) :

for /l %%i in (180,-5,1) do (sleep 5&set /p dummy=.<nul)

I hope this one will display a period each second and the countdown value each ten seconds :

for /l %%i in (18,-1,1) do (for /l %%j in (9,-1,1) do (sleep 1&set /p dummy=.<nul)&sleep 1&set /p dummy=%%i<nul)

++

Link to comment
Share on other sites

The vbs box is refreshen it self every one second

The hta makes a vbs file called Rest1,vbs that has a sleep

function in it. This runs the count down that get displayed.

Here is a redit of the HTA I change the back ground color

I added more comments to it.

<HTML><HEAD>
<HTA:APPLICATION
ID = "CountDown Demo_V1" APPLICATIONNAME = "CountDown Demo_V1"
BORDER = "thin" CAPTION = "Yes"
SHOWINTASKBAR = "Yes" SINGLEINSTANCE = "Yes"
SYSMENU = "Yes" WINDOWSTATE = "normal"
VERSION = "1.2.1" INNERBORDER = "yes"
SELECTION = "yes" MAXIMIZEBUTTON = "No"
MINIMIZEBUTTON = "Yes" NAVIGABLE = "yes"
CONTEXTMENU = "yes" BORDERSTYLE = "normal"
Icon = "%SystemRoot%\Explorer.exe">
<Title>Count Down Demo</Title>
<!-- ================== -->
<!-- BODY STYLE NORMAL-->
<STYLE type="text/css">
Body.Normal
{
font: 10.25pt Verdana;
color:#000080;
font-weight:bold;
filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=0,StartColorStr='#E9E9E9',EndColorStr='#9E9E9E');
padding-top:1;
padding-bottom:1;
Text-Align:;
}
</STYLE>
<!-- TABLE STYLE NORMAL-->
<STYLE type="text/css">
Table.Normal
{
font: 8.25pt Verdana;
color:#000080;
font-weight:bold;
filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=0,StartColorStr='#E9E9E9',EndColorStr='#9E9E9E');
padding-top:1;
padding-bottom:1;
Text-Align:;
vertical-align:;
}
</STYLE>
<script language="VBScript">
'/-> RESIZE THE HTA WINDOW AND POSSITION IT
window.resizeTo 375,225 : window.moveTo 170,195
Dim Act : Set Act = Createobject("Wscript.Shell")
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim SD : SD = Act.ExpandEnvironmentStrings("%SystemDrive%")
Dim CName : CName = Act.ExpandEnvironmentStrings("%ComputerName%")
Dim UName : UName = Act.ExpandEnvironmentStrings("%UserName%")
'/-> SET THE AMOUNT OF TIME YOU WANT THE SCRIPT TO RUN HERE
Dim CountDown : CountDown = 180
'/-> HTA CAN NOT USE WSCRIPT.SLEEP THIS IS A WORK AROUND
Function Rst1()
Dim Ts : Set Ts = Fso.OpenTextFile(SD & "\Rest1.vbs", 2, true)
Ts.WriteLine "Wscript.sleep 940" : Ts.close
End Function
'/-> Start The StartHta Function
Function StartHta()
Rst1()
Do
CountDown = CountDown - 1
'/-> Text Display Here Span Id For Text1, Text2, Text3
Text1.innerHTML = "Time Left " & chr(187) & Space(2) & CountDown
Text2.innerHTML = UName & Space(2) & "Please close any open Programs"
Text3.innerHTML = "Rebooting This Computer " & chr(187) & Space(2) & CName
Act.run(SD & "\Rest1.vbs"), 0 , True
Loop Until CountDown = 0
'/-> Delete The Rest1.vbs
Fso.DeleteFile(SD & "\Rest1.vbs")
'/-> Shut Down Cmd
Act.Run("shutdown.exe -r -f -t 00"),0,true
window.close()
Exit Function
End Function
</SCRIPT></Head><Center>
<Body Class='Normal' Scroll='No' OnLoad='StartHta'>
<Table Class=Normal Width='350' >
<TD Style='font: 8.25pt Verdana;color:#000080;' Align='Center'>
<!-- Span Id Text1 This Line Text1.innerHTML = "Time Left " & chr(187) & Space(2) & CountDown -->
<!-- Change Text Display In Function StartHta() -->
<Span ID="Text1"></Span>
<BR>
<!-- Span Id Text2 This Line Text2.innerHTML = "Please close any open Programs" -->
<!-- Change Text Display In Function StartHta() -->
<Span ID="Text2"></Span></TD></Table>
<Table Width='350'>
<TD Style='font: 8.25pt Verdana;color:#008800;' Align='Center'>
<!-- Span Id Text3 This Line Text3.innerHTML = "Rebooting This Computer " & chr(187) & Space(2) & CName -->
<!-- Change Text Display In Function StartHta() -->
<Span Id=Text3> </Span></TD></Table>
</Center>

Link to comment
Share on other sites

@ Yzöwl

You are the man!

So we just change the count down to our liking. (180 -1 1)

Yes, 180 should represent 180 seconds, i.e. 3 minutes.

The time will actually be a little longer, it may take up to 2 seconds depending upon the system, especially invoked from a cd, to write /create the working files.

I would therefore suggest trying 178 or 179 for a more precise 3 minutes!

Link to comment
Share on other sites

Another optionis to add a comment to the shutdown screen of shutdown.exe where you say that this shutdown procedure is something they don't have to worry about. They should start doing so when the comment field is blank. Just a suggestion though...

shutdown.exe -t xx -c"This is an automated pc shutdown procedure set in motion by the system administrator. If this text is not displayed, save your data and warn the administrator."

Just a suggestion though...

Link to comment
Share on other sites

couple of perfect programs :thumbup

@ Yzöwl

this is what i was looking for...

the program which can be run in DOS mode , no popups at all

but i wonders,

why it isn't giving the perfect time,,

though it is set to 180, but it is more then 4 minutes ( countdown isn't in seconds)

Link to comment
Share on other sites

I've got no definite answer for you, the time should be pretty much spot on. You will never get a precision time piece, due to the fact that things need to be both processed and written to the screen in between the 1 second intervals. My tests have all been within a couple of seconds over the three minute marker. Time it from the moment 180 appears and not from when you execute it. To be a little more brutal, I can see no real need to have an exact time of 3 minutes, I can however see a need to have at least 3 minutes, which is what both our results do give.

Link to comment
Share on other sites

is there any such third party DOS application..

i have found one,, "waiter.com"

it did the perfect job,,

the only disadvantage is that when any of the key is pressed,, it terminates...

Link to comment
Share on other sites

Here is a VBS Script that makes a HTA that countdown then reboots the computer.

This script you can add the amount of time for reboot, plus you can change 2 different

messages.

Here is the Script

Save As MkRebootHTA.vbs

Dim Act   : Set Act = Createobject("Wscript.Shell")
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim DTop, Hta, Msg1, Msg2, Ts, UserMsg1, UserMsg2, UserTime, Vbs
Vbs = Act.ExpandEnvironmentStrings("%Systemdrive%\MkRebootHTA.vbs")
DTop = Act.SpecialFolders("Desktop")
Hta = DTop & "\Reboot.hta"
Msg1 = "Type in the message you want to apprear in the HTA"
Msg2 = "Or press Cancel to use the Default"
Set Ts = Fso.CreateTextFile(Hta)
Function SetRebootTime()
UserTime = InputBox("Type in the time in the amount of seconds you want before Reboot." & vbCrLf &_
Msg2 & ", time of 180 seconds")
If UserTime = "" Then
UserTime = 180
Else
UserTime = UserTime
End If
End Function
Function SetUserMsg1()
UserMsg1 = InputBox(Msg1 & vbCrLf & Msg2 & vbCrLf & "Please save and close any open programs")
If UserMsg1 = "" Then
UserMsg1 = "Please save and close any open programs"
Else
UserMsg1 = UserMsg1
End If
End Function
Function SetUserMsg2()
UserMsg2 = InputBox(Msg1 & vbCrLf & Msg2 & vbCrLf & "Rebooting This Computer")
If UserMsg2 = "" Then
UserMsg2 = "Rebooting This Computer"
Else
UserMsg2 = UserMsg2
End If
End Function
Ts.WriteLine " <HTML><HEAD><HTA:APPLICATION"
Ts.WriteLine " ID = ""Reboot_V1"" APPLICATIONNAME = ""Reboot_V1"""
Ts.WriteLine " BORDER = ""thin"" CAPTION = ""Yes"""
Ts.WriteLine " SHOWINTASKBAR = ""No"" SINGLEINSTANCE = ""Yes"""
Ts.WriteLine " SYSMENU = ""Yes"" WINDOWSTATE = ""normal"""
Ts.WriteLine " VERSION = ""1.1.1"" INNERBORDER = ""yes"""
Ts.WriteLine " SELECTION = ""yes"" MAXIMIZEBUTTON = ""No"""
Ts.WriteLine " MINIMIZEBUTTON = ""No"" NAVIGABLE = ""No"""
Ts.WriteLine " CONTEXTMENU = ""yes"" BORDERSTYLE = ""normal"""
Ts.WriteLine " Icon = ""%SystemRoot%\Explorer.exe""><Title>Reboot The Computer</Title>"
Ts.WriteLine " <STYLE type=""text/css"">"
Ts.WriteLine " Body.Normal"
Ts.WriteLine " {"
Ts.WriteLine " font: 10.25pt Verdana;"
Ts.WriteLine " color:#000080;"
Ts.WriteLine " font-weight:bold;"
Ts.WriteLine " filter:progid:DXImageTransform.Microsoft.Gradient"
Ts.WriteLine " (GradientType=0,StartColorStr='#E9E9E9',EndColorStr='#9E9E9E');"
Ts.WriteLine " padding-top:1;"
Ts.WriteLine " padding-bottom:1;"
Ts.WriteLine " Text-Align:;"
Ts.WriteLine " }"
Ts.WriteLine " Table.Normal"
Ts.WriteLine " {"
Ts.WriteLine " font: 8.25pt Verdana;"
Ts.WriteLine " color:#000080;"
Ts.WriteLine " font-weight:bold;"
Ts.WriteLine " filter:progid:DXImageTransform.Microsoft.Gradient"
Ts.WriteLine " (GradientType=0,StartColorStr='#E9E9E9',EndColorStr='#9E9E9E');"
Ts.WriteLine " padding-top:1;"
Ts.WriteLine " padding-bottom:1;"
Ts.WriteLine " Text-Align:;"
Ts.WriteLine " vertical-align:;"
Ts.WriteLine " }"
Ts.WriteLine " </STYLE>"
Ts.WriteLine " <script language=""VBScript"">"
Ts.WriteLine " window.resizeTo 385,205 : window.moveTo 170,195"
Ts.WriteLine " Dim Act : Set Act = Createobject(""Wscript.Shell"")"
Ts.WriteLine " Dim Fso : Set Fso = CreateObject(""Scripting.FileSystemObject"")"
Ts.WriteLine " Dim CD : CD = Act.CurrentDirectory"
Ts.WriteLine " Dim Hta : Hta = (CD & ""\Reboot.hta"")"
Ts.WriteLine " Dim Rest1 : Rest1 = Act.ExpandEnvironmentStrings(""%SystemDrive%\Rest1.vbs"")"
Ts.WriteLine " Dim CName : CName = Act.ExpandEnvironmentStrings(""%ComputerName%"")"
Ts.WriteLine " Dim UName : UName = Act.ExpandEnvironmentStrings(""%UserName%"")"
SetRebootTime
Ts.WriteLine " Dim CountDown : CountDown = " & UserTime
Ts.WriteLine " Function Rst1()"
Ts.WriteLine " Dim Ts : Set Ts = Fso.OpenTextFile(Rest1, 2, true)"
Ts.WriteLine " Ts.WriteLine ""Wscript.sleep 940"" : Ts.close"
Ts.WriteLine " End Function"
Ts.WriteLine " Function StartHta()"
Ts.WriteLine " Rst1()"
Ts.WriteLine " Do "
Ts.WriteLine " CountDown = CountDown - 1"
Ts.WriteLine " DisplayText()"
Ts.WriteLine " Loop Until CountDown = 0"
Ts.WriteLine " If fso.FileExists(Rest1) Then Fso.DeleteFile(Rest1) End If"
Ts.WriteLine " '/-> Uncomment The Line Below To Delete The HTA If Needed"
Ts.WriteLine " 'If fso.FileExists(Hta) Then Fso.DeleteFile(Hta) End If"
Ts.WriteLine " Act.Run(""shutdown.exe -r -f -t 00""),0,true "
Ts.WriteLine " window.close()"
Ts.WriteLine " Exit Function"
Ts.WriteLine " End Function"
Ts.WriteLine " '/-> Where The Text Is Diaply Script"
Ts.WriteLine " Function DisplayText()"
Ts.WriteLine " Text1.innerHTML = ""Time Left "" & chr(187) & Space(2) &_"
Ts.WriteLine " ""<Font Style='font: 9.25pt Verdana;color:#c34030;'>"" & CountDown & ""</Font>"""
SetUserMsg1
Ts.WriteLine " Text2.innerHTML = UName & ""<BR>" & UserMsg1 & """"
SetUserMsg2
Ts.WriteLine " Text3.innerHTML = ""<B>" & UserMsg2 &_
" </B><BR><Font Style='font: 9.25pt Verdana;color:#4e5052;'><B>"" & chr(187) & Space(2) & CName & ""</Font></B>"""
Ts.WriteLine " Act.run(Rest1), 0 , True"
Ts.WriteLine " Exit Function"
Ts.WriteLine " End Function"
Ts.WriteLine " </SCRIPT></Head><Center>"
Ts.WriteLine " <Body Class='Normal' Scroll='No' OnLoad='StartHta'><Table Class=Normal Width='350' >"
Ts.WriteLine " <TD Style='font: 9.25pt Verdana;color:#000080;' Align='Center'>"
Ts.WriteLine " <Span ID=""Text1""></Span><BR>"
Ts.WriteLine " <Span ID=""Text2""></Span></TD></Table>"
Ts.WriteLine " <Table Width='350'>"
Ts.WriteLine " <TD Style='font: 9.25pt Verdana;color:#206c40;' Align='Center'>"
Ts.WriteLine " <Span Id=Text3> </Span></TD></Table></Center>"
Ts.Close
If Fso.FileExists(Vbs) Then Fso.DeleteFile(Vbs) End If

I have up dated this script MkRebootHta_V1.exe

Edited by gunsmokingman
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...