Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
Windows Shell
Shell Reference
Shell
Methods
 Windows Method
Windows Method

Creates and returns a ShellWindows object. This object represents a collection of all of the open windows that belong to the Shell.

Syntax

oWindows = Shell.Windows()

Return Value

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 Microsoft JScript, Microsoft Visual Basic Scripting Edition (VBScript), and Visual Basic.

JScript:

<script language="JScript">
    function fnShellWindowsJ()
    {
        var objShell = new ActiveXObject("Shell.Application");
        var objShellWindows;
        
        objShellWindows = objShell.Windows();

        if (objShellWindows != null)
        {
            alert(objShellWindows.Count);
        }
    }
</script>

VBScript:

<script language="VBScript">
    function fnShellWindowsVB()
        dim objShell
        dim objShellWindows
        
        set objShell = CreateObject("Shell.Application")
        set objShellWindows = objShell.Windows

        if (not objShellWindows is nothing) then
            alert(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

Applies To

Shell
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Windows Method sample using PowerShell      Thomas Lee   |   Edit   |   Show History
# get-shellwindows.ps1
# 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
}
This script produces the following output on my Server 2008 workstation:

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\


Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker