How can i set a delay start of a service. Script to do this.

Posted on 2010-08-29
Last Modified: 2012-06-21

How can i set a delay start of a service.
I want to run a script on all remote machines whose names are in a txt file.
So from next startup the service 'Sophos controlled" starts 3 min after start of machine.

Question by:bsharath
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5

Expert Comment

ID: 33556033
use sleep() method u can delay the out put
LVL 42

Expert Comment

ID: 33556043
create a task scheduler using schtasks.exe which upon logong wait 3 minutes and then start the u need a vb script which does that?the easiest thing to do is actually create the task scheduler and then export it as xml and save it somewhere.then the vb script will copy it to all machines from the txt file and run it remotely.the script will then import the xml and from now on and every logon, the task will wait 3 minutes and start the service.
LVL 42

Expert Comment

ID: 33556054
attached is the example xml i have exported which upon logon will run the vb script located under c:\temp\sophos_starter.vbsi'll post the script in a little while
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="">
    <Principal id="Author">
  <Actions Context="Author">

Open in new window

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 42

Expert Comment

ID: 33556097
found a shorter simpler way.change the words  to the actual service name.
Set objShell = CreateObject("WScript.Shell")
parameters = "/create /sc onlogon /TN SohposStarter /tr ""NET START <sophos controller>"""
objShell.Run "schtasks.exe " & parameters , 0 ,true

Open in new window

LVL 42

Expert Comment

ID: 33556174
i forgot the 3 mintes delay argument, so here it is:
Set objShell = CreateObject("WScript.Shell")
parameters = "/create /sc onlogon /TN SohposStarter /delay 0003:00 /tr ""NET START <sophos controller>"""
objShell.Run "schtasks.exe " & parameters , 0 ,true

Open in new window

LVL 42

Accepted Solution

sedgwick earned 500 total points
ID: 33556211
and here's the final script, looping through machines from the txt file and create the scheduler for each one
const MACHINES_LIST_FILE = "c:\temp\machines.txt"
Set objShell = CreateObject("WScript.Shell")
set objFSO = createobject("scripting.filesystemobject")
set objFile = objFSO.OpenTextFile(MACHINES_LIST_FILE, 1)
arrMachines = Split(objFile.ReadAll, vbNewLine)

for each strComputer in arrMachines
	if Trim(strComputer) <> "" then
		parameters = "/create /sc onlogon /s " & strComputer & " /TN SohposStarter /delay 0003:00 /tr ""NET START sophos controller"""
		objShell.Run "schtasks.exe " & parameters , 0 ,true
	end if

Open in new window


Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you haven’t already, I encourage you to read the first article ( in my series to gain a basic foundation of R and R Studio.  You will also find the …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question