zhuqingedu 发表于 2010-9-27 23:40:26

[已解决]关于系统服务优化脚本的修改

本帖最后由 zhuqingedu 于 2010-9-28 20:50 编辑

  skyfree的《XP定制不完全攻略》里,分享了一个自动优化服务的脚本,很是实用,脚本内容如下,我现在有个需求,就是希望用户在运行这个脚本之后,先弹出一个窗口,提示:“运行此程序前,请确定已经在360安全卫士里将禁用的服务全部恢复。”然后点击“确定”按钮开始执行脚本,点击“取消”则关闭脚本。(如果不先在360安全卫士里将禁用的服务恢复的话,即使在services.msc里手动把服务设置成自动启动,重启后还是会被360强行禁用的。)因为对AU3一点都不懂,所以希望哪位朋友可以帮忙改改,呵呵。
      对了,还有个问题请教下,这个脚本里声明$DemandServName[]和$DemandServ[]时好像都是说有24个变量,但是这两个数组都只赋值了21个,不知道是什么原因呀。Dim $DisabledServ,$DemandServ,$AutoServ
Dim $DisabledServName,$DemandServName,$AutoServName
Dim $i,$t

$t=0

;$Disabled

$DisabledServ = "Alerter"
$DisabledServ = "ClipSrv"
$DisabledServ = "TrkWks"
$DisabledServ = "MSDTC"
$DisabledServ = "ERSvc"
$DisabledServ = "FastUserSwitchingCompatibility"
$DisabledServ = "helpsvc"
$DisabledServ = "HidServ"
$DisabledServ = "ImapiService"
$DisabledServ = "CiSvc"
$DisabledServ = "Messenger"
$DisabledServ = "SwPrv"
$DisabledServ = "mnmsrvc"
$DisabledServ = "NetDDE"
$DisabledServ = "NetDDEdsdm"
$DisabledServ = "RSVP"
$DisabledServ = "RemoteRegistry"
$DisabledServ = "NtmsSvc"
$DisabledServ = "RemoteAccess"
$DisabledServ = "seclogon"
$DisabledServ = "wscsvc"
$DisabledServ = "ShellHWDetection"
$DisabledServ = "SENS"
$DisabledServ = "srservice"
$DisabledServ = "TlntSvr"
$DisabledServ = "TermService"
$DisabledServ = "UPS"
$DisabledServ = "VSS"
$DisabledServ = "WebClient"
$DisabledServ = "W32Time"

$DisabledServName = "Alerter"
$DisabledServName = "ClipBook"
$DisabledServName = "Distributed Link Tracking Client"
$DisabledServName = "Distributed Transaction Coordinator"
$DisabledServName = "Error Reporting Service"
$DisabledServName = "Fast User Switching Compatibility"
$DisabledServName = "Help and Support"
$DisabledServName = "Human Interface Device Access"
$DisabledServName = "IMAPI CD-Burning COM Service"
$DisabledServName = "Indexing Service"
$DisabledServName = "Messenger"
$DisabledServName = "MS Software Shadow Copy Provider"
$DisabledServName = "NetMeeting Remote Desktop Sharing"
$DisabledServName = "Network DDE"
$DisabledServName = "Network DDE DSDM"
$DisabledServName = "QoS RSVP"
$DisabledServName = "Remote Registry"
$DisabledServName = "Removable Storage"
$DisabledServName = "Routing and Remote Access"
$DisabledServName = "Secondary Logon"
$DisabledServName = "Security Center"
$DisabledServName = "Shell Hardware Detection"
$DisabledServName = "System Event Notification"
$DisabledServName = "System Restore Service"
$DisabledServName = "Telnet"
$DisabledServName = "Terminal Services"
$DisabledServName = "Uninterruptible Power Supply"
$DisabledServName = "Volume Shadow Copy"
$DisabledServName = "WebClient"
$DisabledServName = "Windows Time"

;$Demand

$DemandServ = "AppMgmt"
$DemandServ = "COMSysApp"
$DemandServ = "HTTPFilter"
$DemandServ = "dmadmin"
$DemandServ = "Netlogon"
$DemandServ = "Netman"
$DemandServ = "xmlprov"
$DemandServ = "NtLmSsp"
$DemandServ = "SysmonLog"
$DemandServ = "WmdmPmSN"
$DemandServ = "RasAuto"
$DemandServ = "RasMan"
$DemandServ = "RDSessMgr"
$DemandServ = "RpcLocator"
$DemandServ = "SCardSvr"
$DemandServ = "SSDPSRV"
$DemandServ = "TapiSrv"
$DemandServ = "stisvc"
$DemandServ = "MSIServer"
$DemandServ = "Wmi"
$DemandServ = "WmiApSrv"
;$DemandServ[] = "WudfSvc"
;$DemandServ[] = "WMPNetworkSvc"

