自从XP有了SP2之后,域内的网络管理就引来了诸多不便,总是受到防火墙的阻扰。对于XP我们可以禁用之,但是2000没得罪你,犯不着受到牵连。可以采用组策略的wmi筛选功能只对xp有效,也可以在脚本里进行OS判断,本文采用后者。
复制以下脚本命名为Firewall-disable.vbs,通过组策略指派到计算机的开机脚本中。
- 'Script Start
- On Error Resume Next
- '==Get OS==
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
- Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
- For Each objOperatingSystem in colOperatingSystems
- 'Wscript.Echo objOperatingSystem.Caption
- strOS = objOperatingSystem.Caption
- Next
- 'If OS=XP then disable firewall
- If InStr(strOS, "XP") Then
- Set objFirewall = CreateObject("HNetCfg.FwMgr")
- Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
- objPolicy.FirewallEnabled = FALSE
- Else
- Wscript.Quit
- End If
- '==Get computer name==
- Set objNet = createobject("Wscript.Network")
- strPCName = objNet.Computername
- '==Get current Date & Time==
- strYear = Year(Date)
- strMonth = Month(Date)
- If strMonth < 10 Then strMonth = 0 & strMonth
- strDay = Day(Date)
- If strDay < 10 Then strDay = 0 & strDay
- strDate = strYear & strMonth & strDay
- Dim MyTime, MyHour, MyMin
- MyTime = Now
- MyHour = Hour(MyTime)
- If MyHour < 10 Then MyHour = 0 & MyHour
- MyMin = Minute(Now)
- If MyMin < 10 Then MyMin = 0 & MyMin
- strTime = MyHour & ":" & MyMin
- '==Create report==
- Const ForReading=1
- Const ForWriting=2
- Const ForAppending=8
- Const OverwriteExisting = True
- Dim fso, ts
- Set fso = CreateObject("Scripting.FileSystemObject")
- strPath = "\\FileSrv\GPreport\FW_Report\"
- If fso.FileExists(strPath & strPCName & ".txt") Then
- Set ts = fso.OpenTextFile(strPath & strPCName & ".txt", ForAppending)
- ts.WriteLine strPCName & " firewall has been disabled on " & strDate & "." & strtime & VbCrlf
- ts.Close
- Else
- Set ts = fso.CreateTextFile(strPath & strPCName & ".txt", true)
- ts.WriteLine strPCName & " firewall has been disabled on " & strDate & "." & strtime & VbCrlf
- ts.Close
- End If
- 'Script End
本文转自yangye1985 51CTO博客,原文链接:http://blog.51cto.com/yangye/200450,如需转载请自行联系原作者