Jump to content

How to use ObjCreateInterface to detect firewall information


Go to solution Solved by Nine,

Recommended Posts

Posted
Local $oFireWall = ObjCreate("HNetCfg.FwPolicy2")
ConsoleWrite($oFireWall.CurrentProfileTypes & @CRLF)
ConsoleWrite($oFireWall.FirewallEnabled($oFireWall.CurrentProfileTypes) & @CRLF)

Regarding Windows Firewall information detection, the results of the above code are correct, but the results of the following code are wrong. What‘s the problem with the following code?

Local Const $CLSID_NetFwPolicy2 = "{E2B3C97F-6AE1-41AC-817A-F6F92166D7DD}"
Local Const $IID_INetFwPolicy2 = "{98325047-C671-4174-8D81-DEFCD3F03186}"
Local Const $TaskList = 'get_CurrentProfileTypes HRESULT(long*);' & _
        'get_FirewallEnabled HRESULT(long;short*);'
Local $pNetFwPolicy2 = ObjCreateInterface($CLSID_NetFwPolicy2, $IID_INetFwPolicy2, $TaskList, True)
Local $profileType = 0
Local $Ret = $pNetFwPolicy2.get_CurrentProfileTypes($profileType)
ConsoleWrite('$Ret=' & $Ret & @CRLF)
ConsoleWrite('$profileType=' & $profileType & @CRLF)
Local $enabled = 0
Local $Ret = $pNetFwPolicy2.get_FirewallEnabled($profileType, $enabled)
ConsoleWrite('$Ret=' & $Ret & @CRLF)
ConsoleWrite('$enabled=' & $enabled & @CRLF)

 

  • Solution
Posted (edited)

No tested

Local Const $CLSID_NetFwPolicy2 = "{E2B3C97F-6AE1-41AC-817A-F6F92166D7DD}"
Local Const $IID_INetFwPolicy2 = "{98325047-C671-4174-8D81-DEFCD3F03186}"
Local $pNetFwPolicy2 = ObjCreateInterface($CLSID_NetFwPolicy2, $IID_INetFwPolicy2, Default)
ConsoleWrite($pNetFwPolicy2.CurrentProfileTypes & @CRLF)
$pNetFwPolicy2 = 0

if not then you have add IDispatch and INetFwPolicy2 all the methods.

Edited by jugador
Posted (edited)
7 hours ago, Nine said:

It is because INetFwPolicy2 inherits from IDispatch.  You need to add the methods of IDispatch before.

thanks

Edited by haijie1223
Posted (edited)
6 hours ago, jugador said:

No tested

Local Const $CLSID_NetFwPolicy2 = "{E2B3C97F-6AE1-41AC-817A-F6F92166D7DD}"
Local Const $IID_INetFwPolicy2 = "{98325047-C671-4174-8D81-DEFCD3F03186}"
Local $pNetFwPolicy2 = ObjCreateInterface($CLSID_NetFwPolicy2, $IID_INetFwPolicy2, Default)
ConsoleWrite($pNetFwPolicy2.CurrentProfileTypes & @CRLF)
$pNetFwPolicy2 = 0

if not then you have add IDispatch and INetFwPolicy2 all the methods.

This code also works fine, thank you, I didn't check the help file carefully. 

Edited by haijie1223

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   1 member

×
×
  • Create New...