EzDevInfo.com

windows-task-scheduler interview questions

Top windows-task-scheduler frequently asked interview questions

Windows Task scheduler Winlogon events - logout not enough(?)

I created a powershell script that I want to run on every logout / restart / shut down.

For trigger I set a custom event: Log: System, Source: Winlogon, Event ID: 7002. I found the above event id somewhere on the internet - it stands for log out (AFAIK).

The problem is that it works only when I go and press Log Out. It doesn't when I want to Shut down or Restart the PC.

Should it even work? And if not, where can I find the other event ID's? How do I even look for them? (I mean what is their name?)


Source: (StackOverflow)

Is it possible to use the AT command to run a command every 5 minutes?

The Windows AT command has an "every" parameter, which can take days of the week, and a "time" parameter specifying the time of day, however I'd like to run a command every 5 minutes. Any way to do this? I've looked at some similar questions, but nothing gives an actual example of the command line syntax for this.

I'm running Windows 7. Thanks!


Source: (StackOverflow)

Advertisements

How to import a scheduled task automatically from an XML file?

I have created a scheduled task in Windows 7. The task is running perfectly well on my computer.

I have also exported the task to an XML file and want to create the same task on another computer automatically. How can I import the XML file pragmatically in Task Scheduler on the second computer?


Source: (StackOverflow)

Starting scheduled task by detecting connection of USB device

I know it has been discussed that it is not possible to start an application from an usb drive upon connection due to limitations of autorun (or autoplay??) in Win 7. But it is possible to create a scheduled task having an event type trigger. Surely there must be an event occurring when the drive -- or any USB device, for that matter -- is connected.

Does anybody have the slightest idea which Event ID should I use? Or at least what type of event? Where can I find the event in event viewer?


Source: (StackOverflow)

What is the difference between "stop the task if it runs longer than" inside Trigger and under Settings tab?

When I schedule a task in Windows Task Scheduler, I can set "stop the task if it runs longer than" inside task trigger or inside Settings tab.

If I set it inside the trigger it does not automatically populate into Settings, so I think it's different, but what is the difference and which one is better to use?


Source: (StackOverflow)

What windows 7 task scheduler event would respond to an idle END condition?

The Windows 7 task scheduler allows me to run a task when the computer goes idle, but there doesn't seem to be any obvious way to run a task when the computer resumes from idle, or is no longer idle.

Surely there's some event triggered in windows (an event log?) when the computer is no longer idle? Or some way to capture the fact that the computer is no longer idle, and respond to that with a scheduled task?

How would I do this?

Or, at worst, is there a command-line program somewhere that can invoke commands or events when the computer enters/exits idle status?

[UPDATE:] The approach in my reply to Diogo Rocha works. I created a null executable via py2exe out of this script:

import sys
import time

#restart a pause every twenty seconds, with two functions that call each other.

def call_pause():
    pause()

def pause():
    time.sleep(20)
    call_pause()

call_pause()

--and set up a scheduled task in Windows for which this is the exported HTML:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2012-04-27T17:40:46.8871631</Date>
    <Author>GENIUS-BREATH-COMPY</Author>
    <Description>This task runs ProgA when the computer enters an idle state, and terminates ProgA when the computer *leaves* an idle state. The is all for scheduled TaskB, which periodically runs a batch that tests whether ProgA is running. If ProgA is not running (because this task terminated it), ProgB runs (as the computer is NOT idle). If ProgA *is* running, TaskB's batch does not run ProgB.</Description>
  </RegistrationInfo>
  <Triggers>
    <IdleTrigger>
      <Enabled>true</Enabled>
    </IdleTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-18</UserId>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <Duration>PT1M</Duration>
      <WaitTimeout>PT0S</WaitTimeout>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>true</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>true</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
    <Priority>7</Priority>
    <RestartOnFailure>
      <Interval>PT1M</Interval>
      <Count>3</Count>
    </RestartOnFailure>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\path_to\nullExecutable</Command>
    </Exec>
  </Actions>
</Task>

And left my computer idle for 15 minutes. Task manager showed the null executable running. As soon as I moved the mouse, it took the computer out of idle, and the null executable vanished from the task list.

