michaelleewebb Posted April 20, 2012 Share Posted April 20, 2012 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 ExplicitDim CurrentProfilesDim InterfaceArrayDim LowerBoundDim UpperBoundDim iterateDim rule' Profile TypeConst NET_FW_PROFILE2_DOMAIN = 1Const NET_FW_PROFILE2_PRIVATE = 2Const NET_FW_PROFILE2_PUBLIC = 4' ProtocolConst NET_FW_IP_PROTOCOL_TCP = 6Const NET_FW_IP_PROTOCOL_UDP = 17Const NET_FW_IP_PROTOCOL_ICMPv4 = 1Const NET_FW_IP_PROTOCOL_ICMPv6 = 58' DirectionConst NET_FW_RULE_DIR_IN = 1Const NET_FW_RULE_DIR_OUT = 2' ActionConst NET_FW_ACTION_BLOCK = 0Const NET_FW_ACTION_ALLOW = 1' Create the FwPolicy2 object.Dim fwPolicy2Set 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 timeif ( CurrentProfiles AND NET_FW_PROFILE2_DOMAIN ) then WScript.Echo("Domain Firewall Profile is active")end ifif ( CurrentProfiles AND NET_FW_PROFILE2_PRIVATE ) then WScript.Echo("Private Firewall Profile is active")end ifif ( CurrentProfiles AND NET_FW_PROFILE2_PUBLIC ) then WScript.Echo("Public Firewall Profile is active")end if' Get the Rules objectDim RulesObjectSet 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 ifNext Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now