This script lists the open ports and authorized apps for Windows Firewall. To perform this task, the script uses the Windows Firewall COM automation server. It runs only against the local computer.
FwListExceptions.vbs is a bonus script; it does not correspond to any of the scripts that ships with Application Compatibility Testing and Mitigation Guide for Windows XP Service Pack 2 and which are documented in the Appendix. You can download a Windows Installer (.msi) file that installs the Guide and its associated scripts from:
To use the script, copy the code, paste it into Notepad, and then save the script as FwListExceptions.vbs. To run the script, open a command prompt window to the directory of the script and type:
If the default script host on the computer is Cscript.exe, the initial "cscript" may be omitted.
'FwListExceptions.vbs 'Author: Peter Costantini, The Microsoft Scripting Guys 'Date: 9/1/04 'Version: 1.0 'This script lists the open ports and authorized apps for Windows Firewall. '****************************************************************************** 'Set constants. Const NET_FW_IP_PROTOCOL_TCP = 6 Const NET_FW_IP_PROTOCOL_UDP = 17 Const NET_FW_SCOPE_ALL = 0 Const NET_FW_SCOPE_LOCAL_SUBNET = 1 On Error Resume Next 'Create the firewall manager object. Set objFwMgr = CreateObject("HNetCfg.FwMgr") If Err <> 0 Then WScript.Echo "Unable to connect to Windows Firewall." WScript.Quit End If 'Get the current profile for the local firewall policy. Set objProfile = objFwMgr.LocalPolicy.CurrentProfile WScript.Echo VbCrLf & "Windows Firewall" 'Get collection of open ports. Set colOpenPorts = objProfile.GloballyOpenPorts WScript.Echo VbCrLf & "All listed ports:" For Each objPort In colOpenPorts WScript.Echo VbCrLf & "Name: " & objPort.Name If objPort.Protocol = 6 Then strProtocol = "TCP" ElseIf objPort.Protocol = 17 Then strProtocol = "UDP" Else strProtocol = "UNKNOWN" End If WScript.Echo " Protocol: " & strProtocol WScript.Echo " Port Number: " & objPort.Port If objPort.Scope = 0 Then strScope = "All" ElseIf objPort.Scope = 1 Then strScope = "Local Subnet" Else strScope = "UNKNOWN" End If WScript.Echo " Scope: " & strScope WScript.Echo " Enabled: " & objPort.Enabled Next 'Get collection of authorized applications. Set colAuthorizedApps = objProfile.AuthorizedApplications WScript.Echo VbCrLf & "All listed applications:" For Each objApp In colAuthorizedApps WScript.Echo VbCrLf & "Name: " & objApp.Name WScript.Echo " Process Image File: " & objApp.ProcessImageFileName If objApp.Scope = 0 Then strScope = "All" ElseIf objApp.Scope = 1 Then strScope = "Local Subnet" Else strScope = "UNKNOWN" End If WScript.Echo " Scope: " & strScope WScript.Echo " Enabled: " & objApp.Enabled Next
For online peer support, join The Official Scripting Guys Forum! To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.