• 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 -a") >> %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
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.

Link to comment
Share on other sites

  • 0

thanks, unfortunately I don't have access to the users desktops to drop the shortcuts onto and it will be applied through a group policy.

Link to comment
Share on other sites

  • 0

Perhaps this might work better, save as ShutDown.vbx

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

 Act.Run("Shutdown -s -t 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 -a"),1,True
 End If

Link to comment
Share on other sites

  • 0

Perhaps this might work better, save as ShutDown.vbx

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

 Act.Run("Shutdown -s -t 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 -a"),1,True
 End If

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

Link to comment
Share on other sites

  • 0

Save it as a .vbs file (not .vbx - think that's a typo).

Double Click or set-up a scheudled task to run it.

I did start making an app to do something similar, but got distracted by RL stuff... >.>

Link to comment
Share on other sites

  • 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 :(

Link to comment
Share on other sites

  • 0
ShutDown.vbx

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

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 -s -t 1"),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()'>Cancel Shut Down</BUTON>
</TABLE>
</BODY>

Link to comment
Share on other sites

  • 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 -s -t 1"),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!

Link to comment
Share on other sites

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

    • No registered users viewing this page.