From here, it's a matter of setting up a task (or program--which I'm doing with Python and py2exe) that uses pslist (with an -accepteula switch so that on computers it's deployed to it will actually run the program) to check whether the null exe is running. If it is running, the %ERRORLEVEL% environment variable is set to 0 because pslist ran without error. If that environment variable is 1, it ran with an error (it didn't find the executable running). I'm exploiting that environment variable in a batch script to run another task if the computer is not idle.


Source: (StackOverflow)

Scheduling silent hourly Windows Defender definition updates using Task Scheduler on Windows 8

I want to update Windows Defender's definitions every hour and came up with the idea of using the Task Scheduler to execute the Defender update service with the signature update argument.

~/Windows Defender/MpCmdRun -SignatureUpdate

This works pretty well but opens up a cmd window every hour and I want to run it silently in the background.

I am aware of the registry mod that can be done to increase the update frequency but do not want to do that hack over and over again after critical Defender updates after which the registry goes back to the original settings.

I am not very familiar with cmd arguments. I know that some executables work with the /silent argument for background launching, but it doesn't help. What else can I try or use?


Source: (StackOverflow)

How can I allow non-administrators to use shutdown.exe?

As per the comments in the accepted answer to this question, I'm having issues running a scheduled task which calls shutdown.exe, even when the user is an administrator. I'm administrating someone else's machine using their main account, so I can't exactly change too much as they like things the way that they are.

What's really strange is that I can only make the task run if:

  1. The user is an administrator.
  2. They have defined a password.

For some strange reason unknown to me, not only does a user have to be an administrator, but they also must have a password on the account in order for the scheduled task to run. Otherwise, I get access denied errors and the task fails to run.

How can I make this work without having to force the user to define a password for their account?

Essentially, the remaining goal is to have the computer shut down (no matter who is or is not logged in) at 11pm every night.

I run into the following errors below when I try to set the task in the Scheduled Tasks program:

enter image description here

An error has occurred while attempting to set task account information.
The specific error is:
0x8007005: Access is denied.
You do not have permission to perform the requested operation.

For the record, here's my security policy, you can see that my user has the permission to force shutdown and manually shutdown the computer:

enter image description here


Source: (StackOverflow)

How to launch a GUI Windows application with administrator rights without asking for the pasword from the user?

The user using the computer logs-in to the Windows 7 Professional system through an Active Directory domain and has no administrative rights.

I am the administrator and can give him the rights but, for obvious reasons, don't want to.

The user needs to use one special application (a surveillance dashboard) that demands local administrative rights.

So I need the user to be able to run this (and only this) particular application in elevated rights mode without knowing the password (I don't mind to enter and save it for this shortcut but I couldn't find such an option). And/or (both, ideally) the application to start up (elevated) after the user logs in.

I understand that this is going to be a security breach anyway, but there is hardly any choice.

I have tried adjusting the shortcut properties in many different way with no luck - it still asks for an administrator credentials.

I have also tried experimenting with Task Scheduler but the best result I reached is the application running invisibly with no GUI shown (in all the other set-ups the task was just failing to start).

Any suggestions?


Source: (StackOverflow)

Automatically running a windows bat file after returning from idle

First off, the background on what I want to do:

I am running rosetta@home on my computers at home and work, and I often find minirosetta tasks stuck in memory when I resume using the computer after a long idle period. I haven't found any real solution to the problem so I am looking for a workaround solution that involves automatically killing the minirosetta tasks when I return from an idle state.

It is possible to kill tasks with a simple command line (in windows7):

taskkill /IM taskname.exe /F

So I am looking for a way to execute a batch script to kill minirosetta tasks when I return from idle mode. Does anyone know if I can use one of the event triggers under windows task scheduler to automatically run a bat file after returning from idle? I see many different possibilities for event triggers but no idea what to use for returning from idle.

Alternatively I could run an executable or bat file when idle, and this executable could wait for mouse/keyboard action before it runs a script to kill the minirosetta tasks. Is this possible with simple scripts or do I need to compile a windows exec?

Thanks


Source: (StackOverflow)

Using plink.exe or similar in a scheduled task (to be run continuously)

I've been trying to get plink.exe (from the maker of PuTTY) to establish a local SOCKS proxy to a remote site, as well as some tunnels.

