• 0

shut down script


Question

I am currently trying to write a script that will shut down a XP based computer at a certain time to save energy by preventing it being left on overnight. However I don't want it to force a shut down if the computer is still in use so a button to cancel would be required. Now I have absolutely no clue when it comes to programming / writing scripts, so what I currently have is all sourced from google.

This is what I have

@Shutdown -s -t 300 -c "This Computer will shut down in 5 minutes to save energy. If you are currently working please click yes on the abort window to cancel"

@echo off

echo Set objshell = CreateObject("wscript.shell") > %temp%\abort.vbs

echo strAnswer = MsgBox("abort shutdown ?",vbYesNo) >> %temp%\abort.vbs

echo If strAnswer = 6 Then >> %temp%\abort.vbs

echo objshell.Run("shutdown >> %temp%\abort.vbs

echo End if >> %temp%\abort.vbs

%temp%\abort.vbs

However my problem is that the pop-up with the abort yes/ no buttons appears directly behind the shut down timer so wont be seen. How can I customise this to move the box lower or place it on top. The command prompt also appears, so it would look neater to hide this also but no essential .

Thanks.

Link to comment
https://www.neowin.net/forum/topic/934084-shut-down-script/
Share on other sites

13 answers to this question

Recommended Posts

  • 0

You could just make two desktop shortcuts

First One - Starts the shutdown

%windir%\system32\shutdown.exe -r -c "Rebooting For Fun"

Second One - This aborts the shutdown

%windir%\system32\shutdown.exe -a -c "Shutdown Cancelled"

Seems easier than a entire script, you could then set the first one on a schedule.

  • 0

Perhaps this might work better, save as ShutDown.vbx

 Dim Act :Set Act = CreateObject("Wscript.Shell")

 Act.Run("Shutdownt 300 -c " & Chr(34) & "This Computer will shut down in 5 minutes to save energy." & _
 "If you are currently working please click yes on the abort window to cancel" & Chr(34))

 If MsgBox("Press Yes To Stop Shut Down" ,4132,"Stop Shut Down") = 6 Then
  Act.Run("shutdown,1,True
 End If

  • 0
  On 31/08/2010 at 16:37, jake1eye said:

Perhaps this might work better, save as ShutDown.vbx

 Dim Act :Set Act = CreateObject("Wscript.Shell")

 Act.Run("Shutdownt 300 -c " & Chr(34) & "This Computer will shut down in 5 minutes to save energy." & _
 "If you are currently working please click yes on the abort window to cancel" & Chr(34))

 If MsgBox("Press Yes To Stop Shut Down" ,4132,"Stop Shut Down") = 6 Then
  Act.Run("shutdown,1,True
 End If

Thanks for that. How do I get it to run?

  • 0

thanks yea must have been a typo. the code doesn't work either, it brings the timed shutdown up with the yes no box but the yes to cancel button doesn't do anything and then the pc restarts rather than shuts down :(

  • 0
  Quote
ShutDown.vbx

This was a typo error ShutDown.vbx it should be ShutDown.vbs

  Quote

thanks yea must have been a typo. the code doesn't work either, it brings the timed shutdown up with the yes no box but the yes to cancel button doesn't do anything and then the pc restarts rather than shuts down

I tested the code on Windows 7 and it worked correct.

Before Yes Selected

Logoff1.png

After Yes Selected

Logoff2.png

I was bored and I made a HTA for a GUI for the shutdown, I tested on Windows 7 and it works correct.

Save As ShutDownGui.hta

ShutDownGui.png

<TITLE>Shut Down Gui</TITLE>
<!-- 
Coded By Jake1Eye Aka Gunsmokingman 11:08 PM August-31-10
-->
<HTA:APPLICATION 
     Id="SDGui" 
     APPLICATIONNAME="ShutDownGui"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="minimize"
     SELECTION="NO"
     CONTEXTMENU = "NO"
     BORDER="Thin"
     BORDERStyle = "Normal"
     INNERBORDER = "YES"
     NOWRAP
     MAXIMIZEBUTTON = "NO"
     MINIMIZEBUTTON = "NO"
     SYSMENU = "NO">
 <STYLE Type='text/css'>
   Body
    {
     Font-Size:9.75pt;
     Font-Weight:Bold;
     Font-Family:Arial,Tahoma,Comic Sans MS,Segoe Ui;
     Color:#203063;
     BackGround-Color:Transparent;
     Filter:progid:DXImageTransform.Microsoft.Gradient
     (StartColorStr='#ece6e0',endColorStr='#c0bab4');
     Margin-Top:5;
     Margin-Bottom:5;
     Margin-Left:2;
     Margin-Right:2;
     Padding-Top:5;
     Padding-Bottom:5;
     Padding-Left:2;
     Padding-Right:2;
     Text-Align:Center;
     Vertical-Align:Top;
     Border-Top:2px Solid #dbd5d1;
     Border-Bottom:4px Solid #c6c1ba;
     Border-Left:2px Solid #c1bdb9;
     Border-Right:3px Solid #d7d1cb;
    }
   BUTTON 
    {
     Cursor:Hand;
     Font-Size:8.25pt;
     Font-Weight:Bold;
     Color:#001141;
     Filter:progid:DXImageTransform.Microsoft.Gradient
     (StartColorStr='AliceBlue',endColorStr='LightSlateGray');
     Border-Top:0px Transparent;
     Border-Bottom:0px Transparent;
     Border-Left:0px Transparent;
     Border-Right:0px Transparent;
    }
   .pgbar 
    {
     filter:progid:DXImageTransform.Microsoft.Gradient
     (GradientType=0,StartColorStr='#44DC88',endColorStr='#005a00')
    }
</STYLE>
  <script LANGUAGE='VBScript'>
'-> Controls The Loop Count
  Dim C1 :C1 = 300  
  Function Window_OnLoad()
   self.Focus
   self.resizeTo 400,187
   self.MoveTo screen.availWidth / 2 - 400/2,screen.availHeight / 2 -187/2
   bar.style.width = "100%"
   DemoSelf()
  End Function
  Function DemoSelf()
   If C1 = 0 Then
     CreateObject("Wscript.Shell").Run("Shutdown,0,True
     window.close()
    Else
     TextDsp(C1) 
     If Not bar.style.width < "100%" Or bar.style.width > "0%" Then
      BarSize(C1)
     Else
      BarSize(C1)
     End If
     C1 = C1 - 1
    End If 
   idTimer = window.setTimeout("DemoSelf", 1000, "VBScript")   
  End Function
'-> Resize The Bar
  Function BarSize(N)
   If N > 1 Then
     document.title = FormatPercent(N / 300 ,2)
   End If 
   bar.style.width = n * 1 
  End Function
  Function TextDsp(NM)
   Txt.innerHTML= NM & " Seconds Remaining"
  End Function
  </SCRIPT>
 <BODY Scroll='No'>
  <TABLE>Shut Down Computer</TABLE>
  <TABLE Style='Margin:3pt;'>
   <TD><DIV ID='Txt1' Style='Font-Size:8.25pt;Font-Family:Lucida Console;Font-Weight:Bold;Color:#000047;'>
   In Aproxementy 5 Minutes Or When The Green Graph Is Gone This Computer Will Be Shut Down. 
   Save All Open Work Files Or Documents, Before Shut Down Occors. To Cancel The Shut Down
   Press The Cancel Shut Down Button.</DIV></TD>
 </TABLE>  
 <DIV Align='Left' Style="Width:226pt;Border-width:1;Border-style:solid;Border-color:#BBBBBB;Font-size:9.25pt">
<!-- Position The Text In The Bar Graph Area -->
  <SPAN ID="bar" Class='pgbar'></SPAN>
  <SPAN ID="Txt" Style='Position:Absolute;Top:99;Left:88;Font-Family:Lucida Console;Font-Weight:Bold;Color:#003434;'></SPAN>
 </DIV>
<!-- Cancel Shut Down -->
<TABLE Style='Margin-Top:5pt;'>
 <BUTTOn ONClick='window.close()'>Cancelt Down</BUTON>
</TABLE>
</BODY>

  • 0

I've tested it and seems to work great: With apologies to the origional coder here is the same thing with a few changes and spelling corrections.


<TITLE>Shut Down Gui</TITLE>
<!--
Coded By Jake1Eye Aka Gunsmokingman 11:08 PM August-31-10
-->
<HTA:APPLICATION
Id="SDGui"
APPLICATIONNAME="ShutDownGui"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="minimize"
SELECTION="NO"
CONTEXTMENU = "NO"
BORDER="Thin"
BORDERStyle = "Normal"
INNERBORDER = "YES"
NOWRAP
MAXIMIZEBUTTON = "NO"
MINIMIZEBUTTON = "NO"
SYSMENU = "NO">
<STYLE Type='text/css'>
Body
{
Font-Size:9.75pt;
Font-Weight:Bold;
Font-Family:Arial,Tahoma,Comic Sans MS,Segoe Ui;
Color:#203063;
BackGround-Color:Transparent;
Filter:progid:DXImageTransform.Microsoft.Gradient
(StartColorStr='#ece6e0',endColorStr='#c0bab4');
Margin-Top:5;
Margin-Bottom:5;
Margin-Left:2;
Margin-Right:2;
Padding-Top:5;
Padding-Bottom:5;
Padding-Left:2;
Padding-Right:2;
Text-Align:Center;
Vertical-Align:Top;
Border-Top:2px Solid #dbd5d1;
Border-Bottom:4px Solid #c6c1ba;
Border-Left:2px Solid #c1bdb9;
Border-Right:3px Solid #d7d1cb;
}
BUTTON
{
Cursor:Hand;
Font-Size:8.25pt;
Font-Weight:Bold;
Color:#001141;
Filter:progid:DXImageTransform.Microsoft.Gradient
(StartColorStr='AliceBlue',endColorStr='LightSlateGray');
Border-Top:0px Transparent;
Border-Bottom:0px Transparent;
Border-Left:0px Transparent;
Border-Right:0px Transparent;
}
.pgbar
{
filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=0,StartColorStr='#44DC88',endColorStr='#005a00')
}
</STYLE>
<script LANGUAGE='VBScript'>
'-> Controls The Loop Count
Dim C1 :C1 = 60
Function Window_OnLoad()
self.Focus
self.resizeTo 400,187
self.MoveTo screen.availWidth / 2 - 400/2,screen.availHeight / 2 -187/2
bar.style.width = "100%"
DemoSelf()
End Function
Function DemoSelf()
If C1 = 0 Then
CreateObject("Wscript.Shell").Run("Shutdown,0,True
window.close()
Else
TextDsp(C1)
If Not bar.style.width < "100%" Or bar.style.width > "0%" Then
BarSize(C1)
Else
BarSize(C1)
End If
C1 = C1 - 1
End If
idTimer = window.setTimeout("DemoSelf", 1000, "VBScript")
End Function
'-> Resize The Bar
Function BarSize(N)
If N > 1 Then
document.title = FormatPercent(N / 300 ,2)
End If
bar.style.width = n * 1
End Function
Function TextDsp(NM)
Txt.innerHTML= NM & " Seconds Remaining"
End Function
</SCRIPT>
<BODY Scroll='No'>
<TABLE>Shut Down Computer</TABLE>
<TABLE Style='Margin:3pt;'>
<TD><DIV ID='Txt1' Style='Font-Size:8.25pt;Font-Family:Lucida Console;Font-Weight:Bold;Color:#000047;'>
In Approximately 60 Seconds Or When The Green Graph Is Gone, This Computer Will Be Shut Down.
Save All Open Work Files Or Documents, Before Shut Down Occurs. To Cancel The Shut Down
Press The Cancel Shut Down Button.</DIV></TD>
</TABLE>
<DIV Align='Left' Style="Width:226pt;Border-width:1;Border-style:solid;Border-color:#BBBBBB;Font-size:9.25pt">
<!-- Position The Text In The Bar Graph Area -->
<SPAN ID="bar" Class='pgbar'></SPAN>
<SPAN ID="Txt" Style='Position:Absolute;Top:99;Left:88;Font-Family:Lucida Console;Font-Weight:Bold;Color:#003434;'></SPAN>
</DIV>
<!-- Cancel Shut Down -->
<TABLE Style='Margin-Top:5pt;'>
<BUTTON ONClick='window.close()'>Cancel Shut Down</BUTTON>
</TABLE>
</BODY>
[/CODE]

Also a holy thread revival Batman!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • they will use your data anyways, this way you at least get to take advantage of it, might as well use it
    • I think its a great thing, whoever messes with my msgs is going to be real bored. Even those who dont trust meta, like myself, if the gains translate into an improved communication, easiness, everyone will use it. The alternative is not use Meta Whatsapp since they will AI your msgs an resume it anyways
    • Write-Host “Initiate porno mode!” -ForegroundColor Red Read-Host “Press the any key to continue” Save as “PornoMode.ps1
    • The so called tri-fold phone is not a phone just like today's so called smartphones are not phones. They are computing camera devices with the ability to make and receive phone calls. For many the phone app is among the least used apps on these so called smartphones.
    • Backpack Hero and Figment are free to claim on the Epic Games Store by Pulasthi Ariyasinghe The Epic Games Store has just refreshed its weekly giveaways promotion, and there are two games up for grabs this time. Replacing the Sable freebie from last week, Backpack Hero and Figment have now landed for all PC gamers to claim. As always, you have seven days to add the latest indie game permanently to your Epic Games Store library. From the double giveaway, Backpack Hero comes in from indie developer Jaspel, offering a unique inventory management roguelike experience. Aside from collecting items to maximize the potential of a run, like with other roguelikes, here, your placement of the item in the backpack also matters. Each run offers randomly generated dungeons, enemies, and loot to grab. Next, Figment lands from Bedtime Digital Games. This isometric perspective action adventure game takes place in a surreal landscape with hand-drawn artwork, and everything is taking place inside a mind. You take the role of Dusty, the former voice of courage in the mind. The musical adventure involves trying to return Dusty to his old self while also helping the mind beat back its nightmares and restoring its original purpose. The Figment and Backpack Hero giveaways on the Epic Games Store are now active, and they will last until July 10. When not on sale, both games come in at $19.99 to purchase, but PC gamers can add the duo to their library for no cost during the seven-day timeframe. When the giveaways refresh next week, Epic Games plans on giving away two more games: the next musical adventure, Figment 2: Creed Valley, as well as the classic arcade-inspired shoot’em up Sky Racket.
  • Recent Achievements

    • Week One Done
      Devesh Beri earned a badge
      Week One Done
    • Week One Done
      956400 earned a badge
      Week One Done
    • First Post
      loose_observer earned a badge
      First Post
    • Week One Done
      BeeJay_Balu earned a badge
      Week One Done
    • Week One Done
      filminutz earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      454
    2. 2
      ATLien_0
      158
    3. 3
      +FloatingFatMan
      152
    4. 4
      Nick H.
      65
    5. 5
      +thexfile
      62
  • Tell a friend

    Love Neowin? Tell a friend!