• 0

[VBScript] Shutting Down Computers Remotely


Question

Hi guys,

You'll have to bear with me, as my knowledge of VBScript is about as extensive as a morning of looking at a script could be. Thankfully I've worked with other programming languages before, so there is a lot that was understandable.

We have a .vbs file that runs every day at around 19:00 from the server. The basic idea is that it tells each computer in the area to display a message that says, "you have 5 minutes before this computer shuts down," and then it runs the shutdown command in cmd (with the timer set to 5 minutes).

What we would like to do is have the popup message provide an option to stop the shutdown process if the user would prefer to continue working. However, from my research on Google the only way of doing this appears to be by having a second .vbs script on the local machine that will present a separate popup box.

Is there a way of doing this without having a .vbs script on each machine? If it is possible and someone has a link to the relevant information then that would be greatly appreciated.

EDIT: Continuing my research, it appears that you need to have admin privileges to run the .vbs script on the local machine. This is going to be a problem, as not everyone is an admin (for obvious reasons :laugh:).

Link to comment
Share on other sites

19 answers to this question

Recommended Posts

  • 0

The pop-up is provided by the shutdown command on the local machine.

There is no way to call a shutdown that has an offer of cancelling.

You stop the shutdown with "shutdown -a" in command.

Link to comment
Share on other sites

  • 0

The pop-up is provided by the shutdown command on the local machine.

There is no way to call a shutdown that has an offer of cancelling.

You stop the shutdown with "shutdown -a" in command.

Yeah, I read that and knew about the command, but it's not a viable solution for us.

However, I found this script (EDIT: Whoops, I meant the second script, not the OP's script) which (if I'm understanding it right) presents the user with a popup box before running the shut down command. If the user doesn't respond in 20 seconds then the shutdown command is run. But as I said, this script requires that it be run on the local machine, and I think the user also needs admin rights, which isn't going to work either.

...I think I'm looking for something that just isn't possible, aren't I? :(

Link to comment
Share on other sites

  • 0

If I was going to do it, I would add the script via group policy to execute locally and assign the watcher thread admin privileges, which is easy enough to do >.<

Is this possible for you?

Link to comment
Share on other sites

  • 0

It's easier than that. We do it here. let me take a loot to remember how I did it.

Damn it. I forgot the MSA failed this morning so I can't get to my scripts till HP replace it.

I think it went like this.

Scheduled task executes script 1 at 11pm

Script 1 with user level privileges.

check for noreboot.txt

if found delete noreboot.txt

prompt user computer will shutdown at 00:00. do you want to cancel?

If user cancels, create noreboot.txt.

Scheduled task executes script 2 at 00:00

Script 2 with admin level privileges.

Check for noreboot.txt

if not found, shut down pc

All setup through group policy but it's easy to do manually.

Link to comment
Share on other sites

  • 0

We think we've found a way around the problem. We're just going to wait until the end of the day to try it, that way if it doesn't work we're not going to be causing anyone (or at least, as few people as possible) problems.

That said, MarkusDarkus's idea sounds like a decent alternative for if this fails. It's always good to have a backup plan. (Y)

Link to comment
Share on other sites

  • 0

He just said what I said :o

:\

BALLS!

Well then thank you to both of you for an alternative plan, should ours fail. :D

Link to comment
Share on other sites

  • 0

He just said what I said :o

:\

BALLS!

I know but I thought I'd spell it out. And also the fact that I said that's what we already do here would help build confidence in our method.

Link to comment
Share on other sites

  • 0

Have you thought of using a HTA for a shutdown dialog with a cancel button.

ShutDownHta.png

I made this a while ago for someone else and thought that it might help you solve your problem.

ShutDownGui.hta

&lt;TITLE&gt;Shut Down Gui&lt;/TITLE&gt;
&lt;!-- 
Coded By Jake1Eye Aka Gunsmokingman 11:08 PM August-31-10
--&gt;
&lt;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"&gt;
 &lt;STYLE Type='text/css'&gt;
   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')
    }
&lt;/STYLE&gt;
  &lt;script LANGUAGE='VBScript'&gt;
'-&gt; 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 &lt; "100%" Or bar.style.width &gt; "0%" Then
      BarSize(C1)
     Else
      BarSize(C1)
     End If
     C1 = C1 - 1
    End If 
   idTimer = window.setTimeout("DemoSelf", 1000, "VBScript")   
  End Function
