|
Class clsWindowsFirewall
'////////////////////////////////////////////////////
'Windows Firewall Class
'File Name: clsWinFirewall
'Script Version: 1.0.0
'Last Edit: 9/5/2006
'Developer: Dx21, LLC
'////////////////////////////////////////////////////
Private NET_FW_PROFILE_DOMAIN
Private NET_FW_PROFILE_STANDARD
Private NET_FW_IP_PROTOCOL_UDP
Private NET_FW_IP_PROTOCOL_TCP
Private NET_FW_SCOPE_ALL
Private NET_FW_SCOPE_LOCAL_SUBNET
Private NET_FW_IP_VERSION_ANY
Private FILE_AND_PRINT_SHARING
Private UPNP_FRAMEWORK
Private REMOTE_DESKTOP
Private CURRENT_PROFILE
Private STANDARD_PROFILE
Private Sub Class_Initialize()
NET_FW_PROFILE_DOMAIN = 0
NET_FW_PROFILE_STANDARD = 1
NET_FW_IP_PROTOCOL_UDP = 17
NET_FW_IP_PROTOCOL_TCP = 6
NET_FW_SCOPE_ALL = 0
NET_FW_SCOPE_LOCAL_SUBNET = 1
NET_FW_IP_VERSION_ANY = 2
FILE_AND_PRINT_SHARING = 0
UPNP_FRAMEWORK = 1
REMOTE_DESKTOP = 2
CURRENT_PROFILE = 0
STANDARD_PROFILE = 1
End Sub
'---PRIVATE FUNCTIONS---------------------------------------------------------
Private Function ConnectToProfile(ByRef objP, bStandardProfile)
On Error Resume Next
Dim fwMgr: Set fwMgr = CreateObject("HNetCfg.FwMgr")
If fwMgr Is Nothing Then
ConnectToProfile = False
Exit Function
End If
If bStandardProfile Then
Dim objPolicy: Set objPolicy = fwMgr.LocalPolicy
Set objP = objPolicy.GetProfileByType(1)
Else
Set objP = fwMgr.LocalPolicy.CurrentProfile
End If
ConnectToProfile = (Err.Number = 0)
Set fwMgr = Nothing
Set objPolicy = Nothing
End Function
Private Function SetService(intService, bEnabled)
'Enables or Disables the File and Printer Sharing thru Firewall
'bEnabled (Boolean) T/F for setting state
'RETURNS: Boolean
Dim objProfile, colServices, objService
If ConnectToProfile(objProfile, False) = False Then
SetService = False
Exit Function
End If
Set colServices = objProfile.Services
Set objService = colServices.Item(intService)
objService.Enabled = bEnabled
Set objProfile = Nothing
Set colServices = Nothing
Set objService = Nothing
End Function
Private Function GetService(intService)
'Enables or Disables the File and Printer Sharing thru Firewall
'bEnabled (Boolean) T/F for setting state
'RETURNS: Boolean
Dim objProfile, colServices, objService
If ConnectToProfile(objProfile, False) = False Then
GetService = False
Exit Function
End If
Set colServices = objProfile.Services
Set objService = colServices.Item(intService)
GetService = objService.Enabled
Set objProfile = Nothing
Set colServices = Nothing
Set objService = Nothing
End Function
'---PUBLIC PROPERTIES---------------------------------------------------------
' General Firewall
Property Let FirewallEnabled(bEnabled)
'Enables or Disables the Firewall
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
objProfile.FirewallEnabled = bEnabled
Set objProfile = Nothing
End Property
Property Get FirewallEnabled()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
FirewallEnabled = False
Exit Property
End If
On Error Resume Next: Err.Clear
FirewallEnabled = objProfile.FirewallEnabled
Set objProfile = Nothing
End Property
Property Let FileAndPrinterSharing(bEnabled)
'Enables or Disables the File and Printer Sharing thru Firewall
'bEnabled (Boolean) T/F for setting state
SetService FILE_AND_PRINT_SHARING, bEnabled
End Property
Property Get FileAndPrinterSharing()
FileAndPrinterSharing = GetService(FILE_AND_PRINT_SHARING)
End Property
Property Let UPnPFramework(bEnabled)
'Enables or Disables UPnP Framework
'bEnabled (Boolean) T/F for setting state
SetService UPNP_FRAMEWORK, bEnabled
End Property
Property Get UPnPFramework()
UPnPFramework = GetService(UPNP_FRAMEWORK)
End Property
Property Let RemoteDesktop(bEnabled)
'Enables or Disables Remote Desktop
'bEnabled (Boolean) T/F for setting state
SetService REMOTE_DESKTOP, bEnabled
End Property
Property Get RemoteDesktop()
RemoteDesktop = GetService(REMOTE_DESKTOP)
End Property
Property Let ExceptionsNotAllowed(bEnabled)
'Enables or Disables Exceptions
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
objProfile.ExceptionsNotAllowed = bEnabled
Set objProfile = Nothing
End Property
Property Get ExceptionsNotAllowed()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ExceptionsNotAllowed = False
Exit Property
End If
On Error Resume Next: Err.Clear
ExceptionsNotAllowed = objProfile.ExceptionsNotAllowed
Set objProfile = Nothing
End Property
Property Let NotificationsDisabled(bEnabled)
'Enables or Disables Notifications
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
objProfile.NotificationsDisabled = bEnabled
Set objProfile = Nothing
End Property
Property Get NotificationsDisabled()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
NotificationsDisabled = False
Exit Property
End If
On Error Resume Next: Err.Clear
NotificationsDisabled = objProfile.NotificationsDisabled
Set objProfile = Nothing
End Property
Property Get CurrentProfileType()
Dim fwMgr: Set fwMgr = CreateObject("HNetCfg.FwMgr")
If fwMgr Is Nothing Then
CurrentProfileType = False
Exit Property
End If
On Error Resume Next: Err.Clear
CurrentProfileType = fwMgr.CurrentProfileType
'0 for Current Profile
'1 for Standard Profile
Set fwMgr = Nothing
End Property
Property Let UnicastResponsestoMulticastBroadcastDisabled(bEnabled)
'Enables or Disables the Unicast....
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
objProfile.UnicastResponsestoMulticastBroadcastDisabled = bEnabled
Set objProfile = Nothing
End Property
Property Get UnicastResponsestoMulticastBroadcastDisabled()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
UnicastResponsestoMulticastBroadcastDisabled = False
Exit Property
End If
On Error Resume Next: Err.Clear
UnicastResponsestoMulticastBroadcastDisabled = objProfile.UnicastResponsestoMulticastBroadcastDisabled
Set objProfile = Nothing
End Property
'ICMP
Property Let ICMP_AllowInboundEchoRequest(bEnabled)
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
objICMPSettings.AllowInboundEchoRequest = bEnabled
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Get ICMP_AllowInboundEchoRequest()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ICMP_AllowInboundEchoRequest = False
Exit Property
End If
On Error Resume Next: Err.Clear
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
ICMP_AllowInboundEchoRequest = objICMPSettings.AllowInboundEchoRequest
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Let ICMP_AllowInboundMaskRequest(bEnabled)
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
objICMPSettings.AllowInboundMaskRequest = bEnabled
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Get ICMP_AllowInboundMaskRequest()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ICMP_AllowInboundMaskRequest = False
Exit Property
End If
On Error Resume Next: Err.Clear
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
ICMP_AllowInboundMaskRequest = objICMPSettings.AllowInboundMaskRequest
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Let ICMP_AllowInboundRouterRequest(bEnabled)
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
objICMPSettings.AllowInboundRouterRequest = bEnabled
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Get ICMP_AllowInboundRouterRequest()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ICMP_AllowInboundRouterRequest = False
Exit Property
End If
On Error Resume Next: Err.Clear
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
ICMP_AllowInboundRouterRequest = objICMPSettings.AllowInboundRouterRequest
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Let ICMP_AllowInboundTimestampRequest(bEnabled)
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
objICMPSettings.AllowInboundTimestampRequest = bEnabled
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Get ICMP_AllowInboundTimestampRequest()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ICMP_AllowInboundTimestampRequest = False
Exit Property
End If
On Error Resume Next: Err.Clear
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
ICMP_AllowInboundTimestampRequest = objICMPSettings.AllowInboundTimestampRequest
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Let ICMP_AllowOutboundDestinationUnreachable(bEnabled)
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
objICMPSettings.AllowOutboundDestinationUnreachable = bEnabled
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Get ICMP_AllowOutboundDestinationUnreachable()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ICMP_AllowOutboundDestinationUnreachable = False
Exit Property
End If
On Error Resume Next: Err.Clear
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
ICMP_AllowOutboundDestinationUnreachable = objICMPSettings.AllowOutboundDestinationUnreachable
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Let ICMP_AllowOutboundPacketTooBig(bEnabled)
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
objICMPSettings.AllowOutboundPacketTooBig = bEnabled
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Get ICMP_AllowOutboundPacketTooBig()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ICMP_AllowOutboundPacketTooBig = False
Exit Property
End If
On Error Resume Next: Err.Clear
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
ICMP_AllowOutboundPacketTooBig = objICMPSettings.AllowOutboundPacketTooBig
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Let ICMP_AllowOutboundParameterProblem(bEnabled)
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
objICMPSettings.AllowOutboundParameterProblem = bEnabled
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Get ICMP_AllowOutboundParameterProblem()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ICMP_AllowOutboundParameterProblem = False
Exit Property
End If
On Error Resume Next: Err.Clear
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
ICMP_AllowOutboundParameterProblem = objICMPSettings.AllowOutboundParameterProblem
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Let ICMP_AllowOutboundSourceQuench(bEnabled)
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
objICMPSettings.AllowOutboundSourceQuench = bEnabled
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Get ICMP_AllowOutboundSourceQuench()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ICMP_AllowOutboundSourceQuench = False
Exit Property
End If
On Error Resume Next: Err.Clear
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
ICMP_AllowOutboundSourceQuench = objICMPSettings.AllowOutboundSourceQuench
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Let ICMP_AllowOutboundTimeExceeded(bEnabled)
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
objICMPSettings.AllowOutboundTimeExceeded = bEnabled
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Get ICMP_AllowOutboundTimeExceeded()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ICMP_AllowOutboundTimeExceeded = False
Exit Property
End If
On Error Resume Next: Err.Clear
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
ICMP_AllowOutboundTimeExceeded = objICMPSettings.AllowOutboundTimeExceeded
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Let ICMP_AllowRedirect(bEnabled)
'bEnabled (Boolean) T/F for setting state
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then Exit Property
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
objICMPSettings.AllowRedirect = bEnabled
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
Property Get ICMP_AllowRedirect()
Dim objProfile
If ConnectToProfile(objProfile, False) = False Then
ICMP_AllowRedirect = False
Exit Property
End If
On Error Resume Next: Err.Clear
Dim objICMPSettings: Set objICMPSettings = objProfile.ICMPSettings
ICMP_AllowRedirect = objICMPSettings.AllowRedirect
Set objProfile = Nothing
Set objICMPSettings = Nothing
End Property
'Remote Administration
Property Let RemoteAdministration_Enabled(bEnabled)
'Enables or Disables the Remote Administration
'bEnabled (Boolean) T/F for setting state
Dim objProfile, objAdminSettings
If ConnectToProfile(objProfile, False) = False Then Exit Property
Set objAdminSettings = objProfile.RemoteAdminSettings
objAdminSettings.Enabled = bEnabled
Set objProfile = Nothing
Set objAdminSettings = Nothing
End Property
Property Get RemoteAdministration_Enabled()
Dim objProfile, objAdminSettings
If ConnectToProfile(objProfile, False) = False Then
RemoteAdministration_Enabled = False
Exit Property
End If
On Error Resume Next: Err.Clear
Set objAdminSettings = objProfile.RemoteAdminSettings
RemoteAdministration_Enabled = objAdminSettings.Enabled
Set objProfile = Nothing
Set objAdminSettings = Nothing
End Property
Property Let RemoteAdministration_RemoteAddresses(strAddress)
'strAddress (String) IP Address/Submet Mask
Dim objRE: Set objRE = New RegExp
objRE.Global = True
objRE.IgnoreCase = True
objRE.Pattern = "((\b\d?\d?\d\.){3,3}\d?\d?\d|\*)"
If objRE.Test(strAddress) = False Then Exit Property
Dim objProfile, objAdminSettings
If ConnectToProfile(objProfile, False) = False Then Exit Property
Set objAdminSettings = objProfile.RemoteAdminSettings
objAdminSettings.RemoteAddresses = strAddress
Set objProfile = Nothing
Set objAdminSettings = Nothing
End Property
Property Get RemoteAdministration_RemoteAddresses()
Dim objProfile, objAdminSettings
If ConnectToProfile(objProfile, False) = False Then
RemoteAdministration_RemoteAddresses = vbNullString
Exit Property
End If
On Error Resume Next: Err.Clear
Set objAdminSettings = objProfile.RemoteAdminSettings
RemoteAdministration_RemoteAddresses = objAdminSettings.RemoteAddresses
Set objProfile = Nothing
Set objAdminSettings = Nothing
End Property
Property Let RemoteAdministration_Scope(intScope)
'intScope (Integer) Scope (0 or 1)
If intScope <> CURRENT_PROFILE And intScope <> STANDARD_PROFILE Then Exit Property
Dim objProfile, objAdminSettings
If ConnectToProfile(objProfile, False) = False Then Exit Property
Set objAdminSettings = objProfile.RemoteAdminSettings
objAdminSettings.Scope = intScope
Set objProfile = Nothing
Set objAdminSettings = Nothing
End Property
Property Get RemoteAdministration_Scope()
Dim objProfile, objAdminSettings
If ConnectToProfile(objProfile, False) = False Then
RemoteAdministration_Scope = False
Exit Property
End If
On Error Resume Next: Err.Clear
Set objAdminSettings = objProfile.RemoteAdminSettings
RemoteAdministration_Scope = objAdminSettings.Scope
Set objProfile = Nothing
Set objAdminSettings = Nothing
End Property
Property Get RemoteAdministration_IPVersion()
Dim objProfile, objAdminSettings
If ConnectToProfile(objProfile, False) = False Then
RemoteAdministration_IPVersion = False
Exit Property
End If
On Error Resume Next: Err.Clear
Set objAdminSettings = objProfile.RemoteAdminSettings
RemoteAdministration_IPVersion = objAdminSettings.IPVersion
Set objProfile = Nothing
Set objAdminSettings = Nothing
End Property
'---PUBLIC FUNCTIONS---------------------------------------------------------
Public Function AddAuthorizedApplication(strEXE, strAPPName, bStandardProfile)
'Adds an authorized application to the Windows Firewall
'strEXE (String) The full path and name of the application to add (must exist)
'strAPPName (String) The title of the application (for display)
'bStandardProfile (Boolean) T/F for adding application to the standard or current profile
'RETURNS: Boolean
Dim objProfile
If ConnectToProfile(objProfile,bStandardProfile) = False Then
AddAuthorizedApplication = False
Exit Function
End If
On Error Resume Next: Err.Clear
Dim objApp: Set objApp = CreateObject("HNetCfg.FwAuthorizedApplication")
If Err.Number <> 0 Then
AddAuthorizedApplication = False
Exit Function
End If
objApp.ProcessImageFileName = strEXE
objApp.Name = strAPPName
objApp.Scope = NET_FW_SCOPE_ALL
objApp.IpVersion = NET_FW_IP_VERSION_ANY
objApp.RemoteAddresses = "*"
objApp.Enabled = True
objProfile.AuthorizedApplications.Add objApp
AddAuthorizedApplication = (Err.Number = 0)
Set objProfile = Nothing
Set objApp = Nothing
End Function
Public Function RemoveAuthorizedApplication(strEXE, bStandardProfile)
'Removes an authorized application to the Windows Firewall
'strEXE (String) The full path and name of the application to add (must exist)
'bStandardProfile (Boolean) T/F for removing application from the standard or current profile
'RETURNS: Boolean
Dim objProfile
If ConnectToProfile(objProfile,bStandardProfile) = False Then
RemoveAuthorizedApplication = False
Exit Function
End If
On Error Resume Next: Err.Clear
objProfile.AuthorizedApplications.Remove(strEXE)
RemoveAuthorizedApplication = (Err.Number = 0)
Set objProfile = Nothing
End Function
Public Function AddPort(strName, intPort, intIPType, bStandardProfile)
'Adds an authorized port to the Windows Firewall
'strName (String) Display Name for the Port
'intPort (Integer) Port Number
'intIPType (Integer) UDP or TCP via Constant
'bStandardProfile (Boolean) T/F for adding port to the standard or current profile
'RETURNS: Boolean
Dim objProfile, objPort
If ConnectToProfile(objProfile,bStandardProfile) = False Then
AddPort = False
Exit Function
End If
On Error Resume Next: Err.Clear
Set objPort = CreateObject("HNetCfg.FwOpenPort")
If Err.Number <> 0 Then
AddPort = False
Exit Function
End If
objPort.Name = strName
objPort.Protocol = intIPType
objPort.port = intPort
objPort.Scope = NET_FW_SCOPE_ALL
objPort.Enabled = True
objProfile.GloballyOpenPorts.Add objPort
AddPort = (Err.Number = 0)
Set objPort = Nothing
Set objProfile = Nothing
End Function
Public Function RemovePort(intPort, intIPType, bStandardProfile)
'Removes an authorized port to the Windows Firewall
'intPort (Integer) Port Number
'intIPType (Integer) UDP or TCP via Constant
'bStandardProfile (Boolean) T/F for removing port from the standard or current profile
'RETURNS: Boolean
Dim objProfile
If ConnectToProfile(objProfile,bStandardProfile) = False Then
RemovePort = False
Exit Function
End If
On Error Resume Next: Err.Clear
objProfile.GloballyOpenPorts.Remove intPort, intIPType
RemovePort = (Err.Number = 0)
Set objProfile = Nothing
End Function
Public Function GetAuthorizedApplicationList(bStandardProfile)
'Provides List of Authorized Applications
'bStandardProfile (Boolean) T/F for removing port from the standard or current profile
'RETURNS: Array
Dim objProfile, colApplications, objApplication
Dim aryAppList(), Index
If ConnectToProfile(objProfile,bStandardProfile) = False Then
GetAuthorizedApplicationList = vbNullString
Exit Function
End If
On Error Resume Next: Err.Clear
Set colApplications = objProfile.AuthorizedApplications
If Err.Number <> 0 Then
GetAuthorizedApplicationList = vbNullString
Exit Function
End If
ReDim aryAppList(colApplications.Count,6)
Index = 0
For Each objApplication In colApplications
aryAppList(Index,0) = objApplication.Name
aryAppList(Index,1) = objApplication.Enabled
aryAppList(Index,2) = objApplication.IPVersion
aryAppList(Index,3) = objApplication.ProcessImageFileName
aryAppList(Index,4) = objApplication.RemoteAddresses
aryAppList(Index,5) = objApplication.Scope
Index = Index + 1
Next
GetAuthorizedApplicationList = aryAppList
Erase aryAppList
End Function
Public Function GetGloballyOpenPorts(bStandardProfile)
'Provides List of Globally Open Ports
'bStandardProfile (Boolean) T/F for removing port from the standard or current profile
'RETURNS: ArraySet
Dim objProfile, colPorts, objPort
Dim aryPortList(), Index
If ConnectToProfile(objProfile,bStandardProfile) = False Then
GetGloballyOpenPorts = vbNullString
Exit Function
End If
On Error Resume Next: Err.Clear
Set colPorts = objProfile.GloballyOpenPorts
If Err.Number <> 0 Then
GetGloballyOpenPorts = vbNullString
Exit Function
End If
ReDim aryPortList(colPorts.Count,8)
Index = 0
For Each objPort In colPorts
aryPortList(Index,0) = objPort.Name
aryPortList(Index,1) = objPort.Port
aryPortList(Index,2) = objPort.IPVersion
aryPortList(Index,3) = objPort.Protocol
aryPortList(Index,4) = objPort.Scope
aryPortList(Index,5) = objPort.RemoteAddresses
aryPortList(Index,6) = objPort.Enabled
aryPortList(Index,7) = objPort.Builtin
Index = Index + 1
Next
GetGloballyOpenPorts = aryPortList
Erase aryPortList
End Function
Public Function RestoreDefaults()
On Error Resume Next: Err.Clear
Dim fwMgr: Set fwMgr = CreateObject("HNetCfg.FwMgr")
If fwMgr Is Nothing Then
RestoreDefaults = False
Exit Function
Else
fwMgr.RestoreDefaults()
RestoreDefaults = (Err.Number = 0)
End If
Set fwMgr = Nothing
End Function
'////////////////////////////////////////////////////
'
'/
[ 本帖最后由 netegg 于 2008-6-13 12:28 编辑 ] |
|