您好,欢迎访问三七文档
脚本服务相关更改服务帐户密码描述更改在假定的服务帐户Netsvc下运行的任何服务的服务帐户密码。脚本代码以下是代码片段:strComputer=.SetobjWMIService=GetObject(winmgmts:_&{impersonationLevel=impersonate}!\\&strComputer&\root\cimv2)SetcolServiceList=objWMIService.ExecQuery_(Select*fromWin32_Service)ForEachobjserviceincolServiceListIfobjService.Startname=.\netsvcThenerrReturn=objService.Change(,,,,,,,password)EndIfNext配置服务错误控制代码描述将所有的自动启动服务配置为在服务启动失败时发出警报。脚本代码以下是代码片段:ConstNORMAL_ERROR_CONTROL=2strComputer=.SetobjWMIService=GetObject(winmgmts:_&{impersonationLevel=impersonate}!\\&strComputer&\root\cimv2)SetcolServiceList=objWMIService.ExecQuery_(Select*fromWin32_ServicewhereErrorControl='Ignore')ForEachobjServiceincolServiceListerrReturn=objService.Change(,,,NORMAL_ERROR_CONTROL)Next配置服务启动选项描述禁用所有配置为手动启动的服务。除了别的之外,这会使得PowerUser不能启动这些服务。脚本代码以下是代码片段:strComputer=.SetobjWMIService=GetObject(winmgmts:_&{impersonationLevel=impersonate}!\\&strComputer&\root\cimv2)SetcolServiceList=objWMIService.ExecQuery_(Select*fromWin32_ServicewhereStartMode='Manual')ForEachobjServiceincolServiceListerrReturnCode=objService.Change(,,,,Disabled)Next确定在某个进程中运行的服务描述返回在Services.exe进程中运行的服务的列表。脚本代码以下是代码片段:strComputer=.SetobjWMIService=GetObject(winmgmts:_&{impersonationLevel=impersonate}!\\&strComputer&\root\cimv2)SetcolListOfServices=objWMIService.ExecQuery_(Select*fromWin32_Service)ForEachobjServiceincolListOfServicesIfobjService.PathName=C:\WINDOWS\system32\services.exeThenWscript.EchoobjService.DisplayNameEndIfNext确定在所有进程中运行的服务描述返回进程列表以及当前在每个进程中运行的所有服务。脚本代码以下是代码片段:setobjIdDictionary=CreateObject(Scripting.Dictionary)strComputer=.SetobjWMIService=GetObject(winmgmts:_&{impersonationLevel=impersonate}!\\&strComputer&\root\cimv2)SetcolServices=objWMIService.ExecQuery_(Select*fromWin32_ServiceWhereState'Stopped')ForEachobjServiceincolServicesIfobjIdDictionary.Exists(objService.ProcessID)ThenElseobjIdDictionary.AddobjService.ProcessID,objService.ProcessIDEndIfNextcolProcessIDs=objIdDictionary.ItemsFori=0toobjIdDictionary.Count-1SetcolServices=objWMIService.ExecQuery_(Select*fromWin32_ServiceWhereProcessID='&_colProcessIDs(i)&')Wscript.EchoProcessID:&colProcessIDs(i)ForEachobjServiceincolServicesWscript.EchoVbTab&objService.DisplayNameNextNext确定可以暂停的服务描述返回可以暂停的服务的列表。脚本代码以下是代码片段:strComputer=.SetobjWMIService=GetObject(winmgmts:_&{impersonationLevel=impersonate}!\\&strComputer&\root\cimv2)SetcolServices=objWMIService.ExecQuery_(Select*fromWin32_ServiceWhereAcceptPause=True)ForEachobjServiceincolServicesWscript.EchoobjService.DisplayNameNext确定可以停止的服务描述返回可以停止的服务的列表。脚本代码以下是代码片段:strComputer=.SetobjWMIService=GetObject(winmgmts:_&{impersonationLevel=impersonate}!\\&strComputer&\root\cimv2)SetcolServices=objWMIService.ExecQuery_(Select*fromWin32_ServiceWhereAcceptStop=True)ForEachobjServiceincolServicesWscript.EchoobjService.DisplayNameNext枚举单个服务的前项服务描述枚举必须在启动SMTP服务之前运行的所有服务。脚本代码以下是代码片段:strComputer=.SetobjWMIService=GetObject(winmgmts:_&{impersonationLevel=impersonate}!\\&strComputer&\root\cimv2)SetcolServiceList=objWMIService.ExecQuery(Associatorsof_&{Win32_service.Name='SMTPSVC'}Where_&AssocClass=Win32_DependentService&Role=Dependent)ForEachobjServiceincolServiceListWscript.EchoobjService.DisplayNameNext枚举单个服务的依赖服务描述枚举不能在启动Rasman服务之前启动的所有服务。脚本代码以下是代码片段:strComputer=.SetobjWMIService=GetObject(winmgmts:_&{impersonationLevel=impersonate}!\\&strComputer&\root\cimv2)SetcolServiceList=objWMIService.ExecQuery(Associatorsof_&{Win32_Service.Name='rasman'}Where_&AssocClass=Win32_DependentService&Role=Antecedent)ForEachobjServiceincolServiceListWscript.EchoobjService.DisplayNameNext枚举所有服务的依赖服务描述枚举所有安装在计算机上的服务的依赖服务。脚本代码以下是代码片段:ConstForAppending=8SetobjFSO=CreateObject(Scripting.FileSystemObject)SetobjLogFile=_objFSO.OpenTextFile(C:\Scripts\Service_Dependencies.csv,_ForAppending,True)objLogFile.Write(ServiceDependencies)objLogFile.WriteLinestrComputer=.SetobjWMIService=GetObject(winmgmts:&_{impersonationLevel=Impersonate}!\\&strComputer&\root\cimv2)SetcolServices=objWMIService.ExecQuery(Select*fromWin32_Service)ForEachobjServiceincolServicesstrServiceRegistryName=objService.NamestrServiceDisplayName=objService.DisplayNameSetcolDependentServices=objWMIService.ExecQuery(Associatorsof&_{Win32_Service.Name='&strServiceRegistryName&'}&_WhereAssocClass=Win32_DependentServiceRole=Antecedent)IfcolDependentServices.Count=0ThenobjLogFile.Write(strServiceDisplayName&,None)objLogFile.WriteLineElseobjLogFile.Write(strServiceDisplayName&,)ForEachobjDependentServiceincolDependentServicesobjLogFile.Write(objDependentService.DisplayName&,)NextobjLogFile.WriteLineEndIfNextobjLogFile.Close枚举非活动服务描述返回安装在计算机上目前已经停止的所有服务的列表。脚本代码以下是代码片段:strComputer=.SetobjWMIService=GetObject(winmgmts:&_{impersonationLevel=Impersonate}!\\&strComputer&\root\cimv2)SetcolStoppedServices=objWMIService.ExecQuery_(SELECTDisplayName,StateFROMWin32_ServiceWHEREState'Running')ForEachobjServiceincolStoppedServicesWscript.EchoobjService.DisplayName&=&objService.StateNext枚举服务加载顺序组描述返回计算机上的所有服务加载顺序组的列表以及它们的加载顺序。有关在这段代码中使用的Win32_LoadOrderGroup类别的更多信息,请单击此处。支持平台Windo
本文标题:脚本 服务相关
链接地址:https://www.777doc.com/doc-1601400 .html