'-&gt; Resize The Bar
  Function BarSize(N)
   If N &gt; 1 Then
     document.title = FormatPercent(N / 300 ,2)
   End If 
   bar.style.width = n * 1 
  End Function
  Function TextDsp(NM)
   Txt.innerHTML= NM &amp; " Seconds Remaining"
  End Function
  &lt;/SCRIPT&gt;
 &lt;BODY Scroll='No'&gt;
  &lt;TABLE&gt;Shut Down Computer&lt;/TABLE&gt;
  &lt;TABLE Style='Margin:3pt;'&gt;
   &lt;TD&gt;&lt;DIV ID='Txt1' Style='Font-Size:8.25pt;Font-Family:Lucida Console;Font-Weight:Bold;Color:#000047;'&gt;
   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.&lt;/DIV&gt;&lt;/TD&gt;
 &lt;/TABLE&gt;  
 &lt;DIV Align='Left' Style="Width:226pt;Border-width:1;Border-style:solid;Border-color:#BBBBBB;Font-size:9.25pt"&gt;
&lt;!-- Position The Text In The Bar Graph Area --&gt;
  &lt;SPAN ID="bar" Class='pgbar'&gt;&lt;/SPAN&gt;
  &lt;SPAN ID="Txt" Style='Position:Absolute;Top:99;Left:88;Font-Family:Lucida Console;Font-Weight:Bold;Color:#003434;'&gt;&lt;/SPAN&gt;
 &lt;/DIV&gt;
&lt;!-- Cancel Shut Down --&gt;
&lt;TABLE Style='Margin-Top:5pt;'&gt;
 &lt;BUTTOn ONClick='window.close()'&gt;Cancel Shut Down&lt;/BUTON&gt;
&lt;/TABLE&gt;
&lt;/BODY&gt;

ShutDownGui.zip

Link to comment
Share on other sites

  • 0

Have you thought of using a HTA for a shutdown dialog with a cancel button.

ShutDownHta.png

I made this a while ago for someone else and thought that it might help you solve your problem.

:blink:

That is magic! I'll pass it on and see what the team says. (Y)

Link to comment
Share on other sites

  • 0

Here is an updated version of the HTA, thank you to those who downloaded this.

Displays The Minutes Ans Seconds Counting Up while the graph shrinks in size.

Made a 5 minute and 10 minute version, graph is scaled to each Counter

Shut Down Gui v2

<TITLE>Shut Down Gui</TITLE>
<!-- 
  Coded By Jake1Eye Aka Gunsmokingman 3:27 PM February-11-14
-->
<HTA:APPLICATION 
     Id="SDGuiv2" 
     APPLICATIONNAME="ShutDownGuiv2"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="Normal"
     SELECTION="NO"
     CONTEXTMENU = "NO"
     BORDER="Thin"
     BORDERStyle = "Normal"
     INNERBORDER = "YES"
     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:#EFE9E3;
     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 
    {width:300pt;
     filter:progid:DXImageTransform.Microsoft.Gradient
     (GradientType=0,StartColorStr='#44DC88',endColorStr='#005a00')
    }
</STYLE>
  <script LANGUAGE='VBScript'>
'-> Varibles Used At Runtime
  Dim C1, C2, C3, Tmr   
  Function Window_OnLoad()
   self.Focus
   self.resizeTo 400,187
   self.MoveTo screen.availWidth / 2 - 400/2,screen.availHeight / 2 -187/2
   DemoSelf()
 End Function
'-> Function For The Counter 
  Function DemoSelf()
   If C1 Mod 60 Then
    C2 = C2 + 1
   Else
    C3 = C3 + 1 
    C2 = 0
   End If 
   C1 = C1 + 1
   If C3 = 0 Then C3 = AddZero("0")
   IF C1 = 300 Then 
'-> Shut Down Command At 300 Seconds Or 5 Minutes
    CreateObject("Wscript.Shell").Run("Shutdown -s -t 1 -f"),0,True
    window.close()
   End If 
    Txt.innerHTML= "Minute: "  & AddZero(C3-1)& " Seconds: "   & AddZero(C2)
    BarSize(int("300") - int(C1))
   Tmr = window.setTimeout("DemoSelf", 1000, "VBScript") 
  End Function
