管理和优化服务的vbs

本文介绍了一段VBScript脚本,用于批量修改Windows系统中特定服务的状态和启动类型。涉及的服务包括DFs、Error Reporting Service等,脚本通过Win32_Service WMI类来实现这些操作。
Dim SS, S

Dim szMsg, szTtl

Dim l

 

Set SS = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("Select * From Win32_Service")

szMsg = "执行了下列操作:" & vbCrLf

szTtl = "管理服务程序"

l = Len(szMsg)

 

For Each S In SS

 Select Case UCase(Trim(S.Name))

 Case "DFS":

  Call StopManual()

 Case "ERSVC":

  Call StopManual()

 Case "HELPSVC":

  Call StopManual()

 Case "MDM":

  Call StopManual()

 Case "MESSENGER":

  Call StopDisable()

 Case "SPOOLER":

  Call PrintSpooler()

 Case "REMOTEREGISTRY":

  Call StopDisable()

 Case "SCHEDULE":

  Call StopManual()

 Case "THEMES":

  Call Themes()

 Case "AUDIOSRV":

  Call WindowsAudio()

 Case "W32TIME":

  Call StopManual()

 End Select

Next

 

Set SS = Nothing

Set S = Nothing

 

If Len(szMsg) = l Then szMsg = "您的服务设置和本程序预期的一样!"

MsgBox szMsg, 4160, szTtl

 

'Distributed File System

'Error Reporting Service

'Help and Support

'Machine Debug Manager

'Task Scheduler

'Windows Time

Sub StopManual()

 Dim bFlg

 

 bFlg = False

 

 If StrComp(S.StartMode, "Manual", 1) Then

  S.ChangeStartMode("Manual")

  bFlg = True

 End If

 If StrComp(S.State, "Stopped", 1) Then

  S.StopService

  bFlg = True

 End If

 

 If bFlg Then szMsg = szMsg & vbCrLf & "停止" & S.Caption & "服务,并将其启动类型设为手动。"

End Sub

 

'Messenger

'Remote Registry

Sub StopDisable()

 Dim bFlg

 

 bFlg = False

 

 If StrComp(S.StartMode, "Disabled", 1) Then

  S.ChangeStartMode("Disabled")

  bFlg = True

 End If

 If StrComp(S.State, "Stopped", 1) Then

  S.StopService

  bFlg = True

 End If

 

 If bFlg Then szMsg = szMsg & vbCrLf & "停止并禁用了" & S.Caption & "服务。"

End Sub

 

'Print Spooler

Sub PrintSpooler()

 If StrComp(S.State, "Stopped", 1) or StrComp(S.StartMode, "Manual", 1) Then

  If MsgBox("您是否有打印机?", 4132, szTtl) = 7 Then

   S.ChangeStartMode("Manual")

   S.StopService

   szMsg = szMsg & vbCrLf & "停止并禁用了" & S.Caption & "服务。"

  End If

 End If

End Sub

 

'Themes

Sub Themes()

 If StrComp(S.State, "Stopped", 1) or StrComp(S.StartMode, "Manual", 1) Then

  If MsgBox("您是否要使用 XP 主题风格?", 4132, szTtl) = 7 Then

   S.ChangeStartMode("Manual")

   S.StopService

   szMsg = szMsg & vbCrLf & "停止并禁用了" & S.Caption & "服务。"

  End If

 End If

End Sub

 

'Windows Audio

Sub WindowsAudio()

 If StrComp(S.State, "Running", 1) or StrComp(S.StartMode, "Auto", 1) Then

  S.ChangeStartMode("Automatic")

  S.StartService

  szMsg = szMsg & vbCrLf & "自动启用了" & S.Name & "服务。"

 End If

End Sub  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值