If you have installed the Microsoft Internet Explorer 4.0/5.0 on your Windows system, you have may access Windows shell function. The Windows Shell object mentioned below provides several methods to access your Windows shell. You can create a reference to the shell's application object using the following VBScript command:
Set Shell = WScript.CreateObject ("Shell.Application")
Afterward you can use the object variable Shell to access the methods and properties provided by the appliation object.
Note: If you receive a run-time error reporting that CreateObject can't instantiate the Shell.Application object, than the Shell version is probably below 4.71. This may the case in Windows 95 and Windows NT, if IE 4 is installed without Active Desktop. |
I have introduced already the Suspend and the ShutdownWindows methods in previous samples. Beside these methods there are other methods (which may be studied using the Object Browser provided in several of Microsoft's development environments - see also chapter 2 of my WSH Tutorial, which is downloadable as a sneak preview from my web-site).
Method | Remark |
MinimizeAll | Minimize all windows |
UndoMinimizeAll | Rollback the last action (e.g. MinimizeAll, MaximizeAll etc.) |
TileVertically | Tile windows vertically |
TileHorizontally | Tile windows horizontally |
I used this know how in the following VBScript program to access the Shell object. The script is derived from my WSH Tutorial and demonstrates how to minimize/maximize and tile desktop windows using the Shell.application object and its methods.
'************************************************ ' File: Shell.vbs (WSH sample in VBScript) ' Author: Günter Born ' ' Demonstrates how to access the Windows-Shell ' from a WSH script. The windows shown on the ' Desktop will be minimized and aligned ' horizontally/vertically. ' ' In no way shall the author be liable for any ' losses or damages resulting from the use of this ' program. Use AS-IS at your own risk. ' ' The code is the property of the author. You may ' use the code and modify it, as far as this header ' remains intact. Further updates and other samples ' may be found on my WSH Bazaar: ' http://www.borncity.de '************************************************ Option Explicit Dim Shell, Title Title = "WSH sample - by Günter Born" ' create WSH Shell object Set Shell = WScript.CreateObject ("Shell.Application") If (MsgBox("Minimize all Windows?", _ vbYesNo + vbQuestion, Title) = vbYes) Then Shell.MinimizeAll ' MinimizeAll-method WScript.Echo "Undo?" Shell.UndoMinimizeAll ' restore windows first End if If (MsgBox("Tile Windows Vertically?", _ vbYesNo + vbQuestion, Title) = vbYes) Then Shell.TileVertically ' vertically WScript.Echo "Undo?" Shell.UndoMinimizeAll ' restore windows first End if If (MsgBox("Tile Windows Horizontally?", _ vbYesNo + vbQuestion, Title) = vbYes) Then Shell.TileHorizontally WScript.Echo "Undo?" Shell.UndoMinimizeAll ' restore windows first End if If (MsgBox("Cascade all Windows?", _ vbYesNo + vbQuestion, Title) = vbYes) Then Shell.CascadeWindows WScript.Echo "Undo?" Shell.UndoMinimizeAll ' restore windows first End if WScript.Echo "Ready?" ' End |
The next sample demonstrate how to invoke several dialogs using the Shell.Application object and its methods.
'************************************************ ' File: Shell1.vbs (WSH sample in VBScript) ' Author: Günter Born ' Demonstrates how to access the Windows-Shell ' from a WSH script. We opens a folder window. ' ' In no way shall the author be liable for any ' losses or damages resulting from the use of this ' program. Use AS-IS at your own risk. ' ' The code is the property of the author. You may ' use the code and modify it, as far as this header ' remains intact. Further updates and other samples ' may be found on my WSH Bazaar: ' http://www.borncity.de '************************************************ Option Explicit Dim Shell, wsh, Title, path Title = "WSH sample - by Günter Born" 'create WSH Shell object Set wsh = WScript.CreateObject ("WScript.Shell") path = wsh.ExpandEnvironmentStrings("%windir%") ' create Windows Shell Application object Set Shell = WScript.CreateObject ("Shell.Application") ' open a folder in the Explorer window WScript.Echo "Explorer Windows folder" Shell.Explore path 'show folder in a shell window WScript.Echo "Open Windows folder \System" Shell.Open path & "\System" WScript.Echo "Ready?" ' End |
The Shell object provides many other methods and properties which are described in my WSH book Inside Windows Scripting Host, published by Microsoft Press Germany and within my book Microsoft Windows Script Host 2.0 Developer's Guide, published by Microsoft Press USA. The documentation of the Shell object may be found also in the Microsoft Developers Network (MSDN) - have a look at msdn.microsoft.com in the developers documentation, and search for Windows Shell (I forgot the exact location).
(c) Günter Born