hmmm...well Duh! yes its '"One or more arguments are invalid' - but looking at the original function it would seem the arguments are correct, so it must be something i'm doing with the formatting or something.
#NET_FW_IP_PROTOCOL_TCP = 6 ; for TCP ports
Protected objFirewall.COMateObject
Protected objPolicy.COMateObject
Protected colPorts.COMateObject
Protected objPort.ComateObject
objFirewall = COMate_CreateObject("HNetCfg.FwMgr")
objPolicy = objFirewall\GetObjectProperty("LocalPolicy()\CurrentProfile()")
colPorts = objPolicy\GetObjectProperty("GloballyOpenPorts()")
count = colPorts\GetIntegerProperty("Count()")
;seems to be working to here OK - count returns 38 ports which is correct per manual count
for I = 0 to count
objPort = colPorts\GetObjectProperty("Item(" + Str(I) + ", " + Str(#NET_FW_IP_PROTOCOL_TCP) + ")")
; the rest goes here
Next
objFirewall\Release()
srod wrote:I get a count of zero open global ports here!!! How do I manually add a port?
However, you do want For I = 0 to Count -1 do you not?
To manually add a port you have to do it in the firewall interface its self. I do have a script that will progmatically add it if thats what you want? But were not adding ports here, just enumerating whats already there and getting info.
I don't think I = 0 to Count -1 is correct in this case, it doesn't work that way with the existing vbs script and throws an error. besides the count would start at -1 instead of 0 then.
it returns 38 ports here, which is correct for this setup because there are actually 38 global open ports. So I tend to think this part at least is correct because the manual count says its 38 and it returns the same with the .vbs as well which I already know works properly.
Last edited by SFSxOI on Tue Mar 31, 2009 2:18 pm, edited 2 times in total.
Okay, have added a port and it is being picked up.... let's have a look at this code then...
I am getting a general exception error with the objPort = colPorts\GetObjectProperty("Item(" + Str(I) + ", " + Str(#NET_FW_IP_PROTOCOL_TCP) + ")") line.
I may look like a mule, but I'm not a complete ass.
Actually you do want the loop to run in this case I think because port 0 always exists even though it doesn't do anything, but for a firewall there is always a port 0. But I just tried the -1 and indeed the loop doesn't run which makes sense, but when the loop does run there is still the problem with objPort. So I know the ports exist and are in the collection already in GloballyOpenPorts() which is the collection, and I know they are there because the count tells me so. You think the COMate enum functions are needed here?
Last edited by SFSxOI on Tue Mar 31, 2009 2:31 pm, edited 1 time in total.
srod wrote:Okay, have added a port and it is being picked up.... let's have a look at this code then...
I am getting a general exception error with the objPort = colPorts\GetObjectProperty("Item(" + Str(I) + ", " + Str(#NET_FW_IP_PROTOCOL_TCP) + ")") line.
Thats odd, I still get the 'One or more arguments are invalid' thing
IncludePath "..\"
XIncludeFile "COMate.pbi"
Global objExcel.COMateObject
#NET_FW_IP_PROTOCOL_TCP = 6 ; for TCP ports
Define objFirewall.COMateObject
Define objPolicy.COMateObject
Define colPorts.COMateEnumObject
Define objPort.ComateObject
objFirewall = COMate_CreateObject("HNetCfg.FwMgr")
If objFirewall
objPolicy = objFirewall\GetObjectProperty("LocalPolicy()\CurrentProfile()")
If objPolicy
colPorts = objPolicy\CreateEnumeration("GloballyOpenPorts()")
If colPorts
objPort = colPorts\GetNextObject()
While objPort
Debug objPort\GetStringProperty("Name")
objPort\Release()
objPort = colPorts\GetNextObject()
Wend
colPorts\Release()
EndIf
objPolicy\Release()
EndIf
objFirewall\Release()
EndIf
**EDIT : sorry, if I had looked at the VB Script which you posted then I would have been absolutely definite from the beginning that you needed to use COMate's enumeration functions etc!
I may look like a mule, but I'm not a complete ass.