Solved

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

Posted on 2010-08-29
6
412 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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 …

751 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