Windows Task Scheduler will run app only once - windows

So my situation is that I am running an app on the Windows Task Scheduler. This app is run once a day at 1pm. the app does some queries and transfers data to an FTP site. All that is working great except on the weekends when i am not here the app is run and the GUI is still displayed for me to review. This seems to make it stop running on the scheduler until I shut down the app. So on Saturday it will run and the app will remain displayed for me to review when I get back on Monday. but on Sunday when the scheduler attempts to run it again it will fail because the app has not been closed down.
First let me confirm that this is how the Task Scheduler is supposed to work. Second, what are my alternatives for scheduling to run every day and keep the GUI displayed so that I can review. The app can run multiple times as each session does not interfere with the other sessions. So if I'm gone for a week on vacation I would expect that when i get back that 7 instances of the app have been run and are waiting for my review.
Thanks
AGP

Your best bet is to eliminate the UI and log messages to the Event Log or a log file. The UI could be spawned from the CLI as a separate process if you prefer, but it should be done so in as its own non-child process.
Alternatively, you could run a batch file instead of the process directly. In the batch file, invoke "START path_to_exe" instead of the EXE. That will cause the batch file to "finish" instantly, and the exe to be run in its own process. This is not a good long term solution, but will give you a temporary solution to your immediate problem.

This is the default behavior of the Scheduled Task system, as it doesn't know that the job is complete until the application actually exits. Therefore, if your application is still open after 24 hours, the next run will simply be skipped because the current run is "still going" as far as the scheduler is concerned.
Personally I would re-visit the way that you handle your job process, as your are setting up a scenario that will be hard to manage long term.

I recommend writing to a log file instead of displaying a UI for any output and/or errors. This way, the application can write, then exit, and you can review the log at your convenience. This is a very common solution for automated processes.

Related

Schedule script on windows so that it should always be running in background when someone logins

I am a beginner at developing Windows apps. I have created a VB script that executes the EXE file in background. I have referred some articles online and scheduled the script with windows scheduler. Now Every time I log in to the computer, the script starts running in the background normally as expected. The problem occurs when I lock the computer for a long period of time, somehow script gets killed by Windows. If I try to log in again, script(which got killed) doesn't start once again.
I want the script to run every time the computer gets unlocked no matter whether the computer was restarted/power-on/woke up from sleep and it should start running the script. But I am unable to achieve this.
This is what my current trigger looks like . Please tell me if I am doing something wrong

How can I see all the processes that were run during a specific time period

I know that PS will show me all the currently running processes. But that won't show me anything that's started, then stopped, during some time span. Is there any other way that I can see all the processes that were run during some event?
I'm trying to setup a way of auditing all the processes that ran during a build compilation. I can use PS to check all the running processes at the start of the build, and even run it again at the end. And I can setup a separate thread that will run PS over and over and over again during the build to catch all the processes that might have been run in the middle. But is there some better way of accomplishing this task that I'm not aware of?
This build is being run on a mac, so it uses the mac version of bash.
After your processes have run you can go to the Console (in the Applications/Utilities Folder) and check the system logs for the time period of interest. Many messages are written so the narrower the time window the better.

UWP apps running background tasks when the app is closed

I want to run a background task for every 10 mins.As the UWP app will not always be opened.Is there a way to run a background task even when the app is closed(Not Running State)?
If the answer is NO,
Is there any another way other than Windows Services?
You can create BackgroundTask which run at the most every 15 minutes not less than that in UWP apps. for more details you can check this source.
Is there a way to run a background task even when the app is
closed(Not Running State)?
According to this document:
You can use background tasks to provide functionality when your app is
suspended or not running.
The 'not running' state in UWP is described in more detail here. It reads:
An app could be in this state because it hasn't been launched since
the last time the user rebooted or logged in. It can also be in this
state if it was running but then crashed, or because the user closed
it earlier.
This implies that the app simply needs to run once after installation to be able to successfully register a background task, which can then run even after your app is closed.
I want to run a background task for every 10 mins
Not sure I'm interpreting this correctly but I assume you mean you want to run some bit of code every 10 mins while your app is not running. Well there are two way that I can think of to achieve this.
Method 1:
While background tasks are meant to be very short-lived tasks, they may even be made to run indefinitely if:
extendedBackgroundTaskTime capability is added as a restricted
capability in your app's manifest file
Using this technique along with a simple timer mechanism would achieve the desired result.
Method 2 (more complicated but keeps background tasks short-lived):
Setup a DatagramSocket to a remote server which sends some data every 10 mins and register your background task with a SocketActivityTrigger.

