Solved

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

Posted on 2010-08-29
6
404 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: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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now