Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-08-29
6
Medium Priority
?
416 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
  • 5
6 Comments
 

Expert Comment

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

Expert Comment

by:Meir Rivkin
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:Meir Rivkin
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 42

Expert Comment

by:Meir Rivkin
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:Meir Rivkin
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:
Meir Rivkin earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

879 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