'-> Resize The Bar
  Function BarSize(N)
   If N > 1 Then document.title = "% Of Time Left : " & FormatPercent(N / 300 ,2)
   bar.style.width = N * 1 
  End Function
'-> Add Zero To Display Numbers
  Function AddZero(n)
   If Len(n)=1 Then n="0"&n
   AddZero=n
  End Function
  </SCRIPT>
 <BODY><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 05 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 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;Size:7.25pt;'></SPAN>
 </DIV>
<!-- Cancel Shut Down -->
<TABLE Style='Margin-Top:5pt;'>
 <BUTTOn ONClick='window.clearInterval(Tmr): window.close()'>Cancel Shut Down</BUTON>
</TABLE>
</BODY>
ShutdownGuiV2.zip

post-25092-0-99900200-1392162111.png

Shut Down Gui v3

<TITLE>Shut Down Gui</TITLE>
<!-- 
  Coded By Jake1Eye Aka Gunsmokingman 3:32 PM February-11-14
-->
<HTA:APPLICATION 
     Id="SDGuiv3" 
     APPLICATIONNAME="ShutDownGuiv3"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="Normal"
     SELECTION="NO"
     CONTEXTMENU = "NO"
     BORDER="Thin"
     BORDERStyle = "Normal"
     INNERBORDER = "YES"
     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:#EFE9E3;
     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 
    {width:300pt;
     filter:progid:DXImageTransform.Microsoft.Gradient
     (GradientType=0,StartColorStr='#44DC88',endColorStr='#005a00')
    }
</STYLE>
  <script LANGUAGE='VBScript'>
'-> Varibles Used At Runtime
  Dim C1, C2, C3, Tmr   
  Function Window_OnLoad()
   self.Focus
   self.resizeTo 400,187
   self.MoveTo screen.availWidth / 2 - 400/2,screen.availHeight / 2 -187/2
   DemoSelf()
 End Function
'-> Function For The Counter 
  Function DemoSelf()
   If C1 Mod 60 Then
    C2 = C2 + 1
   Else
    C3 = C3 + 1 
    C2 = 0
   End If 
   C1 = C1 + 1
   If C3 = 0 Then C3 = AddZero("0")
   IF C1 = 600 Then 
'-> Shut Down Command At 600 Seconds Or 10 Minutes
     CreateObject("Wscript.Shell").Run("Shutdown -s -t 0 -f"),0,True
     window.close()
   End If 
   Txt.innerHTML= "Minute: "  & AddZero(C3-1)& " Seconds: "   & AddZero(C2)
   BarSize(int("300") - int(C1/2))
   Tmr = window.setTimeout("DemoSelf", 1000, "VBScript") 
  End Function
'-> Resize The Bar
  Function BarSize(N)
   If N > 1 Then document.title = "% Of Time Left : " & FormatPercent(N / 300 ,2)
   bar.style.width = N * 1 
  End Function
'-> Add Zero To Display Numbers
  Function AddZero(n)
   If Len(n)=1 Then n="0"&n
   AddZero=n
  End Function
  </SCRIPT>
 <BODY><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 10 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 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;Size:7.25pt;'></SPAN>
 </DIV>
<!-- Cancel Shut Down -->
<TABLE Style='Margin-Top:5pt;'>
 <BUTTOn ONClick='window.clearInterval(Tmr): window.close()'>Cancel Shut Down</BUTON>
</TABLE>
</BODY>
ShutdownGuiV3.zip

post-25092-0-99949900-1392162502.png

Link to comment
Share on other sites

  • 0

1:\ I am Dxylexic

2:\ This forum is for coding and not English Assignments, perhaps your comment belongs in the Proper English Assignment Forum

of this board, if they had one.

Link to comment
Share on other sites

  • 0

Just trying to help pal, don't get your panties in a bunch. :p

Fair enough but

1:\ Thread plus 2400 reads

2:\ 100 or so downloads

3:\ My original post is almost 3 years old

Your the only one who mention the grammar, it a template meant to be changed. I just

as easily could coded it this way.

post-25092-0-26014600-1392324352.png

Link to comment
Share on other sites

  • 0

Code change for DemoSelf() function. You will have to make these changes manually.

10 minute hta

Old

