Home > VBScript > VBScript – Poor Man’s “Energy Consumption Reducer”

VBScript – Poor Man’s “Energy Consumption Reducer”


***Critical Note***  This is to be used this at your own risk and this is not a supported solution.  This includes a framework to provide a solution – you as the IT Professional are responsible for making the appropriate changes to the script and determining any deployment methods if any.  Remember – this will shutdown a device without user intervention.
 
Overview
So the back story on this one is that the company I work for has a couple things going on that need attention and this "Green" idea came from a coworker of mine.  So I took the concept and developed the script and did a business case (still pending approval).  I am not saying that this is better than anything else out there and I certainly do not put any claims on how much energy this could save – I just like the branding and control I have with it (at MMS last year Microsoft discussed that users tend to be more responsive to alerts or deployments that have your company logo).
 

List of things that took me down this path:

  1. We use SCCM to deploy software updates and some users, let’s say 1%-3% of them, were getting frustrated with the "Mandatory" installs and reboots (this is not a very large number but their titles make it high profile)
  2. We need to enforce reboots after the software updates because the Windows Installer will hold the rebooting pending and other deployments will fail
  3. Users complain that they do not get an alert for the install or the reboot (not likely because the balloons are enabled but the customer is always right)
  4. Although we tell the users that they should log off each night they do not so we cannot expect them to do the reboots and have them supressed in SCCM Software Updates

Proposed Solution
I devloped the script and HTA below that executes a shutdown (long-term the devices can be started back up by the End-User, Wake-On-LAN, or ideally Intel AMT).  The script calls the HTA if it is executed within the specified window.  If it does fall in the window then the HTA, with the company logo, is launched and the End-User is prompted with a 30 minutes countdown and a way to stop the shutdown or speed it up.

We use this with SCCM and have it published to run from the DP vs. chached so if a user is not on the internal network it does not run.  At this point we are still in Mixed Mode so IBCM is not a factor.

There is a folder structure that you will need to have which is outlined below:

  • File: WindowsClientShutdown.HTA
  • File: WindowsClientShutdown.VBS
  • Folder: Images
  • File: ImagesCOMPANY_LOGO.gif
  • File: Imageswinicon.ico

WindowsClientShutdown.VBS
(***NOTE***  The specified windows can be modified in the script by changing the "strStart" and "strEnd" variables.)

*************************************************************************
option explicit

‘————————————————–
‘Set Variables
‘————————————————–
Dim strDirectory, strFileName, WshShell, objFSO, objShell, objTextFile, strProgramFiles, strStartup, objWMIService
Dim colComputer, strComputer, objComputer, strLogonUser, objNetwork, strCurrentDir, strStart, strEnd

Set WshShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objShell = CreateObject("WScript.Shell")

strComputer = "."
strCurrentDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "")

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

strStart = "08:00:00 PM"
strEnd = "08:30:00 PM"

‘————————————————–
‘Body
‘————————————————–

If Time > strStart Then
 Wscript.Echo "It is after " & strStart & "."
 If Time < strEnd Then
  ‘Wscript.Echo strCurrentDir & "WindowsClientShutdown.HTA"
  WshShell.Run (chr(34) & strCurrentDir & "WindowsClientShutdown.HTA" & chr(34))
 Else
  ‘Wscript.Echo Time & " is later than " & strEnd & ".  It is too late to run this."
 End If
Else
 ‘Wscript.Echo Time & " is less than " & strStart
 ‘Wscript.Echo "Not time yet."
End If
*************************************************************************

 

WindowsClientShutdown.HTA
*************************************************************************

<script language="vbscript" type="text/vbscript">
<!–

‘————————————————–
‘ Global Variables
‘————————————————–
Dim strComputer, strAppName, objFSO, objShell, objWMIService, colComputer, objRegistry, WshShell, objNetwork
Dim nmsecs
Const adOpenStatic1 = 3
Const adLockOptimistic1 = 3

strComputer = "."

Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = createObject("wscript.shell")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "rootdefault:StdRegProv")

‘————————————————–
‘ End of Global Variables
‘————————————————–

‘——————————————————————-
‘ Onload_Window
‘——————————————————————-
Sub Onload_Window

 Window.resizeTo 300,300
 window.moveTo (screen.width-300) ,(screen.height – 300)

 Shutdown

 intrespond = msgbox("Is now a good time to shut down?", vbYesNo + vbQuestion + vbSystemModal, "Shutdown")
 
 If intrespond = vbYes Then
  ShutdownNow
 Else
  If intrespond = vbNo Then
   NoShutdown
   CloseWindow
  End If
 End If
 

End Sub

 

‘——————————————————————-
‘ CloseWindow
‘——————————————————————-
Sub CloseWindow
 window.close
End Sub

‘——————————————————————-
‘ Shutdown
‘——————————————————————-
Sub Shutdown

objShell.Run("shutdown -s -f -t 1800"), 1, TRUE

End Sub

‘——————————————————————-
‘ ShutdownNow
‘——————————————————————-
Sub ShutdownNow

objShell.Run("shutdown -a"), 1, TRUE
iTimerID = window.setInterval("ReallyShutdown", 3000)

End Sub

‘——————————————————————-
‘ ReallyShutdown
‘——————————————————————-
Sub ReallyShutdown

objShell.Run("shutdown -s -f -t 30"), 1, TRUE

End Sub

‘——————————————————————-
‘ NoShutdown
‘——————————————————————-
Sub NoShutdown

objShell.Run("shutdown -a"), 1, TRUE

End Sub

–>
</script>

<html>
<head>

<title>Windows Client Shutdown</title>

<HTA:APPLICATION ID="HTA1" APPLICATIONNAME="WindowsClientShutdownHTA" ICON="imageswinicon.ico"
  BORDER="thin"
  BORDERSTYLE="normal"
  CAPTION="yes"
  INNERBORDER="no"
  SELECTION="no"
  MAXIMIZEBUTTON="yes"
  MINIMIZEBUTTON="yes"
  SHOWINTASKBAR="yes"
  SINGLEINSTANCE="yes"
  SYSMENU="yes"
  VERSION="1.0" /> 
 
</head>

<body onload=Onload_Window>

<p><td><center><img src="imagesCOMPANY_LOGO.gif" hspace=5 vspace=5></center></td></p>

<p><td><center><b><font face="Arial" size="4">DEPARTMENT</font></b></center></td></p>

</body>
</html>

*************************************************************************

 

Advertisements
Categories: VBScript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: