To start or stop a windows service from SSIS package add a Script Task and in design script page use the below code. Replace the ComputerName and ServiceName accordingly.
Imports SystemImports System.DataImports System.MathImports Microsoft.SqlServer.Dts.RuntimeImports System.ServiceProcessPublic Class ScriptMainPublic SubMain ()Dim controller As New ServiceControllerDim serviceStatus As ServiceControllerStatusDim conter As Integer'Code below is to atop Window services.controller.MachineName = "ComputerName"controller.ServiceName = "ServiceName"If ((controller.Status.Equals(serviceStatus.Running)) Or (controller.Status.Equals(serviceStatus.Paused))) Thencontroller.Stop()controller.Refresh()End If'Code below is to start Window services.If ((controller.Status.Equals(serviceStatus.Stopped)) Or (controller.Status.Equals(serviceStatus.StopPending))) Thencontroller.Start()controller.Refresh()End If
No comments:
Post a Comment