Remove application exception (VBScript)

This code can be found in Chapter 3 of Windows Server 2003 Networking Recipes

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book "Windows Server 2003 Networking Recipes"

' This code removes an existing application exception
'  and re-creates it with new values
' ------ SCRIPT CONFIGURATION ------
 Set Firewall = CreateObject("HNetCfg.FwMgr")
 Set Policy = Firewall.LocalPolicy
 Set Profile = Policy.GetProfileByType(1)
 strCurrentApp = "c:\program files\image\image123.exe"
 strNewApp = "c:\program files\image\imaging.exe"
' ------ END CONFIGURATION ---------

Set colApplications = Profile.AuthorizedApplications

For Each Application in colApplications
  If Application.ProcessImageFileName = strCurrentApp Then
    WScript.Echo "Removed " & Application.Name " from authorized list!"
    colApplications.Remove(Application)
  End If
Next

Set newApplication = CreateObject("HNetCfg.FwAuthorizedApplication")
newApplication.Name = "Imaging"
newApplication.IPVersion = 2
newApplication.ProcessImageFileName = strNewApp
newApplication.RemoteAddresses = "*"
newApplication.Scope = 0
newApplication.Enabled = True

colApplications.Add(objApplication)

WScript.Echo "Application " & strNewApp & " added successfully!"

This code has been viewed 1194 times.

New from the creators of TechTasks.com: StatSheet.com