Jump to content

firewall : block, unblock utorrent with vbs


Recommended Posts

i'm trying to block utorrent via the firewall using vba. utorrent is installed and it created an opening in the firewall. where i want to get to is a vbs script that block utorrent and other script that unblocks it. so far i cant even block it. heres the code i'm trying to use. could someone help me ??



Option Explicit

Dim CurrentProfiles
Dim InterfaceArray
Dim LowerBound
Dim UpperBound
Dim iterate
Dim rule

' Profile Type
Const NET_FW_PROFILE2_DOMAIN = 1
Const NET_FW_PROFILE2_PRIVATE = 2
Const NET_FW_PROFILE2_PUBLIC = 4

' Protocol
Const NET_FW_IP_PROTOCOL_TCP = 6
Const NET_FW_IP_PROTOCOL_UDP = 17
Const NET_FW_IP_PROTOCOL_ICMPv4 = 1
Const NET_FW_IP_PROTOCOL_ICMPv6 = 58

' Direction
Const NET_FW_RULE_DIR_IN = 1
Const NET_FW_RULE_DIR_OUT = 2

' Action
Const NET_FW_ACTION_BLOCK = 0
Const NET_FW_ACTION_ALLOW = 1


' Create the FwPolicy2 object.
Dim fwPolicy2
Set fwPolicy2 = CreateObject("HNetCfg.FwPolicy2")

CurrentProfiles = fwPolicy2.CurrentProfileTypes

'// The returned 'CurrentProfiles' bitmask can have more than 1 bit set if multiple profiles
'// are active or current at the same time

if ( CurrentProfiles AND NET_FW_PROFILE2_DOMAIN ) then
WScript.Echo("Domain Firewall Profile is active")
end if

if ( CurrentProfiles AND NET_FW_PROFILE2_PRIVATE ) then
WScript.Echo("Private Firewall Profile is active")
end if

if ( CurrentProfiles AND NET_FW_PROFILE2_PUBLIC ) then
WScript.Echo("Public Firewall Profile is active")
end if

' Get the Rules object
Dim RulesObject
Set RulesObject = fwPolicy2.Rules

' Print all the rules in currently active firewall profiles.
WScript.Echo("Rules:")

For Each rule In Rulesobject
if rule.Profiles And CurrentProfiles then
if rule.ApplicationName = "C:\Program Files\uTorrent\uTorrent.exe" then
rule.Enabled = false
WScript.Echo(" Rule Name: " & rule.Name)
WScript.Echo(" ----------------------------------------------")
WScript.Echo(" Description: " & rule.Description)
WScript.Echo(" Application Name: " & rule.ApplicationName)
WScript.Echo(" Service Name: " & rule.ServiceName)
Select Case rule.Protocol
Case NET_FW_IP_PROTOCOL_TCP WScript.Echo(" IP Protocol: TCP.")
Case NET_FW_IP_PROTOCOL_UDP WScript.Echo(" IP Protocol: UDP.")
Case NET_FW_IP_PROTOCOL_ICMPv4 WScript.Echo(" IP Protocol: UDP.")
Case NET_FW_IP_PROTOCOL_ICMPv6 WScript.Echo(" IP Protocol: UDP.")
Case Else WScript.Echo(" IP Protocol: " & rule.Protocol)
End Select
if rule.Protocol = NET_FW_IP_PROTOCOL_TCP or rule.Protocol = NET_FW_IP_PROTOCOL_UDP then
WScript.Echo(" Local Ports: " & rule.LocalPorts)
WScript.Echo(" Remote Ports: " & rule.RemotePorts)
WScript.Echo(" LocalAddresses: " & rule.LocalAddresses)
WScript.Echo(" RemoteAddresses: " & rule.RemoteAddresses)
end if
if rule.Protocol = NET_FW_IP_PROTOCOL_ICMPv4 or rule.Protocol = NET_FW_IP_PROTOCOL_ICMPv6 then
WScript.Echo(" ICMP Type and Code: " & rule.IcmpTypesAndCodes)
end if
Select Case rule.Direction
Case NET_FW_RULE_DIR_IN WScript.Echo(" Direction: In")
Case NET_FW_RULE_DIR_OUT WScript.Echo(" Direction: Out")
End Select
WScript.Echo(" Enabled: " & rule.Enabled)
WScript.Echo(" Edge: " & rule.EdgeTraversal)
Select Case rule.Action
Case NET_FW_ACTION_ALLOW WScript.Echo(" Action: Allow")
Case NET_FW_ACTION_BLOCk WScript.Echo(" Action: Block")
End Select
WScript.Echo(" Grouping: " & rule.Grouping)
WScript.Echo(" Edge: " & rule.EdgeTraversal)
WScript.Echo(" Interface Types: " & rule.InterfaceTypes)
InterfaceArray = rule.Interfaces
if IsEmpty(InterfaceArray) then
WScript.Echo(" Interfaces: All")
else
LowerBound = LBound(InterfaceArray)
UpperBound = UBound(InterfaceArray)
WScript.Echo(" Interfaces: ")
for iterate = LowerBound To UpperBound
WScript.Echo(" " & InterfaceArray(iterate))
Next
end if

WScript.Echo("")

end if
end if
Next

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...