Aggiungere una regola per un'applicazione al Firewall di Windows tramite PowerShell (it-IT)

Aggiungere una regola per un'applicazione al Firewall di Windows tramite PowerShell (it-IT)

Lo script seguente è stato adattato dal codice VBScript pubblicato all'indirizzo

http://msdn.microsoft.com/en-us/library/aa364695(v=VS.85).aspx

 

#--********************************************************************/
#  This PowerShell script includes sample code for adding an Application
#  rule using the Microsoft Windows Firewall APIs.
#--********************************************************************/

set-psdebug -strict

$CurrentProfile = $null

# Protocol
set-variable -name NET_FW_IP_PROTOCOL_TCP -value 6 -option constant

# Action
set-variable -name NET_FW_ACTION_ALLOW -value 1 -option constant

# Create the FwPolicy2 object.
$fwPolicy2 = $null
$fwPolicy2 = new-object -comobject HNetCfg.FwPolicy2

# Get the Rules object
$RulesObject = $null
$RulesObject = $fwPolicy2.Rules

$CurrentProfiles = $fwPolicy2.CurrentProfileTypes

# Create a Rule Object.
$NewRule = $null
$NewRule = new-object -comobject HNetCfg.FWRule

$NewRule.Name = "My Application Name"
$NewRule.Description = "Allow my application network traffic"
$NewRule.Applicationname = "%systemDrive%\Program Files\MyApplication.exe"
$NewRule.Protocol = $NET_FW_IP_PROTOCOL_TCP
$NewRule.LocalPorts = 4000
$NewRule.Enabled = $True
$NewRule.Grouping = "@firewallapi.dll,-23255"
$NewRule.Profiles = $CurrentProfiles
$NewRule.Action = $NET_FW_ACTION_ALLOW

# Add a new rule
$RulesObject.Add($NewRule)




Altre lingue

Questo articolo è disponibile anche nelle seguenti lingue:

Leave a Comment
  • Please add 2 and 1 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Comments
  • Luigi Bruno edited Original. Comment: Added the "Altre lingue" section. Added the "Multi Language Wiki Articles" tag.

  • Luigi Bruno edited Revision 1. Comment: Added the "Italian Wiki Articles" tag to the tag list.

Page 1 of 1 (2 items)
Wikis - Comment List
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Luigi Bruno edited Original. Comment: Added the "Altre lingue" section. Added the "Multi Language Wiki Articles" tag.

  • Luigi Bruno edited Revision 1. Comment: Added the "Italian Wiki Articles" tag to the tag list.

Page 1 of 1 (2 items)