Einzelnen Beitrag anzeigen

Benutzerbild von Dalai
Dalai
Online

Registriert seit: 9. Apr 2006
1.680 Beiträge
 
Delphi 5 Professional
 
#4

AW: Aufruf von Properties über Automatisierung schlägt fehl?

  Alt 20. Mai 2015, 12:40
Ich hab eben mal das Beispiel "Retrieving Firewall Settings" ausprobiert und das tut, was es soll. Ich bekomme die Ausgabe "Firewall is ON on private profile.".

Das Beispiel "Checking if a Rule is Enabled" funktioniert nicht, da bekomme ich ebenfalls die Meldung "Mitglied nicht gefunden". Lustig, denn wenn ich auf einer PowerShell die Member ausgeben lasse mit
Code:
$fw = New-Object -ComObject hnetcfg.fwpolicy2
$fw | Get-Member
bekomme ich dies:
Code:
Name                                        MemberType           Definition
----                                         ----------            ----------
EnableRuleGroup                             Method               void EnableRuleGroup (int, string, bool)
IsRuleGroupEnabled                          Method               bool IsRuleGroupEnabled (int, string)
RestoreLocalFirewallDefaults                Method               void RestoreLocalFirewallDefaults ()
BlockAllInboundTraffic                      ParameterizedProperty bool BlockAllInboundTraffic (NET_FW_PROFILE_TYPE2_) {get} {set}
DefaultInboundAction                        ParameterizedProperty NET_FW_ACTION_ DefaultInboundAction (NET_FW_PROFILE_TYPE2_) {get} {set}
DefaultOutboundAction                       ParameterizedProperty NET_FW_ACTION_ DefaultOutboundAction (NET_FW_PROFILE_TYPE2_) {get} {s...
ExcludedInterfaces                          ParameterizedProperty Variant ExcludedInterfaces (NET_FW_PROFILE_TYPE2_) {get} {set}
FirewallEnabled                             ParameterizedProperty bool FirewallEnabled (NET_FW_PROFILE_TYPE2_) {get} {set}
IsRuleGroupCurrentlyEnabled                 ParameterizedProperty bool IsRuleGroupCurrentlyEnabled (string) {get}
NotificationsDisabled                       ParameterizedProperty bool NotificationsDisabled (NET_FW_PROFILE_TYPE2_) {get} {set}
UnicastResponsesToMulticastBroadcastDisabled ParameterizedProperty bool UnicastResponsesToMulticastBroadcastDisabled (NET_FW_PROFILE_TYP...
CurrentProfileTypes                         Property             int CurrentProfileTypes () {get}
LocalPolicyModifyState                      Property             NET_FW_MODIFY_STATE_ LocalPolicyModifyState () {get}
Rules                                       Property             INetFwRules Rules () {get}
ServiceRestriction                          Property             INetFwServiceRestriction ServiceRestriction () {get}
In der Ausgabe ist aber der Grund zu finden: Es ist ein Property, keine Funktion! Daraus folgt, dass man den Code so ändern muss:
bIsEnabled := fwPolicy2.IsRuleGroupCurrentlyEnabled['File and Printer Sharing']; und das funktioniert auch. Aber es kann sein, dass der String noch sprachspezifisch ist, d.h. er müsste ggf. für ein deutsches System übersetzt werden.

MfG Dalai
  Mit Zitat antworten Zitat