Remotely Start Business Object Service
By nater

'********************** Gets information and connects to remote computer**********************

Dim strCredentials, arrCredentials, strUser, strPassword, strNamespace, strLocalComputer, strComputer, strService, objService

'On Error Resume Next

Const WbemAuthenticationLevelPktPrivacy = 6

'strCredentials = InputBox ("Please enter the user name, a blank space, and then the password:", "Enter User Credentials")

'If strCredentials = "" Then
'Wscript.Quit
'End If

'arrCredentials = Split(strCredentials," ")
'strUser = arrCredentials(0)
'strPassword = arrCredentials(1)

struser = "YOUR USER"
strPassword = "YOUR PASSWORD"
strNamespace = "root\cimv2"

Set objNetwork = CreateObject("Wscript.Network")
'strLocalComputer = objNetwork.ComputerName

strComputer = InputBox ("Please enter the name of the computer you to restart the Central Managment Server for Buisiness Objects :", "Enter Computer Name", strLocalComputer)

If strComputer = "XXX" then
answer = msgbox ("You chose to enable XXX's Central Managment Server " & Vbcrlf & " Do you wish to Continue", 4, "Central Managment Server")

elseIf strComputer = "XXX" then
answer= msgbox ("You chose to enable XXX's Central Managment Server " & Vbcrlf & " Do you wish To Continue", 4, "Central Managment Server")

Elseif strComputer = "" Then
wscript.echo "Script Terminited Invalid Entry or Canceled"
Wscript.Quit

Else
wscript.echo "You entered a computer that is not listed in this script as a Buisisness Object server." & Vbcrlf & "This B'O, ilator Script is Terminated"
wscript.quit
End If
If Answer = 7 Then
Wscript.echo "Script Terminating due to user input"
wscript.quit
Else

End If
Call RestartServices()


'********************************************************************************
'************************* List services*****************************************
'******************* This is not called in this script***************************
'********************************************************************************

'Sub Qryservices

'Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
'Set objWMIService = objwbemLocator.ConnectServer (strComputer, strNamespace, strUser, strPassword)
'objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy


'Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & strComputer & "\root\cimv2")

'Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")

'For Each objService in colRunningServices
'Wscript.Echo objService.Name & VbTab & objService.State
'Next

'End Sub

'********************************************************************************
'********************************************************************************

Sub RestartServices()

strService = "BOBJCentralMS"
strServiceDisplay = "Central Management Server"



Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer (strComputer, strNamespace, strUser, strPassword)
GetObject("winmgmts:{impersonationLevel=impersonate}!\.\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name='" & strService & "'")



For Each objService In colServiceList
'Wscript.echo "Hello"
'wscript.echo "this is the status" & objService.DisplayName & "=" & objService.State


'********** Does some checking to ensure the you are working with the right service****************************
'******easier way to do this , but this is the safest since you need to manually add the desc in this sub******


If objService.DisplayName & "=" & objService.State = strServiceDisplay & "=Running" Then
Answer = Msgbox ("The service reported that it is already in a RUNNING state" & Vbcrlf & "Would you like to Cycle the Central Managment Service", 4, "ATTENTION SPARTONIAN")
If Answer = 7 Then
wscript.echo "Terminating this script"
wscript.quit
Else
Call Cycleserv
End If
Else If objService.DisplayName & "=" & objService.State = strServiceDisplay & "=Stopped" Then
'wscript.echo "the service Is not started going to start it"
Call StrtServ()
End If

End If

Next
End Sub
'wscript.quit



'*************************************************************************************************************
'*****************************If you want to disable the service First for a restart**************************
'*************************************************************************************************************

Sub Cycleserv

'wscript.echo struser & strService
Answer = msgbox ("WARNING, THE SERVICE IS ALREADY STARTED, ARE YOU SURE YOU WANT TO CYCLE THIS SERVICE, This may kick users out of the system", 1, "WARNING")
If Answer = 2 Then
wscript.echo "Terminating the script"
Wscript.quit
Else
End If






Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer (strComputer, strNamespace, strUser, strPassword)
GetObject("winmgmts:{impersonationLevel=impersonate}!\.\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name='" & strService & "'")



For Each objService In colServiceList
WScript.Echo "Stopping: " & objService.DisplayName
WScript.sleep 10000
intResult = objService.StopService()
'msgbox "Result: " & intResult , 4
If intReult = 0 Then
Else
wscript.echo "There was an error stopping this service please log into the server to investigate"
wscript.quit
End If
Next

Call StrtServ()

End Sub


'************************************Start The service********************************************************
'**************************************************************************************************************
Sub StrtServ



Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer (strComputer, strNamespace, strUser, strPassword)
GetObject("winmgmts:{impersonationLevel=impersonate}!\.\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name='" & strService & "'")



For Each objService In colServiceList
intResult = objService.StartService()

WScript.Echo "Starting: " & objService.DisplayName
WScript.sleep 10000
'WScript.Echo "Result: " & intResult
If intReult = 0 Then

Else
wscript.echo "There was an error stopping this service please log into the server to investigate"
wscript.quit
End If
Next

End Sub





Wscript.echo "No errors were reported. You can run this script again to verify the service is started"
Set objWbemLocator = Nothing
Set colServiceList = Nothing
Wscript.echo "All Finished"

Rating:


4/5 based on 1 vote. The median rating is 4.

Submitted: 11/19/10 (Edited 11/19/10)

Description: The service can be changed to any service. This was written for our downtime and uptime procedures of a database that Business Objects used. It contains error checking and prompt features.

Tags:

Views: 176 views. Averaging 0 views per day.
In the most recent 30 day period, there've been 0 views.

Similar Articles:
Sony to Start TV Streaming Trials, Service Won't B
Sony to Start TV Streaming Trials, Service Won't B
Sony to Start TV Streaming Trials, Service Won't B
U.S. Telecom Firms Can Now Do Business in Cuba -
1.5 Million Verizon Business Customers Had Their D

Next Article