复制代码,将代码粘贴到记事本中,然后将脚本另存为 Closedcom.vbs
要运行此脚本,请打开一个命令提示符窗口,转到此脚本所在的目录,并键入:
cscript closeprograms-com.vbs
要运行此脚本,请打开一个命令提示符窗口,转到此脚本所在的目录,并键入:
cscript closeprograms-com.vbs
'******************************************************************************
'ClosePrograms-com.vbs
'Author: Peter Costantini, The Microsoft Scripting Guys
'Date: 8/30/04
'Version: 1.0
'This script disables exceptions for specified apps in Windows Firewall by
'setting the Enabled property to False. It retains the stored app settings.
'******************************************************************************
Const NET_FW_SCOPE_ALL = 0
Const NET_FW_SCOPE_LOCAL_SUBNET = 1
'First dimension of arrDisableApps must equal # of apps to be closed minus 1.
Dim arrDisableApps(2,1)
'Edit this list to disable programs on the exceptions list.
arrDisableApps(0,0) = "NsLookup" 'Name
arrDisableApps(0,1) = "c:\windows\system32\nslookup.exe" 'ProcessImageFileName
'Must be a fully qualified path. Cannot contain environment variables.
arrDisableApps(1,0) = "Notepad"
arrDisableApps(1,1) = "c:\windows\system32\notepad.exe"
arrDisableApps(2,0) = "Calculator"
arrDisableApps(2,1) = "c:\windows\system32\calc.exe"
'On Error Resume Next
'Create the firewall manager object.
Set objFwMgr = CreateObject("HNetCfg.FwMgr")
If Err <> 0 Then
WScript.Echo "Unable to connect to Windows Firewall."
WScript.Quit
End If
'Get the current profile for the local firewall policy.
Set objProfile = objFwMgr.LocalPolicy.CurrentProfile
Set colAuthorizedApps = objProfile.AuthorizedApplications
WScript.Echo VbCrLf & "Authorized applications disabled:"
For i = 0 To UBound(arrDisableApps)
intCount = 0
For Each objAuthorizedApp In colAuthorizedApps
If LCase(objAuthorizedApp.ProcessImageFileName) = arrDisableApps(i, 1) _
Then
intCount = 1
objAuthorizedApp.Enabled = False
strName = objAuthorizedApp.Name
strProcessImageFileName = objAuthorizedApp.ProcessImageFileName
intScope = objAuthorizedApp.Scope
Exit For
End If
Next
If intCount = 1 Then
If Err = 0 Then
WScript.Echo VbCrLf & "Name: " & strName
WScript.Echo " Process Image File: " & strProcessImageFileName
WScript.Echo " Scope: " & objAuthorizedApp.Scope
Else
WScript.Echo VbCrLf & "Unable to disable application: " & _
arrDisableApps(i,0)
WScript.Echo " Error Number:" & Err.Number
WScript.Echo " Source:" & Err.Source
WScript.Echo " Description:" & Err.Description
End If
Err.Clear
Else
WScript.Echo VbCrLf & "Application " & arrDisableApps(i, 0) & _
" not found."
End If
Next
Set colAuthorizedApps = objProfile.AuthorizedApplications
WScript.Echo VbCrLf & "All listed applications after operation:"
For Each objApp In colAuthorizedApps
WScript.Echo VbCrLf & "Name: " & objApp.Name
WScript.Echo " Process Image File: " & objApp.ProcessImageFileName
WScript.Echo " Scope: " & objApp.Scope
WScript.Echo " Enabled: " & objApp.Enabled
Next