Saturday, August 23, 2008

Oracle - Start / Stop services manually

As suggested by Fiza , i'll shared the script here

For both script , it didnt just start or stop the services , but also change the StartupType for each Oracle services. Please remove returnCode = objService.Change( , , , , "Manual") or returnCode = objService.Change( , , , , "Automatic") if you dont need this.

Stop the services (Save as StopServices.vbs)

strComputer = "."
intKira = 0
intFail = 0

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

strService = "Oracle"

Set colListOfServices = objWMIService.ExecQuery _
("SELECT * FROM Win32_Service WHERE Name LIKE '%" & strService & "%'")
For Each objService in colListOfServices

If objService.StartMode = "Auto" Then

returnCode = objService.Change( , , , , "Manual")

returnCode = objService.StopService()

If returnCode <> 0 Then
intFail = intFail +1
else
intKira = intKira +1
End If

End If

Next

if intKira > 0 then
msgbox "Stop Succeded : " & intKira & vbcrlf & "Failed : " & intFail
else
msgbox "Failed"
end if



Start the services {Save as StartServices.vbs)

strComputer = "."
intKira = 0
intFail = 0

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

strService = "Oracle"

Set colListOfServices = objWMIService.ExecQuery _
("SELECT * FROM Win32_Service WHERE Name LIKE '%" & strService & "%'")
For Each objService in colListOfServices

If objService.StartMode = "Manual" Then

returnCode = objService.Change( , , , , "Automatic")

returnCode = objService.StartService()

If returnCode <> 0 Then
intFail = intFail +1
else
intKira = intKira +1
End If

End If

Next

if intKira > 0 then
msgbox "Start Succeded : " & intKira & vbcrlf & "Failed: " & intFail
else
msgbox "Failed"
end if