The action is simply to start plink.exe with the right parameters. No questions there.

The conditions tie the start to an available network connection, which I thought to be sensible.

Then I also set it to:

  • Allow task to be run on demand
  • Run task as soon as possible after a scheduled start is missed
  • If the task fails, restart every: [1 minute]
  • If the running task does not end when requested, force it to stop

Now all of this works perfectly fine at system start. However, when I put the machine to sleep and wake it up again, this fails.

In fact right after waking up, the plink.exe console window is still visible, but disappears (likely because the SSH session from before the sleep long timed out). However, the status of the task is then still listed as Running although it's clearly gone (i.e. if I were to use CreateProcess, I'd be notified of the process having gone away).

The status means I have to explicitly End it and then explicitly Run it again.

Does anybody know a method by which I can essentially teach the scheduled tasks that it should restart the job when the process goes away? I have no idea what the exact metric is, but clearly the Running status I am observing is bogus.

The idea is to restart plink.exe (thus reestablishing the SOCKS proxy) whenever it goes down. Be that right after the startup and a failed connection attempt or be that after waking the machine up from sleep.

NB: I am looking for a solution that can work on both Windows 7 and Windows 10.


As per the suggestions in the comments, the following two settings have been changed:

Never turn off hard drive Don't allow computer to turn off NIC


Source: (StackOverflow)

Creating Task With a Batch File - run task as soon as possible if missed

When creating a task with a batch file or command line, how do I specify the following option?

Run task as soon as possible after a scheduled start is missed

I know that this option exists via the GUI, but I need to specify it via command line.


Source: (StackOverflow)

How to show command-line app started by Windows Task Scheduler?

I have created a task on Windows Task Scheduler to run a command-line app everytime I lock this machine. It works like a charm.

My question is: Is it possible to see the Command Prompt window when I unlock?

Note: This command line app will never finish by itself. It has to be stopped manually.


Source: (StackOverflow)

How can I cause Task Scheduler to "fail" if a dialog box returns a certain result?

I'm working on a VBScript to do a weekly reboot of all machines on our network. I want to run this script via Task Scheduler. The script runs at 3:00 AM, but there is a small chance that users may still be on the network at that time, and I need to give them the option to terminate the reboot. If they do so, I would like the reboot to occur the next night at 3:00 AM. I've set Task Scheduler up to repeat in this way.

So far, so good. The problem is that if the user selects "Cancel" in my script, the Task Scheduler does not see my task as failed, and won't run it again the next night.

Any ideas? Can I pass an errorcode to task scheduler or otherwise abort the task via VBScript?

My code is below:

Option Explicit
Dim objShell, intShutdown
Dim strShutdown, strAbort

' -r = restart, -t 600 = 10 minutes, -f = force programs to close
strShutdown = "shutdown.exe -r -t 600 -f"
set objShell = CreateObject("WScript.Shell")
objShell.Run strShutdown, 0, false

'go to sleep so message box appears on top
WScript.Sleep 100

' Input Box to abort shutdown
intShutdown = (MsgBox("Computer will restart in 10 minutes. Do you want to cancel computer     restart?",vbYesNo+vbExclamation+vbApplicationModal,"Cancel Restart"))
If intShutdown = vbYes Then
' Abort Shutdown
strAbort = "shutdown.exe -a"
set objShell = CreateObject("WScript.Shell")
objShell.Run strAbort, 0, false
End if

Wscript.Quit

Appreciate any thoughts.


Source: (StackOverflow)

How (behind-the-scenes) does Task Scheduler end tasks?

When Windows' Task Scheduler ends as task (either because the task exceeded the stop the task if it runs longer than timeout or because a user right-clicked on it and chose 'End'), what happens behind-the-scenes? Is a WM_CLOSE message sent to the task's executable? Is the OS asked to kill the task?

The fact that a task can be configured to if the running task does not end when requested, force it to stop (Task Properties, Settings tab) makes me think that first Task Scheduler sends a 'hey, I'd like you to close' message (like WM_CLOSE) to the executing task, then, if that message isn't acted on in a timely manner and if the 'force stop' option is configured, the OS is asked to kill the process.

I haven't been able to find documentation on this.


Source: (StackOverflow)