Solved

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

Posted on 2010-08-29
6
411 Views
Last Modified: 2012-06-21
Hi,

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.

regards
Sharath
0
Comment
Question by:bsharath
[X]
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
6 Comments
 

Expert Comment

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

Expert Comment

by:sedgwick
ID: 33556043
create a task scheduler using schtasks.exe which upon logong wait 3 minutes and then start the service.do 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.
0
 
LVL 42

Expert Comment

by:sedgwick
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="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2010-08-30T09:13:04.8790634</Date>
    <Author>SOAP\meirr</Author>
  </RegistrationInfo>
  <Triggers>
    <LogonTrigger>
      <Enabled>true</Enabled>
    </LogonTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <IdleSettings>
      <Duration>PT10M</Duration>
      <WaitTimeout>PT1H</WaitTimeout>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>c:\temp\sophos_starter.vbs</Command>
    </Exec>
  </Actions>
</Task>

Open in new window

0
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

by:sedgwick
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

0
 
LVL 42

Expert Comment

by:sedgwick
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

0
 
LVL 42

Accepted Solution

by:
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)
objFile.Close

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
next

Open in new window

0

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 (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) 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