Jump to content

Recommended Posts

Posted

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.

Thanks

  • Staff
Posted

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]).

  • 8 months later...
Posted

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">
  <RegistrationInfo>
    <Date>2017-04-10T10:47:49.7419447</Date>
    <Author>Author</Author>
    <URI>\Check Pulseway</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <Repetition>
        <Interval>PT1H</Interval>
        <StopAtDurationEnd>false</StopAtDurationEnd>
      </Repetition>
      <StartBoundary>2017-04-10T10:43:02</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-3327590030-3417645755-2999866733-1004</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>Powershell.exe</Command>
      <Arguments>-ExecutionPolicy Bypass '+$workd+'\ChkPulse.ps1</Arguments>
    </Exec>
  </Actions>
</Task>'

# Create a variable containing the entire contents of the powershell script that checks to see if pulseway is running or not.
$text2 = 'function FuncCheckService{
param($ServiceName)
$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

  • 2 years later...
Posted

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

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...