hi
i do a simple vbscript to stop a service and have a simple log out.
It work but not properly.
Infact if service exist and it can be stopped ,in log file i read "Service Messenger Stopped",and all work well
but if not exist or it not stopped... the script finish and i read nothing in log file.
Why?
can tell me where is the error,so i can read "service Not stopped"?
Maybe i must insert a pause for wait response of negative stop?
this is the script
**********************************************************
strOutputFile="C:\shutdown.log"
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
If Err.Number then
Print "Error 0x" & CStr(Hex(Err.Number)) & _
" occurred in opening a filesystem object."
If Err.Description <> "" Then
Print "Error description: " & Err.Description & "."
End If
End If
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, Forappending, True)
If Err.Number then
Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred in opening file " _
& objOutputFile
If Err.Description <> "" Then
Print "Error description: " & Err.Description & "."
End If
End If
on error resume next
StrComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = 'Messenger'")
For Each objService in colListOfServices
objService.StopService()
if err.number<>0 then
objOutputFile.Writeline "Service Messenger Not stopped"
else
objOutputFile.Writeline "Service Messenger Stopped"
end if
next
WScript.Echo "Finished"
WScript.Quit(0)
*********************************************
i do a simple vbscript to stop a service and have a simple log out.
It work but not properly.
Infact if service exist and it can be stopped ,in log file i read "Service Messenger Stopped",and all work well
but if not exist or it not stopped... the script finish and i read nothing in log file.
Why?
can tell me where is the error,so i can read "service Not stopped"?
Maybe i must insert a pause for wait response of negative stop?
this is the script
**********************************************************
strOutputFile="C:\shutdown.log"
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
If Err.Number then
Print "Error 0x" & CStr(Hex(Err.Number)) & _
" occurred in opening a filesystem object."
If Err.Description <> "" Then
Print "Error description: " & Err.Description & "."
End If
End If
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, Forappending, True)
If Err.Number then
Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred in opening file " _
& objOutputFile
If Err.Description <> "" Then
Print "Error description: " & Err.Description & "."
End If
End If
on error resume next
StrComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = 'Messenger'")
For Each objService in colListOfServices
objService.StopService()
if err.number<>0 then
objOutputFile.Writeline "Service Messenger Not stopped"
else
objOutputFile.Writeline "Service Messenger Stopped"
end if
next
WScript.Echo "Finished"
WScript.Quit(0)
*********************************************