Task Scheduler WorkItem Not Running

I have a very specific problem that I need fixing. The major issue is that I don't exactly know how to properly search the remnants of my problem on google. Therefore I am coming to StackOverflow for advice in hopes that someone will assist me.
Summary
So I am writing an application which is to be PCI-compliant for the company which I am starting. The application involves IPC (Inter-process communication) and two "watch-dog" apps which monitor the status of the main application. One of these "watch-dog" applications is an updater (sends an HTTP Request to the server looking for updates of the application).
So! This method which I am using to check the server if the application is up-to-date is using the WinInet library and InternetOpen() to send the request. Then read the response of the page and use GetCookie() to store the response in a buffer. It shall then parse the response accordingly.
If the response says that the current version of my application is less than the version located on the server. It will then tell the customer (user) that their application is out of date, and ask them whether or not they want to update the software. If they choose to update the software, it will perform a Download And Execute from the internet and launch the update-installer on the user's PC.
The Problem
Unfortunately, windows is very "secure" when it comes to having an "unauthorized" application send an HTTP Request to an outgoing url, let alone download something from the server then execute it on the users PC.
My conclusion to this issue was to add the watch-dog programs to the Task Scheduler. That way after the main application is run, it will spawn the watch-dog programs and check if they are running with NTAUTHORITY privileges (which are granted by the Task Scheduler).
After implementing the code to create the task and point it to the location of the watch-dog programs, naming it, writing a description and everything. I executed the program. It ran without errors though here the REAL PROBLEM:
1) Programs executes
2) Spawns watch-dog programs
3) Watchdog program checks for new version
4) Version is found
5) Installer is downloaded, execute ... but
6) The installer does not appear on the screen!
When I run my 'Process Hacker' application to monitor all process actions. I can see that the new installer is download & executed. It is running as NTAUTHORITY/SYSTEM just like the watch-dog programs but it doesn't appear on the system.
I made sure that in my code the status of the window is set to SW_SHOWNORMAL not SW_HIDE. I also made sure that all flags are set accordingly. Though it doesn't appear on the screen!
When I run the application without adding it to the Task Scheduler as my user without NTAUTHORITY/SYSTEM status and just regular user status. It executes (obviously since I am already running as administrator) -- everything works fine. But after adding it to Task Scheduler and having it run with SYSTEM level privileges. The window doesn't appear on the screen visually. Why's that?
I would greatly appreciate anyone that is able to assist me with this problem. Thank-you!
edit 1
Can anyone help me understand how this user applied his fix in the registry? By reading the problem I can somewhat interpret that he had the same issue as me.
App is invisible if started from Task Scheduler without any user logged in
In any case, I am trying to use the advice that Gisley gave me to run the application in Interactive Mode. Possibly going to try to give that a try. Still looking for more answers but I am going to be working no this none-the-less in the meantime.
edit 2
I tried setting the INTERACTIVE FLAG and it had no effect unfortunately.
Allow me to just emphasize my problem:
For example I write a program which has message boxes and put it in a loop.
for
message box
get current pid
make process in the task scheduler
spawn new process as the task scheduler proc with NTAUTHORITY/SYSTEM
kill last proc pid
end for
Then when I execute it:
I get the message box. Then after new process opens with NTAUTHORITY/SYSTEM the message box does not appear anymore.
Same for if I open a calculator for example.
System("cmd.exe start /c calc.exe")
Program runs... opens calculator
Program gets NTAUTHORITY/SYSTEM status
ON the next loop it executes the calc.exe
I see it in my task manager but it doesnt appear on the screen
I hope the above helped emphasize the core of my issue. I dont see the processes opened by the task scheduler process id with NTAUTHORITY/SYSTEM rights... I dont see the procs executed by it on my screen, though I see them in the task manager | process hacker and they are running with NTAUTHORITY/SYSTEM privileges too.
A shot in the dark - try running the task in interactive mode, but you'll need to have a user logged on.
https://superuser.com/questions/616206/run-interactive-task-even-if-user-is-not-logged-on-windows
Alternatively, or additionally, pass parameters to the installer so that it installs silently.
Silent installation of a MSI package

How to troubleshoot Windows Scheduled Task not running?

