Jump to content



Photo

shut down script


  • Please log in to reply
13 replies to this topic

#1 anthdci

anthdci

    Neowinian

  • Joined: 20-November 09
  • Location: Sunderland, UK

Posted 31 August 2010 - 09:36

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.


#2 Lilrich

Lilrich

    Apple Fan-Boi

  • Joined: 31-October 06

Posted 31 August 2010 - 09:52

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.

#3 OP anthdci

anthdci

    Neowinian

  • Joined: 20-November 09
  • Location: Sunderland, UK

Posted 31 August 2010 - 10:12

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.

#4 Kami-

Kami-

    ♫ d(-_-)b ♫

  • Tech Issues Solved: 2
  • Joined: 28-July 08
  • Location: SandBox

Posted 31 August 2010 - 11:23

I'll send you something later today that'll do this... :)

#5 jake1eye

jake1eye

    Neowinian

  • Joined: 02-April 03
  • Location: New Westminster

Posted 31 August 2010 - 16:37

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


#6 OP anthdci

anthdci

    Neowinian

  • Joined: 20-November 09
  • Location: Sunderland, UK

Posted 01 September 2010 - 08:20

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?

#7 Kami-

Kami-

    ♫ d(-_-)b ♫

  • Tech Issues Solved: 2
  • Joined: 28-July 08
  • Location: SandBox

Posted 01 September 2010 - 11:47

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

#8 OP anthdci

anthdci

    Neowinian

  • Joined: 20-November 09
  • Location: Sunderland, UK

Posted 01 September 2010 - 12:52

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

#9 jake1eye

jake1eye

    Neowinian

  • Joined: 02-April 03
  • Location: New Westminster

Posted 01 September 2010 - 16:13

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
Posted Image
After Yes Selected
Posted Image

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
Posted Image
<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>


#10 OP anthdci

anthdci

    Neowinian

  • Joined: 20-November 09
  • Location: Sunderland, UK

Posted 02 September 2010 - 09:51

jake you are an absolute hero! I wish I could code like that.

#11 jake1eye

jake1eye

    Neowinian

  • Joined: 02-April 03
  • Location: New Westminster

Posted 02 September 2010 - 16:07

jake you are an absolute hero! I wish I could code like that.

Your welcome, glad I could help.

#12 jimmy682

jimmy682

    Resident One Post Wonder

  • Joined: 01-December 12

Posted 01 December 2012 - 11:05

Jake or anyone, which lines do I need to change to make the countdown 60 seconds?

Thanks,
Jimmy

#13 Farstrider

Farstrider

    The Clash

  • Joined: 16-March 03
  • Location: Somerset West, Cape Town, SA
  • OS: Arch Linux

Posted 01 December 2012 - 12:25

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>

Also a holy thread revival Batman!

#14 jake1eye

jake1eye

    Neowinian

  • Joined: 02-April 03
  • Location: New Westminster

Posted 01 December 2012 - 19:19

Thank you for the spelling corrections.