'-> Function For The Counter 
  Function DemoSelf()
   If C1 Mod 60 Then
    C2 = C2 + 1
   Else
    C3 = C3 + 1 
    C2 = 0
   End If 
   C1 = C1 + 1
   If C3 = 0 Then C3 = AddZero("0")
   IF C1 = 600 Then 
'-> Shut Down Command At 600 Seconds Or 10 Minutes
     CreateObject("Wscript.Shell").Run("Shutdown -s -t 0 -f"),0,True
     window.close()
   End If 
   Txt.innerHTML= "Minute: "  & AddZero(C3-1)& " Seconds: "   & AddZero(C2)
   BarSize(int("300") - int(C1/2))
   Tmr = window.setTimeout("DemoSelf", 1000, "VBScript") 
  End Function
New

'-> Function For The Counter 
  Function DemoSelf()
   C3 = C3 + 1 :C1 = C1 + 1
   If C1 = 60 Then
    C2 = C2 + 1
    C1 = 0
   End If 
   If C2 = 0 Then C2 = AddZero("0")
   IF C2 = 10 Then 
'-> Shut Down Command At 600 Seconds Or 10 Minutes, C3 = 600
     CreateObject("Wscript.Shell").Run("Shutdown -s -t 0 -f"),0,True
     window.close()
   End If 
   Txt.innerHTML= "Minute: "  & AddZero(C2)& " Seconds: "   & AddZero(C1)
   BarSize(int("300") - int(C3/2))
   Tmr = window.setTimeout("DemoSelf", 1000, "VBScript") 
  End Function
5 minute hta

Old

'-> Function For The Counter 
  Function DemoSelf()
   If C1 Mod 60 Then
    C2 = C2 + 1
   Else
    C3 = C3 + 1 
    C2 = 0
   End If 
   C1 = C1 + 1
   If C3 = 0 Then C3 = AddZero("0")
   IF C1 = 300 Then 
'-> Shut Down Command At 300 Seconds Or 5 Minutes
    CreateObject("Wscript.Shell").Run("Shutdown -s -t 1 -f"),0,True
    window.close()
   End If 
    Txt.innerHTML= "Minute: "  & AddZero(C3-1)& " Seconds: "   & AddZero(C2)
    BarSize(int("300") - int(C1))
   Tmr = window.setTimeout("DemoSelf", 1000, "VBScript") 
  End Function
New

'-> Function For The Counter 
  Function DemoSelf()
   C3 = C3 + 1 :C1 = C1 + 1
   If C1 = 60 Then
    C2 = C2 + 1
    C1 = 0
   End If 
   If C2 = 0 Then C2 = AddZero("0")
   IF C2 = 5 Then 
'-> Shut Down Command At 300 Seconds Or 5 Minutes C3 = 300
    CreateObject("Wscript.Shell").Run("Shutdown -s -t 1 -f"),0,True
    window.close()
   End If 
    Txt.innerHTML= "Minute: "  & AddZero(C2)& " Seconds: "   & AddZero(C1)
    BarSize(int("300") - int(C3))
   Tmr = window.setTimeout("DemoSelf", 1000, "VBScript") 
  End Function
Link to comment
Share on other sites

  • 0

hi

i am trying to run the hta script 

created the task as domain\administrator in the built in task scheduler works for the administrator

but if other user is logged in (it is a meeting room computer any domain user can use it) the window is not visible. after 5 minutes the computer indeed shuts down.

 

tried to use "system scheduler" (http://www.splinterware.com/index.htm) works for the administrator.

when other user is logged on he can see the window and can cancel the shut down but when the counter ends the window closes and the computer is not shutting down.

 

any ideas?

 

thanks

Amir

Link to comment
Share on other sites

  • 0

OK i got it to work

needed permission on shutdown.exe

and added domain users group to local administrators group so they can initiate the shutdown command

 

now comes another problem....

i want the computer to shut down even if no user is logged in.

is it possible?

 

thank you

it is  a nice script

Link to comment
Share on other sites

  • 0

OK i got it to work

needed permission on shutdown.exe

and added domain users group to local administrators group so they can initiate the shutdown command

 

now comes another problem....

i want the computer to shut down even if no user is logged in.

is it possible?

 

thank you

it is  a nice script

That's not possible, a script can only be run by a user which requires that user to be logged in.

You can use a hidden logged in account that works in the background of the login screen in your case.

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.