In the process of deploying our .net app, I've got about 20 scheduled tasks set up on a server, all of which basically do the same thing: invoke a small .net console app that pulls data from a SQL db and posts it to a web service. Each task invokes a separate copy of the app, each copy having a different lookup ID value in its config file.
All but two of these tasks run reliably every night. Two of the tasks seem to sporadically stop running from time to time, and it's currently a mystery as to why. When they stop running, the scheduled task interface correctly shows their last run date, which is a day or more behind the other tasks, which have continued to run at the scheduled time. The tasks which stopped running do not run again on their own, despite being indicated as scheduled to run every night. There are no errors recorded in the event log or in the scheduled task interface itself. And here's the strangest part to us: If I manually kick off the scheduled task, it runs fine, it invokes the .net console app and everything finishes without anomaly. And then it continues to run fine at its scheduled time, for days or weeks at a time, only to eventually fail, seemingly out of the blue. It appears both tasks always start to fail on the same night.
There's a "Last Result" column that should give you a code related to the task itself running (it's not going to have any kind of exception data). 0 means the task completed without errors. Anything else you can look up and see why the task won't start. If the task still seems to not be running, but you still see a 0 for the Last Result, that means there's something broken in your code, but it's exiting gracefully.
Did you set "Start in" property?
If these .NET console apps need app.config or some files located into their path, you have to set "Start in" property to "c:\your\app\path\, otherwise they start as if they are in the system directory, and they cannot find files they need!
Taskscheduler assumes on 64 bits systems that the applicaiton is 64 bit.
If it is 32 bit launch it from the 32 bit command line, i.e. if you want to run c:\program files (x86)\Myprogram\Program.exe, tell taskscheduler to launch:
%systemroot%\Syswow64\cmd.exe /C "c:\program files (x86)\Myprogram\Program.exe"
This forces it to launch from the 32 bit command-prompt and hence with 32 bit emulation.
I found this super helpful link :https://windowsreport.com/windows-scheduled-tasks-not-running/ for thorough debugging steps for many use cases.
In my case user account with which scheduler was configured to run was locked that stopped execution of scheduled tasks without any logs or reporting problem.
One reason for Scheduled Tasks not running occurs when associating them with a password-less Windows user account: by default Scheduled Tasks are prevented from running with a blank password. If you want to run a Scheduled Task from an account with no password you have to disable a system variable:
Go to: Start > Administrative Tools > Local Security Policy > Security Settings > Local Policies > Security Options
Select: "Accounts: Limit local account use of blank passwords to console logon only"
Disable this variable
Disclaimer: It´s not recommended to have accounts with no password.
The answer to the below SO question may also be highly relevant to people reading this question (but, NB, it describes only one possible specific problem with Scheduled Tasks and I believe neither of these questions is a duplicate of the other):
Why is my Scheduled Task updating its 'Last Run Time' correctly, and giving a 'Last Run Result' of '(0x0)', but still not actually working?
The summary of the answer given to that other question is that Windows 2012 Scheduled Tasks do not see the correct environment variables, including PATH, for the account which the task is set to run as.
In terms of more general Scheduled Task troubleshooting (as asked about in this question), you can test for this particular issue (e.g. running SET > test.txt in the task, as suggested in that answer), and once you can see it happening, you can work around it if it is affecting you.
In my case, the scheduled task wouldn't run even though it said last run was successful (0). It turned out to be that the windows user account that was running the jobs had become locked out. I only realized this because I tried editing the existing scheduled task, set the user account to the same one, then hit OK and it gave me an error about the account being locked out.
Maybe they hung and were still running?
You can click on the extras-menu and choose the menu entry to view the log, then notepad will open a log file from the task planner
I found this page helpful when I was trying to trouble-shoot a misbehaving Scheduled Task:
http://support.microsoft.com/kb/308558
Select View->Details to show the additional information, like Last Run Time, and Status, and this page gave me the meaning of the status/error code:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx
I discovered a similar issue February 23 2023 but my logs reveal it started mid January 2023.
My tasks had been working for many months without issue. The I began seeing the same error: The system cannot find the file specified. After all day testing and searching I found that a Windows update on Jan 10 2023 changed the way white space is handled. Formerly only needed one set of quotes. The command line help explains:
C:\> schtasks /create /?
==> Spaces in file paths can be used by using two sets of quotes, one
set for CMD.EXE and one for SchTasks.exe. The outer quotes for CMD
need to be double quotes; the inner quotes can be single quotes or
escaped double quotes:
SCHTASKS /Create
/tr "'c:\program files\internet explorer\iexplorer.exe' \"c:\log data\today.xml\""

Resources