Windows Task Scheduler & Administrator user - windows

I have to run automatically a batch file once a week to update a file.
To do so I have created a task with Windows Task Scheduler on the company Server with the following options:
Security Options: user me, run only when user is logged in, Configure for Windows Server 2012
Trigger: every Monday at 11.00am
Action: start a program (the path to the bat file with quote)
This configuration works fine. However I wish the update to happen even if I am not here.
So I tried to change to Security Options to:
User: administrator (with batch job rights)
Run whether user is logged on or not
Run with Highest privileges
Trigger and action are unchanged.
I have also entered the admin password when saving the task.
On the Task History the action and task are completed, but the bat file is not run and there is no update happening on my file.
The Last Run Result display:
Incorrect function (0x80070001).
Looking at other posts I have tried different combination:
Run with Highest privileges: ticked or not
The path to the bat file with or without quote
Try to add the path without quote in Start in (optional)
None of these worked. Any idea?
The code is working fine when activated manually. I am not sure what you mean by the command that start the batch.
In the Scheduler it is on the Action tab. The action is start a program and the details is the path to the file ...run.bat
When launch manually I right click on the file and select run as administrator.
Thank you in advance for your help.
Sylvie

had the same problem with a RScript.exe with batch .R file. Runs perfect with main user, also in command line, but when setting the 'run with different user account' it fails.
What I did: added the ScriptUser (an anonymous user that will work forever when I have left the building) to the group Power Users. (Ok, I don't think you are allowed to set it to Administrator). But local\powerusers did it for me. The strange 'Incorrect function' without any details is solved now.
V

I have been having similar issues with a new scheduled task I was setting up. I could run the .exe no problem by itself by clicking on it, but when task scheduler would run it, the app would execute instantly and return a success, but did not actually execute. For us, the solution was to include the Start in folder on the Action tab where you specify the application location. Leaving this value blank will default to the root directory where the most things do not have permission to run.
Task Scheduler Action Settings:

Related

Open visible window from invisible BAT window on startup

I'm writing this little program that prevents scheduled tasks from being added into the system without user's knowledge https://github.com/DVLP/Unscheduler
Some background about how the program works
install.bat creates a snapshot of current scheduled tasks is being recorded and a new task is being added check.bat to run on each logon
Every time check.bat runs it fetches list of all scheduled tasks and compares it with snapshot
When a task is not in snapshot its being displayed on the list
Now the user can press a number to delete any new entry
When happy, the user presses "S" to save a new snapshot
That's all
It's all working fine on my computer but in step 2 on each logon a window appears even if no entries are present.
Finally the actual question:
How do I first run it in a hidden way and only display the window (or re-run it visible) when there are new entries detected?
Currently the window is either - running as System - always invisible
OR running as user - always visible
I know about "runas" but that requires prompting for user password. Everything now works fine without prompting for password so prompting even once during install.bat is not an option.
Found a workaround by creating two tasks
-FirstTask is running invisible as System on every logon
-SecondTask is created as user's task to run only once - in 50 years(never, basically only there to be triggered manually)
-When the first task detects new entries it's using schtasks /run /ts SecondTask to run the second task with visible window allowing user interaction

Counting computer login times for the week

I am probably asking this question in the wrong place (Maybe I should go to an OS forum) - but I still want to know this.
I am using a windows- 7 machine for my work. I log in everyday, do some work and then log off. I take a few short breaks in between when I Lock (Windows+L) my laptop.
I have to account for the number of hours worked by the end of the week which means the time for which I was logged in to this machine.
The problem is that I do complete all the work that is assigned to me, but I forget to keep track of the exact hours I was logged into this machine. I may have logged in at 5 am in the morning and then logged off at 3 in the afternoon- and I dont have any manual logs of my time.
Is there someplace where windows keep a weekly track of
Say per day:
"The Latest log-off time - The Earliest Log in time" into that system for a particular day. I only need these logs for a week.
any heads up would be appreciated. Thanks
I have tried to solve this problem for years, but only recently found a solution that:
May be implemented without administrative privileges
Does not require extra software
Kudos to Guiding Tech for providing the solution shown below. Change the suggested folder and filenames as you desire, but adjust the batch file code and Task Scheduler commands accordingly.
Part One: Create the script
Create the folder where you would like the script and text log file of login and lock/logoff to reside. For this example, I will presume the desired folder is "C:!Scripts\Login\"
Create a new text file in the folder and name it login.bat. A quick way to do this is to right-click a blank space in the folder view, and select New > Text Document, then name it login.bat.
Open the text file and copy and paste in the following code:
echo off
set datecode=%date:~-4%-%date:~7,2%-%date:~4,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
if "%1"=="i" echo %datecode% - Logged in >> C:\!Scripts\Login\login.txt
if "%1"=="o" echo %datecode% - Locked computer >> C:\!Scripts\Login\login.txt
Save the new batch file
Part Two: Create the login task
Open Task Scheduler. Press the Windows key, and then type "Task Scheduler" and click on the application that appears with that name. Alternatively, use Start > Run (Win + R), type taskschd.msc and press Enter.
Select Create Task... from the actions on the right hand side
Enter a task name like "Log the login date and time"
Click on the Triggers tab and add a new trigger. Select:
Begin the task: At log on
Specific user: This should be your Windows account name.
Click OK to add the trigger.
Add another trigger, except this time select Begin the task: On workstation unlock. Click OK to add the trigger.
Click on the Actions tab. Add a new action and point it to your login script with the argument i.
Click OK to add the action.
7. (Optional – Only required if you are using a laptop) Click on the Conditions tab and uncheck the box that says Start the task only if the computer is on AC power. Click on OK to create the task.
Part Three: Create the lock task
In Task Scheduler, select Create Task… from the actions on the right hand side.
Enter a task name like Log the lock date and time.
Click on the Triggers tab and add a new trigger. Select:
Begin the task: On workstation lock
Specific user: This should be your Windows account
Click OK to add the trigger.
Click on the Actions tab. Add a new action and point it to your login script with the argument o.
Click OK to add the action.
(Optional – Only required if you are using a laptop) Click on the Conditions tab and uncheck the box that says Start the task only if the computer is on AC power. Click on OK to create the task.
Part Four: Testing that everything is working as expected
Your work is now complete. You just need to test that everything is working as expected. Just lock your computer by hitting WIN+L and log back in. If you followed the instructions properly, you should now have a file called login.txt in the same folder as your script. This file should contain a log of each time you log in and out of your computer.
You can use the event log to check when you logged in and logged put (or locked the PC for that matter) but you would have to do that by hand.. You could write a program to do that but that would be hard.
BTW: You will need to enable a group policy or something to enable login events. Have a look here

Windows 7 scheduled task "runs" but doesn't DO anything

I have a vbscript file that must run under 32bit on a 64 bit Windows 7 machine so that it can connect to a 32 bit Access database. From a run box I can enter:
C:\Windows\SysWow64\WSCRIPT.EXE P:\Applicants\Applicants.wsf
and it runs great. When I try to run this as a scheduled task, it runs in under a second (it shouldn't be that fast) and claims it finished successfully. This is the 'action' I am running it under currently:
Start a Program
C:\Windows\SysWow64\WSCRIPT.EXE
Arguments: //Nologo //B P:\Applicants\Applicants.wsf >> P:\Applicants\logfile.txt
I have also tried running it under CScript instead of WScript and the result is exactly the same.
Before I added "//Nologo //B" (a tip I found here) it would start running and never stop.
The optional "Start In" box is empty. If I put any value in it at all (tried P:\Applicants) the task fails to start with "Error Value: 2147942667." No solutions offered by searching this error code have worked so I leave this box empty.
The logfile never even gets created and none of the work the script performs is getting done.
The task runs under my network account and should have access to all needed drives and resources.
Suggestions? Without a logfile I don't even know where to begin troubleshooting this thing.
EDIT: New Info: If I set it to run only when I am logged in it works fine. It is only when set to run even if user is logged off that it doesn't work, even if I am logged in when it runs.
EDIT 2: Security context of 'run even if user is logged off' states that ""...select the radio button labeled Run whether user is logged on or not. If this radio button is selected, tasks will not run interactively. To make a task run interactively, select the Run only when user is logged on radio button."
So I guess it thinks my script is somehow interactive, but it isn't. There aren't any kind of prompts or dialog boxes or msgBox calls so I'm not sure why this would be an issue.
Got it! The problem was that I was referencing a mapped drive with P:\ both in the 'action' call and in the script itself. When I replaced all calls to the P drive with the full network path \server\share everything works fine. Of course mapped drives aren't available if I'm not logged in, makes perfect sense :p
You have two options.
1.Create a batch file with the command to run, then schedule the batch file to run instead of the VBScript file.
2.Run the script file directly, instead of using WScript or CScript.
Sources: http://social.technet.microsoft.com/Forums/en-US/windowsserver2008r2general/thread/464a3bb3-3bcd-47a0-ab03-f0b8910f2ed1/

Windows 2008 RC2 doesn't start scheduled tasks

We have problem with scheduled tasks on Windows Server 2008 RC2.
Lets say that I want to open Firefox browser, everyday at same time, using batch file(we actually want to run Selenium tests, but I simplified problem).
I set it, and it run fine, when I select 'Run this task when user is logged in'.
The problem is that we want to run this task, no matter if user is logged in or not, so we selected this option('Run tasks no matter if user is logged in or not'), selected 'Highest Priority' for this task, but it doesn't work. It showing that task is started, but browser is not opened.
Even when I manually run this task, when I am logged in, it still doesn't open browser(It works perfect when I select to run task only when user is logged in).
Administrators from our web hosting company told us that this is not possible, due some security issues, but I am sure there must be way to archive this.
Thanks in advance.
I had exactly the same problem that you describe, it was resolved by specifying the 'Start in' directory for the action. I simply entered the name of the folder where the command file was.
It now runs with 'Run whether user is logged in or not' selected and without checking 'Run with highest privileges.

Launch batch script before windows login window

I'm working on Windows Server 2003 and Windows server 2008.
I would like to start a batch script just before the login window is displayed.
I read about adding the script in the Group Policy editor (startup/shutdown) but it's not working (it worked for logon and logoff though).
An alternative would be to use the task scheduler service but it's not working either. Plus, I want to be able to see the results in a cmd window. That means the last alternative - creating a service to do the job - is not an option.
Do you have any idea ?
Thanks.
Control Panel -> Scheduled Tasks -> < follow the prompts>
Not as nice as a service, which you can start and stop through well-behaved commands, but if it is a service you want running at all times, it does the job.
Try adding your script as a user defined service
That way it will get executed before the login prompt;
http://support.microsoft.com/default.aspx?kbid=137890
Though this article says it can't be used for batch scripts, you can call the script from an executable.

Resources