Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write a script to start WinXP service

Status
Not open for further replies.

JRMS

MIS
Sep 4, 2003
144
US
I am currently attempting to come up with a script to start a service in Windows XP remotely. I did not know how to even get started. I know there are tools I can purchase to do so, but would like to generate a script.
 
Get yourself a copy of Scriptomatic. Free download from Microsoft.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Three options
Open services.msc - Action - connect to another computer and start the service.
Use GPO on W2k3 to start service automatically

or

Code:
Set objShell = Wscript.CreateObject("WScript.Shell")
On Error Resume Next
strComputer = InputBox("Start Service On Remote Computer") 
'Check if service is Running
  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
   Set colRunningServices =  objWMIService.ExecQuery ("Select * from Win32_Service Where Name = 'DcomLaunch'")
   For Each objItem In colRunningServices
   If objItem.State="Stopped" Then 
       Call SetManStart
   Else
       wscript.quit  
    End If
   Next

Sub SetManStart
'Set service to Manual
Set objWMIService = GetObject("winmgmts:" _ 
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set colServicesState = objWMIService.ExecQuery _ 
  ("Select * from Win32_Service where Name='DcomLaunch'") 
For Each objService in colServicesState 
	objService.ChangeStartMode("AUTO")
	wscript.sleep 5000
'Start service
If objService.State="Stopped" then 
 objService.StartService()
	wscript.sleep 2000
End If
Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top