我有一个启动脚本,根据所使用的操作系统,为MySQL服务器复制一些ini文件。该脚本在WinXP上运行正常但在Win7中它不会停止服务。没有报告错误。该脚本似乎运行正常,除非在服务运行时不复制ini文件。
我已删除代码的停止服务部分并将其自身放入脚本中。但是,它仍适用于WinXP而不适用于Win7。
任何人都可以看到脚本无法正常工作的原因吗?
Sub StopService(computerName, serviceName)
Dim service
Set service = GetService(computerName, serviceName)
If(service Is Nothing) Then
Call Log.Warning("The " & serviceName & " service on the " & computerName & " computer was not found")
Else
service.StopService()
End If
End Sub
Function GetService(computerName, serviceName)
Dim wmiService, objectsList, eObjectsList, ObjService, item, sysID
Set wmiService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & computerName & "\root\cimv2")
Set objectsList = wmiService.ExecQuery("Select * from Win32_Service Where Name = '" & serviceName & "'")
For Each ObjService in objectsList
If(ObjService.Name = serviceName) Then
Set GetService = ObjService
Exit Function
End If
Next
Set GetService = Nothing
End Function
StopService ".", "MySQL56"
感谢您的帮助,
查尔斯