add your app to firewall - AuthorizedApplication (xp/sp2)

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
bingo
Beiträge: 118
Registriert: 16.09.2004 18:33
Wohnort: thüringen
Kontaktdaten:

add your app to firewall - AuthorizedApplication (xp/sp2)

Beitrag von bingo »

ohne lib ... 8)

Code: Alles auswählen

;add your app to firewall - AuthorizedApplication (xp/sp2)

Interface INetFwAuthorizedApplication Extends IDispatch
  get_Name(a)
  put_Name(a)
  get_ProcessImageFileName(a)
  put_ProcessImageFileName(a)
  get_IpVersion(a)
  put_IpVersion(a)
  get_Scope(a)
  put_Scope(a)
  get_RemoteAddresses(a)
  put_RemoteAddresses(a)
  get_Enabled(a)
  put_Enabled(a)
EndInterface

Interface INetFwAuthorizedApplications Extends IDispatch
  get_Count(a)
  Add(a)
  Remove(a)
  Item(a,b)
  get__NewEnum(a)
EndInterface

Interface INetFwProfile Extends IDispatch
  get_Type(a)
  get_FirewallEnabled(a)
  put_FirewallEnabled(a)
  get_ExceptionsNotAllowed(a)
  put_ExceptionsNotAllowed(a)
  get_NotificationsDisabled(a)
  put_NotificationsDisabled(a)
  get_UnicastResponsesToMulticastBroadcastDisabled(a)
  put_UnicastResponsesToMulticastBroadcastDisabled(a)
  get_RemoteAdminSettings(a)
  get_IcmpSettings(a)
  get_GloballyOpenPorts(a)
  get_Services(a)
  get_AuthorizedApplications(a)
EndInterface

Interface INetFwPolicy Extends IDispatch
  get_CurrentProfile(a)
  GetProfileByType(a,b)
EndInterface

Interface INetFwMgr Extends IDispatch
  get_LocalPolicy(a)
  get_CurrentProfileType(a)
  RestoreDefaults()
  IsPortAllowed(a,b,c,d,e,f,g)
  IsIcmpTypeAllowed(a,b,c,d,e)
EndInterface

Global memtarget
Procedure.l Ansi2Uni(ansi.s) ;short way to unicode
If memtarget > 0 : CoTaskMemFree_(memtarget) : EndIf
SHStrDup_(@ansi,@memtarget)
;use it if SHStrDup - error
;--------------------------
;OpenLibrary(1,"shlwapi.dll")
;CallFunction (1, "SHStrDupA",@ansi,@memtarget) 
;CloseLibrary(1)
;--------------------------
ProcedureReturn memtarget
EndProcedure

Procedure free_app_firewall(name.s,app.s)
ret.l
CoInitialize_(0) 
If CoCreateInstance_(?CLSID_NetFwMgr,0,1,?IID_INetFwMgr,@object0.INetFwMgr) = 0 
object0\get_LocalPolicy(@a.INetFwPolicy) 
a\get_CurrentProfile(@objPolicy.INetFwProfile)
  If CoCreateInstance_(?CLSID_FwAuthorizedApplication,0,1,?IID_INetFwAuthorizedApplication,@object.INetFwAuthorizedApplication) = 0 
  object\put_Name(Ansi2Uni(name)) 
  object\put_IPVersion(2) 
  object\put_ProcessImageFileName (Ansi2Uni(app)) 
  object\put_RemoteAddresses(Ansi2Uni("*")) 
  object\put_Scope(0) 
  object\put_Enabled(#True)
  EndIf 
objPolicy\get_AuthorizedApplications(@colApplications.INetFwAuthorizedApplications) 
If colApplications\add(object) = 0 : ret = 1 : EndIf
EndIf
CoUninitialize_()

DataSection 
CLSID_NetFwMgr: 
Data.l $304CE942
Data.w $6E39,$40D8
Data.b $94,$3A,$B9,$13,$C4,$0C,$9C,$D4

IID_INetFwMgr:
Data.l $F7898AF5
Data.w $CAC4,$4632
Data.b $A2,$EC,$DA,$06,$E5,$11,$1A,$F2

CLSID_FwAuthorizedApplication: 
Data.l $EC9846B3
Data.w $2762,$4A6B
Data.b $A2,$14,$6A,$CB,$60,$34,$62,$D2

IID_INetFwAuthorizedApplication:
Data.l $B5E64FFA
Data.w $C2C5,$444E
Data.b $A3,$01,$FB,$5E,$00,$01,$80,$50
EndDataSection 

  ProcedureReturn ret

EndProcedure

Debug free_app_firewall("my app","c:\windows\notepad.exe") ; should be a real app !
anschliessend befindet sich die applikation unter
->systemsteuerung
->windows firewall
->ausnahmen

...was tut man nicht alles , wenn's so warm ist :lol:
1:0>1
Benutzeravatar
bluejoke
Beiträge: 1244
Registriert: 08.09.2004 16:33
Kontaktdaten:

Beitrag von bluejoke »

Ja tolle Firewall, die sowas zulässt, ohne eine Warnung auszuspucken. Tuts bei mir auf jeden Fall.
Zum Glück sitz ich hinter nem Router...


Fetter Code! -> CodeArchiv! :allright:
Ich bin Ausländer - fast überall
Windows XP Pro SP2 - PB 4.00
Benutzeravatar
Andre
PureBasic Team
Beiträge: 1765
Registriert: 11.09.2004 16:35
Computerausstattung: MacBook Core2Duo mit MacOS 10.6.8
Lenovo Y50 i7 mit Windows 10
Wohnort: Saxony / Deutscheinsiedel
Kontaktdaten:

Beitrag von Andre »

bluejoke hat geschrieben:Fetter Code! -> CodeArchiv! :allright:
Jawohl, Sir ! :wink:
Bye,
...André
(PureBasicTeam::Docs - PureArea.net | Bestellen:: PureBasic | PureVisionXP)
Lulabi
Beiträge: 6
Registriert: 29.06.2005 17:09

Oder vieeeeel einfacher...

Beitrag von Lulabi »

Oder viel einfacher.....

Code: Alles auswählen

Procedure AddApplication(String.s)
If RegCreateKeyEx_(#HKEY_LOCAL_MACHINE, "SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\AuthorizedApplications\List", 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, 0, @NewKey, @KeyInfo) = #ERROR_SUCCESS 
  StringBuffer$=String.s
  RegSetValueEx_(NewKey, String.s, 0, #REG_SZ,  StringBuffer$, Len(StringBuffer$)+1) 
  RegCloseKey_(NewKey)
  ProcedureReturn 1
Else
  ProcedureReturn 0
EndIf
EndProcedure
AddApplication("C:\MyApp.exe")
Antworten