Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Register with XP Service Pack 2 Firewall

by olivierp (Hermit)
on Sep 17, 2004 at 22:13 UTC ( #391911=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Register with XP Service Pack 2 Firewall
in thread Register with XP Service Pack 2 Firewall

I assume you are running Activestate Perl on that box. You should take a look at the Win32::OLE documentation, as well as the integrated OLE Browser. The following is untested, as I don't have a Windows box handy, but should get you started.

#Option Explicit use strict; use Win32::OLE; #' Set constants # Const NET_FW_PROFILE_DOMAIN = 0 # Const NET_FW_PROFILE_STANDARD = 1 # ' Scope # Const NET_FW_SCOPE_ALL = 0 #' IP Version - ANY is the only allowable setting for now #Const NET_FW_IP_VERSION_ANY = 2 #' Declare variables #Dim errornum use constant { NET_FW_PROFILE_DOMAIN => 0, NET_FW_PROFILE_STANDARD => 1, NET_FW_SCOPE_ALL => 0, NET_FW_IP_VERSION_ANY => 2, }; my $errornum; #' Create the firewall manager object. #Dim fwMgr #Set fwMgr = CreateObject("HNetCfg.FwMgr") my $fwMgr = Win32::OLE->new("HNetCfg.FwMgr"); #' Get the current profile for the local firewall policy. #Dim profile #Set profile = fwMgr.LocalPolicy.CurrentProfile my $profile = $fwMgr->LocalPolicy->{CurrentProfile}; #Dim app #Set app = CreateObject("HNetCfg.FwAuthorizedApplication") my $app = Win32::OLE->new("HNetCfg.FwAuthorizedApplication"); #app.ProcessImageFileName = "c:\padawan.exe" #app.Name = "Padawan" #app.Scope = NET_FW_SCOPE_ALL $app->{ProcessImageFileName} = "c:\\padawan.exe"; $app->{Name} = "Padawan"; $app->{Scope} = NET_FW_SCOPE_ALL; #' Use either Scope or RemoteAddresses, but not both #'app.RemoteAddresses = "*" #app.IpVersion = NET_FW_IP_VERSION_ANY #app.Enabled = TRUE $app->{IpVersion} = NET_FW_IP_VERSION_ANY; $app->{Enabled} = 0; #' Use this line if you want to add the app, but disabled. #'app.Enabled = FALSE $app->{Enabled} = 1; #On Error Resume Next #errornum = 0 $errornum = 0; #profile.AuthorizedApplications.Add app $profile->AuthorizedApplications->Add($app); #errornum = Err.Number $errornum = 0 + Win32::OLE->LastError(); #if errornum <> 0 then Wscript.Echo("Adding authorized application fai +led with: " & errornum) if ($errornum != 0) { print "Adding authorized application failed with: $errornum"; }

--
Olivier


Comment on Re^3: Register with XP Service Pack 2 Firewall
Download Code
Re^4: Register with XP Service Pack 2 Firewall
by slloyd (Hermit) on Sep 17, 2004 at 23:04 UTC
    Olivier,

    Thank you so much for your excellent example! You are a fine teacher.

    Steve

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://391911]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2015-07-06 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (85 votes), past polls