Shell.Windows method
Applies to: desktop apps only
Creates and returns a ShellWindows object. This object represents a collection of all of the open windows that belong to the Shell.
Syntax
retVal = Shell.Windows()
Parameters
This method has no parameters.
Return value
Type: IDispatch**
An object reference to the ShellWindows object.
Examples
The following example uses Windows to retrieve the ShellWindows object and display a count of the number of items that it contains. Proper usage is shown for JScript, VBScript, and Visual Basic.
JScript:
<script language="JScript">
function fnShellWindowsJ()
{
var objShell = new ActiveXObject("shell.application");
var objShellWindows;
objShellWindows = objShell.Windows();
if (objShellWindows != null)
{
var Shell = new ActiveXObject("WScript.Shell");
Shell.Popup(objShellWindows.Count);
}
}
</script>
VBScript:
<script language="VBScript"> function fnShellWindowsVBS() dim objShell dim objShellWindows set objShell = CreateObject("shell.application") set objShellWindows = objShell.Windows if (not objShellWindows is nothing) then WScript.Echo objShellWindows.Count end if set objShellWindows = nothing set objShell = nothing end function </script>
Visual Basic:
Private Sub fnShellWindowsVB() Dim objShell As Shell Dim objShellWindows As ShellWindows Set objShell = New Shell Set objShellWindows = objShell.Windows If (Not objShellWindows Is Nothing) Then Debug.Print objShellWindows.Count End If Set objShellWindows = Nothing Set objShell = Nothing End Sub
Requirements
|
Minimum supported client | Windows 2000 Professional, Windows XP |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
IDL |
|
|
DLL |
|
Send comments about this topic to Microsoft
Build date: 3/7/2012
Errors in Examples
In the 6th line of the examples (5th line in the Visual Basic example), objshell.Shell_Windows should be objShell.Windows. (In addition to Windows instead of Shell_Windows, note the capital "S" in objShell. JScript is case-sensitive.) Also, if the script is not running inside of a web browser, alert will not work. In VBScript, WScript.Echo can be used instead. In JScript, the following can be used instead:
var Shell = new ActiveXObject("WScript.Shell");
Shell.Popup(objShellWindows.Count);
var Shell = new ActiveXObject("WScript.Shell");
Shell.Popup(objShellWindows.Count);
- 5/12/2011
- Victor S from Sogeti
- 5/12/2011
- Victor S from Sogeti
Windows Method sample using PowerShell
# get-shellwindows.ps1This script produces the following output on my Server 2008 workstation:
# MSDN Sample to get help
# Thomas Lee - tfl@psp.co.uk
# First get shell object
$Shell = new-object -com Shell.Application
# Now get open windows
$windows = $Shell.windows()
# Display details
"There are {0} open windows on this system" -f $windows.count
$i=1
foreach ($window in $windows) {
"Window {0} - title={1}, path={2}" -f $i++, $window.locationname, $window.path
}
PS C:\Users\tfl>
C:\foo\get-shellwindows.ps1
There are 3 open windows on this system
Window 1 - title=Dave Edmunds - Getinge 2000 - FM, path=C:\Windows\
Window 2 - title=1982-05-07 Once Upon A Time.flac, path=C:\Windows\
Window 3 - title=template, path=C:\Windows\
- 6/30/2008
- Thomas Lee