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

I am sure they are just jumping with joy to help :)

I found that following vbscript that will do it but since I do not know vbscript very well, I am not sure how to convert this to a perl script. Any ideas?

Option Explicit ' 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 ' Create the firewall manager object. Dim fwMgr Set fwMgr = CreateObject("HNetCfg.FwMgr") ' Get the current profile for the local firewall policy. Dim profile Set profile = fwMgr.LocalPolicy.CurrentProfile Dim app Set app = CreateObject("HNetCfg.FwAuthorizedApplication") 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 ' Use this line if you want to add the app, but disabled. 'app.Enabled = FALSE On Error Resume Next errornum = 0 profile.AuthorizedApplications.Add app errornum = Err.Number if errornum <> 0 then Wscript.Echo("Adding authorized application fail +ed with: " & errornum)

Replies are listed 'Best First'.
Re^3: Register with XP Service Pack 2 Firewall
by olivierp (Hermit) on Sep 17, 2004 at 22:13 UTC
    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.

    --
    Olivier
      Olivier,

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

      Steve

Re^3: Register with XP Service Pack 2 Firewall
by slloyd (Hermit) on Jun 14, 2005 at 14:37 UTC
    This is how I ended up solving the problem..
    Note: I try 5 times so that this script can be put in startup. Without the retry, the script may run before the firewall has initialized.
    use strict; my $count=0; my $ok=0; my $progname=shift || usage(); my $progexe=shift || usage(); while(1){ $ok=&registerFirewall($progname,$progexe); last if $ok; last if $count>5; $count++; sleep(5); } if(!$ok){die "Unable to register with windows firewall.\n";} ############### sub usage{ print "$0 Name PathToExe\n"; print "\tRegisters program Name found at PathToExe with Windows Fi +rewall\n"; exit; } ############### sub registerFirewall{ my $name=shift || return "No Name"; my $path=shift || return "No Path"; return "$path does not exist" if !-s $path; my $cmd=qq|netsh firewall add allowedprogram "program=$path" "name +=$name"|; #print "$cmd\n"; my @tmp=`$cmd`; my $result=join('',@tmp); if($result=~/ok/is){return 1;} print "registerFirewall Error: $result\n"; return 0; }