#!perl
use Win32::OLE;
my $path=shift || usage();
my $name=shift || usage();
my $bool = ®isterXPSP2($path,$name);
if($bool == 1){print "\n\n<SUCCESS>\n";}
else{print "\n$bool \n\n<FAILURE>\n";}
exit;
#####################
sub usage{
print "Register an exe with windows firewall\n";
print "$0 path name\n";
exit;
}
#####################
sub registerXPSP2{
my $fullpath=shift || return;
my $name=shift || return;
print int(time()-$^T)," registerXPSP2 ", time(), "\n";
#sleep(10);
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.
print int(time()-$^T)," Getting fwMgr in registerXPSP2 ",
time(), "\n";
my $fwMgr = Win32::OLE->new("HNetCfg.FwMgr") || return
Win32::OLE->LastError();
# Get the current profile for the local firewall policy.
my $profile = $fwMgr->LocalPolicy->{CurrentProfile};
# Define application object
print int(time()-$^T)," Getting app in registerXPSP2 ", time(),
"\n";
my $app = Win32::OLE->new("HNetCfg.FwAuthorizedApplication") ||
return Win32::OLE->LastError();
$app->{ProcessImageFileName} = $fullpath;
$app->{Name} = $name;
$app->{Scope} = NET_FW_SCOPE_ALL;
#' Use either Scope or RemoteAddresses, but not both
$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;
print int(time()-$^T)," Adding app in registerXPSP2 ", time(),
"\n";
#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 failed with: " & errornum)
if ($errornum != 0) {
return "Adding authorized application failed with:
$errornum";
}
return 1;
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Alexander Apprich
Sent: Tuesday, September 28, 2004 4:29 AM
To: [EMAIL PROTECTED]
Subject: Configuring XP SP2 Firewall using perl
Hey guys,
is there anyone out there who configured Windows XP's Firewall, that
comes w/SP2, using perl and _not_ editing the registry using
Win32::Registry or Win32::TieRegistry?
The Ruleset (if u can call that a Ruleset) that is under
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\SharedAccess\Parame
ters\FirewallPolicy\StandardProfile\Global
seems to be easy to extend and/or modified using the Registry Perl-
Modules. But I would like to know if there is a way using WMI/
Win32::OLE to do that job.
Any help/hint is appreciated.
Alex
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs