Page 37 of 39
Posted: Tue Mar 31, 2009 1:13 pm
by SFSxOI
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.
need more coffee

Posted: Tue Mar 31, 2009 1:15 pm
by srod
Can you post your code? I'd rather some code which will not alter my Win firewall settings though!

Posted: Tue Mar 31, 2009 1:39 pm
by SFSxOI
LoL

nope, the below is only supposed to return information for globally open ports and doesn't change anything, just collects info:
Code: Select all
#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()
and this is the original code:
Code: Select all
Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
Set colPorts = objPolicy.GloballyOpenPorts
For Each objPort in colPorts
Wscript.Echo "Port name: " & objPort.Name
Wscript.Echo "Port number: " & objPort.Port
Wscript.Echo "Port IP version: " & objPort.IPVersion
Wscript.Echo "Port protocol: " & objPort.Protocol
Wscript.Echo "Port scope: " & objPort.Scope
Wscript.Echo "Port remote addresses: " & objPort.RemoteAddresses
Wscript.Echo "Port enabled: " & objPort.Enabled
Wscript.Echo "Port built-in: " & objPort.Builtin
Next
Posted: Tue Mar 31, 2009 1:53 pm
by srod
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?
Posted: Tue Mar 31, 2009 1:57 pm
by srod
Does the GloballyOpenPorts() property not return an entire collection? If so you will need to use COMate's enumeration functions.
Posted: Tue Mar 31, 2009 2:05 pm
by SFSxOI
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.
Posted: Tue Mar 31, 2009 2:08 pm
by srod
Well if count is 0 then I would have thought that you would not want the loop to run; which is what For I = 0 to count-1 will ensure.
With no ports added then there is no way I can test the code; although I still think that you may need to create an enumeration etc.
Posted: Tue Mar 31, 2009 2:12 pm
by srod
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.
Posted: Tue Mar 31, 2009 2:15 pm
by SFSxOI
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?
Posted: Tue Mar 31, 2009 2:17 pm
by SFSxOI
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
Posted: Tue Mar 31, 2009 2:19 pm
by srod
The following works here :
Code: Select all
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!
Posted: Tue Mar 31, 2009 2:26 pm
by SFSxOI
srod wrote:The following works here :
Code: Select all
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
hmmmm...strange...doesn't work here, nothing returned in the Debug objPort\GetStringProperty("Name")
You using Vista or XP?
Posted: Tue Mar 31, 2009 2:31 pm
by SFSxOI
Whoops! never mind, it works now. I screwed up. OKi Dokee then it works.
Thanks srod

Posted: Tue Mar 31, 2009 2:32 pm
by srod
Let me guess : you didn't use "Define colPorts.COMateEnumObject" ?
Glad it is all working now.
Posted: Tue Mar 31, 2009 2:47 pm
by SFSxOI
yep, you guessed it