$DemandServName = "Application Management"
$DemandServName = "COM+ System Application"
$DemandServName = "HTTP SSL"
$DemandServName = "Logical Disk Manager Administrative Service"
$DemandServName = "Net Logon"
$DemandServName = "Network Connections"
$DemandServName = "Network Provisioning Service"
$DemandServName = "NT LM Security Support Provider"
$DemandServName = "Performance Logs and Alerts"
$DemandServName = "Portable Media Serial Number Service"
$DemandServName = "Remote Access Auto Connection Manager"
$DemandServName = "Remote Access Connection Manager"
$DemandServName = "Remote Desktop Help Session Manager"
$DemandServName = "Remote Procedure Call (RPC) Locator"
$DemandServName = "Smart Card"
$DemandServName = "SSDP Discovery Service"
$DemandServName = "Telephony"
$DemandServName = "Windows Image Acquisition (WIA)"
$DemandServName = "Windows Installer"
$DemandServName = "Windows Management Instrumentation Driver Extensions"
$DemandServName = "WMI Performance Adapter"

;$Auto

$AutoServ = "ALG"
$AutoServ = "wuauserv"
$AutoServ = "BITS"
$AutoServ = "EventSystem"
$AutoServ = "Browser"
$AutoServ = "CryptSvc"
$AutoServ = "DcomLaunch"
$AutoServ = "Dhcp"
$AutoServ = "Dnscache"
$AutoServ = "Eventlog"
$AutoServ = "PolicyAgent"
$AutoServ = "dmserver"
$AutoServ = "Nla"
$AutoServ = "PlugPlay"
$AutoServ = "Spooler"
$AutoServ = "ProtectedStorage"
$AutoServ = "RpcSs"
$AutoServ = "SamSs"
$AutoServ = "lanmanserver"
$AutoServ = "Schedule"
$AutoServ = "LmHosts"
$AutoServ = "Themes"
$AutoServ = "upnphost"
$AutoServ = "AudioSrv"
$AutoServ = "SharedAccess"
$AutoServ = "winmgmt"
$AutoServ = "WZCSVC"
$AutoServ = "lanmanworkstation"

$AutoServName = "Application Layer Gateway Service"
$AutoServName = "Automatic Updates"
$AutoServName = "Background Intelligent Transfer Service"
$AutoServName = "COM+ Event System"
$AutoServName = "Computer Browser"
$AutoServName = "Cryptographic Services"
$AutoServName = "DCOM Server Process Launcher"
$AutoServName = "DHCP Client"
$AutoServName = "DNS Client"
$AutoServName = "Event Log"
$AutoServName = "IPSEC Services"
$AutoServName = "Logical Disk Manager"
$AutoServName = "Network Location Awareness (NLA)"
$AutoServName = "Plug and Play"
$AutoServName = "Print Spooler"
$AutoServName = "Protected Storage"
$AutoServName = "Remote Procedure Call (RPC)"
$AutoServName = "Security Accounts Manager"
$AutoServName = "Server"
$AutoServName = "Task Scheduler"
$AutoServName = "TCP/IP NetBIOS Helper"
$AutoServName = "Themes"
$AutoServName = "Universal Plug and Play Device Host"
$AutoServName = "Windows Audio"
$AutoServName = "Windows Firewall/Internet Connection Sharing (ICS)"
$AutoServName = "Windows Management Instrumentation"
$AutoServName = "Wireless Zero Configuration"
$AutoServName = "Workstation"


For $i=1 To 30
ToolTip(@CR&" 正在将如下服务调整为“禁用”: " & @CRLF & " " & $DisabledServName[$i] & " " & @CR, @DesktopWidth-260, @DesktopHeight-120)
RunWait("sc config " & $DisabledServ[$i] & " start= disabled","",@SW_HIDE)
Sleep($t)
ToolTip(@CR&" 正在停用: " & @CRLF & " " & $DisabledServName[$i] & " " & @CR, @DesktopWidth-260, @DesktopHeight-120)
RunWait("sc stop " & $DisabledServ[$i],"",@SW_HIDE)
Sleep($t)
Next

