Jump to content

Script to create Schedule Task to start PC Monitor


Recommended Posts

The more computers I add the more I see this being a problem whereby the Pulseway service doesn't always start when the computer is turned on. I've got to the point now where I set the PC Monitor service to delayed start each time I install a new device, however I've noticed on at least 2 computers this week that even this doesn't work and the service still hasn't started even though it is set to delayed.

What I would like is a script that will create a Windows Scheduled Task which would run at least once per day to start the service. I've tried manually creating a scheduled task to do this but I'm not sure what I'm doing wrong as it doesn't seem to work.

I'd like to know if anyone else has thought of doing this and if so how they got it to work.


Link to comment
Share on other sites

  • Staff

At first you need to find out why the Pulseway service fails to start. Please look in the System event log for entries from the "Service Control Manager" source related to Pulseway.

If the error is, that service failed to start in 30 seconds, then you can try to increase the startup timeout by running built in script 'Increase Windows Service Timeout at Startup' (You can adjust the timeout interval. In this script it is set to 60000ms [60 seconds]).

Link to comment
Share on other sites

  • 8 months later...

So, I was running into the same issue a while ago and decided to try and crack the puzzle.  It requires a couple of different things.

The first script you need is to generate a universal user name and password across all your client systems.  The reason for this is that in order to create a 'Scheduled Task' on the system, it requires an accompanying user account to be able to run the task. 

Once this was done, I really had to dig for this one, I created a PS script that creates a couple of files.  The first one is an XML file containing the settings for the scheduled task.  The other is a powershell script that the scheduled task executes to ensure the pulseway services is running.  I have mine set to check and make sure the service is running every hour.  

Here is the full script that you would put into pulseway.


# this script will create a scheduled task that runs a powershell script that checks to make sure the Pulseway service is running.

# This line deletes the task if it already exists.  That way if you make changes to the task it will create a fresh copy of it.
schtasks /delete /F /tn "Check Pulseway"

# working directory path
$workd = "c:\temp"

# Check to see if working directory exists and create if it does not.
If (!(Test-Path -Path $workd -PathType Container))
New-Item -Path $workd  -ItemType directory 

# Create a variable with the entire contents of the XML file used to create the scheduled task
$text = '<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
    <URI>\Check Pulseway</URI>
    <Principal id="Author">
  <Actions Context="Author">
      <Arguments>-ExecutionPolicy Bypass '+$workd+'\ChkPulse.ps1</Arguments>

# Create a variable containing the entire contents of the powershell script that checks to see if pulseway is running or not.
$text2 = 'function FuncCheckService{
$arrService = Get-Service -Name $ServiceName
$Start = "Started "

if ($arrService.Status -ne "Running"){
Start-Service $ServiceName
FuncCheckService -ServiceName "Pulseway"

# Pump the contents of the two variables into the actuall files to be used
$text | Set-Content $workd\ChkPulse.xml
$text2 | Set-Content $workd\ChkPulse.ps1

# Command that actually creates the scheduled task.  You will need to change UserName and Password to the universal admin creds that you may use.
schtasks.exe /create /xml "$workd\ChkPulse.xml" /tn "Check Pulseway" /ru UserName /rp Password

#Wait a couple seconds
Start-Sleep -s 2

# Delete the files when done.  Dont need anyone knowing my secrets!
del $workd\chkpulse.ps1
del $workd\chkpulse.xml

Link to comment
Share on other sites

  • 2 years later...

way too much work, this adds a script by currently logged in use or last logged in user if system is logged off, note this is a powershell script, also I  set its start time for before current time so it will only run if you manually start it but do what you will.


#By eDecisions

$TasknameStop = "ExplorerStop"
$TasknameStart = "ExplorerStart"
$lastlogon = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser")

SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStop /RU $lastlogon /TR "taskkill /f /im explorer.exe"
SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $TasknameStart /RU $lastlogon /TR "explorer.exe" 
start-sleep -s 1
schtasks /Run /TN $TasknameStop
start-sleep -s 1
schtasks /Run /TN $TasknameStart
start-sleep -s 1
schtasks /delete /tn $TasknameStop /f
schtasks /delete /tn $TasknameStart /f

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...