For $i=1 To 21
ToolTip(@CR&" 正在将如下服务调整为“手动”: " & @CRLF & " " & $DemandServName[$i] & " " & @CR, @DesktopWidth-260, @DesktopHeight-120)
RunWait("sc config " & $DemandServ[$i] & " start= demand","",@SW_HIDE)
Sleep($t)
If $i=6 Or $i=12 Or $i=16 Or $i=17 Then
ToolTip(@CR&" 正在启用: " & @CRLF & " " & $DemandServName[$i] & " " & @CR, @DesktopWidth-260, @DesktopHeight-120)
RunWait("sc start " & $DemandServ[$i],"",@SW_HIDE)
Sleep($t)
Else
ToolTip(@CR&" 正在停用: " & @CRLF & " " & $DemandServName[$i] & " " & @CR, @DesktopWidth-260, @DesktopHeight-120)
RunWait("sc stop " & $DemandServ[$i],"",@SW_HIDE)
Sleep($t)
EndIf
Next

For $i=1 To 28
ToolTip(@CR&" 正在将如下服务调整为“自动”: " & @CRLF & " " & $AutoServName[$i] & " " & @CR, @DesktopWidth-260, @DesktopHeight-120)
RunWait("sc config " & $AutoServ[$i] & " start= auto","",@SW_HIDE)
Sleep($t)
ToolTip(@CR&" 正在启用: " & @CRLF & " " & $AutoServName[$i] & " " & @CR, @DesktopWidth-260, @DesktopHeight-120)
RunWait("sc start " & $AutoServ[$i],"",@SW_HIDE)
Sleep($t)
Next

ToolTip(@CR&" 服务优化完成! " & @CR, @DesktopWidth-260, @DesktopHeight-120)
Sleep(3000)

netegg 发表于 2010-9-28 04:46:56

脚本做成这样不如用批处理了

zhuqingedu 发表于 2010-9-28 09:10:45

批处理的话会有问题,比如某些服务已经启动了,如果再用批处理去启动或者某些服务已经停止了,如果再用批处理去停止的话就会收到一个错误提示:
StartService 失败 1056:服务的实例已在运行中。
ControlService 失败 1062:服务尚未启动。
如果中途遇到错误还会中断,这种错误提示会使用户产生不安,而且批处理的体验也没有脚本编译成EXE后的体验好。

shenrenba 发表于 2010-9-28 10:24:29

$scr = MsgBox(1, "", "是继续,否关闭!")
If $scr = 1 Then
        MsgBox(0, "", "只是个举例!")
Else
        Exit
EndIf

netegg 发表于 2010-9-28 10:27:45

回复 3# zhuqingedu

你这样操作了,该错还是错

zhuqingedu 发表于 2010-9-28 12:17:07

回复 4# shenrenba

谢谢shenrenba ,我的问题已经解决了,呵呵。

zhuqingedu 发表于 2010-9-28 12:17:56

回复zhuqingedu

你这样操作了,该错还是错
netegg 发表于 2010-9-28 10:27 http://www.autoitx.com/images/common/back.gif

呵呵,建议这位朋友可以把优化服务的脚本和批处理分别在同一台机器上重复运行,就知道哪个会出错了。

netegg 发表于 2010-9-28 15:43:02

回复 7# zhuqingedu
我不用外部文件操作服务

hzxymkb 发表于 2010-9-28 16:26:13

楼主,在天空论坛我已经回复你了!你去看看吧!
如果已经解决了问题,请修改标题为[已解决],谢谢!

zhuqingedu 发表于 2010-9-28 19:23:55

楼主,在天空论坛我已经回复你了!你去看看吧!
如果已经解决了问题,请修改标题为[已解决],谢谢!
hzxymkb 发表于 2010-9-28 16:26 http://www.autoitx.com/images/common/back.gif

呵呵,原来天空论坛的那个热心朋友就是你呀,真是太感谢你了,我这就去修改标题。

hzxymkb 发表于 2010-9-28 20:47:23

回复 10# zhuqingedu
楼主 呀!我的意思是叫你修改本帖子的标题呀!

zhuqingedu 发表于 2010-9-28 20:49:31

噢,这样啊,我还跑去修改天空的帖子了,哈哈。

leon460 发表于 2010-11-2 16:19:20

逛逛,看看大家的新作

baijiri 发表于 2011-1-20 09:37:03

{:face (427):}

qq309266378 发表于 2012-7-22 23:24:29

最近也在研究系统服务,嘿嘿。
页: [1]
查看完整版本: [已解决]关于系统服务优化脚本的修改