Run whether user is logged on or not in Task scheduler - windows

I scheduled batch file using Task scheduler on Windows server 2012 R2, but it's working with only "Run only when user is logged on" and manually. my batch file will only run Jar file that will access remote drive to read some data.
batch file contains below script:
start javaw -jar E:\IS\O\Request.jar
Action page in task scheduler as below
So, i want to run the batch file using "Run whether user is logged on or not"

Related

Powershell Task Scheduler Stuck Running

I was trying to test a simple powershell script with task scheduler, the status showed running but the powershell console never showed up.
My ps1 script just contains two simple commands:
dir
pause
Here is my setup:
General
Run whether user is logged on or not (check)
Run with highest privileges (check)
Actions
Action: Start a program
Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add arguments (optional): -file E:\iQ_Schedule\Untitled1.ps1
This setup works on other computer (Windows 10) but just won't on this one (Windows Server 2012 R2). I am not sure why.
Welcome to Session 0 isolation mode.
When you run your task with "Run whether user logged in or not", it runs in so called session 0. You can check this with your task manager.
Tasks running is Session 0 has restrictions on showing the user interface
This could be due to the user account which is running the script. When the script is running with the SYSTEM account, the script will run in the background.
Try to change the option 'When running the task, use the following user account' to the account you are currently logged on with. Then the PowerShell console should pop up.
It sounds like the Windows Server 2012 R2 could have PSversion 2. The Pause function doesn't exist until PSversion 3.
Could you give the value of this command to us?
$PSVersionTable.PSVersion
Run whether user is logged on or not, will still give you the prompt. If the Hidden option is checked, you will not see the prompt.
I have also seen that the user that is trying to run the PowerShell script inside Task Scheduler doesn't have access to the folder strucutre. Make sure the user that is running the Task Scheduler has access to E:\iQ_Schedule\.
Make sure the user that is running the task scheduler has read access to the file structure you are trying to look up.
You can run as SYSTEM user, but then use the executionpolicy bypass argument
Powershell -ep Bypass 'e:\myPSFile.ps1' -myArg1 'arg1' -myArg2 'arg2'

Windows Task Scheduler Batch File - Whose permissions does commands in batch file take?

I'm running Windows Datacenter, and I'm setting up a scheduled task to create a folder on another server on the network using the md command. Here is my setup. I have 'user A' who has access to log into the server, but does not have permissions to create tasks in Task Scheduler. I also have 'user B' who does not have permissions to log into the server, but does have permissions to create scheduled tasks.
I've created a task with 'User A' as the author with security settings of When running the task, use the following user account: User B.
The action looks like this:
C:\windows\system32\cmd.exe /c "C:\test.bat"
with the Program/script as
C:\windows\system32\cmd.exe
and the arguments of
/c "C:\test.bat"
It doesn't look like the batch file is working. When this batch file is being called by Task Scheduler, who is actually performing the md command, User A (login but no task) or User B (no login but task). I assume if it's User B then that could be the problem, that User B may not have permissions to write to the other server. Any insight you all could provide is greatly appreciated.
The task will run as User B which unfortunately will cause issues regarding permissions.

Running mstsc.exe as batch job under task scheduler

I am trying to automate logging in to a bunch of RDP clients on a 2008 R2 Server, the batch below works fine when running double clicking the batch file from the desktop, however nothing happens when setting the .bat file to run as a task from Task Scheduler
#ECHO off
ECHO This .bat is used to automatically RDP in to the specified servers
ECHO which are contained within this file. Ensure you have logged in to
ECHO these servers beforehand and checked 'save credentials' otherwise
ECHO this batch file won't work as intended.
ECHO.
ECHO Beginning login...
ECHO.
ECHO Beginning login - Server ADMIN...
start mstsc.exe /v:00.00.00.00 /admin
PAUSE
The scheduled task is set to run under the Administrator account (only one available) and the (Start in) optional field has also been set "C:\Users\Administrator\Desktop\".
Turns out mstsc.exe only works if the user account is logged in... so under Security options in the General tab make sure 'Run only when user is logged in' is checked.

Scheduled task & PowerShell Script not being executed

I know this has been asked a 1000 times and I think I looked through all of them.
I have scheduled tasks running PowerShell Scripts on other servers already, but not on this server. Which has me scratching my head as to why I can't get it to work on this server.
I have a powershell script on a Windows 2008 R2 server. I can run it manually and it all works perfectly, but when I try to run it from a scheduled task the History says it was run, but the PowerShell script does not execute.
PSRemoting is enabled
The server ExecutionPolicy is "RemoteSigned"
I get two entries in the History
Action completed
Task Scheduler successfully completed task "\Processing" , instance "{dbbd4924-42d6-4024-a8ed-77494c7f84cf}" , action "C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.EXE" with return code 0.
Task complted
Task Scheduler successfully finished "{dbbd4924-42d6-4024-a8ed-77494c7f84cf}" instance of the "\Processing" task for user "domain\user".
The Scheduled Task looks like this:
I set to run under my account while I'm logged on. (since I can run the script manually as myself already)
checked Run with highest privileges.
trigger is to run every 10 minutes
Start a program Action.... Powershell.exe
Arguments: -executionpolicy remotesigned -File D:\abc\def\powershell\Processing.ps1
Conditions & Settings default settings.
Ensure that you're not being blocked by a permission issue with the task:
http://blogs.technet.com/b/askperf/archive/2012/04/18/task-scheduler-error-a-specified-logon-session-does-not-exist.aspx
The above GPO prevents credentials from being saved. Other User Rights Assignment settings can prevent things being run as batch/script/task/etc.
As a workaround, you can also set the task to run a .bat file with the powershell task. Adding an echo or pipe parameter may give you some clues to the issue.
I would recommend that you should add some diagnostic logging to this script to find out a place that causes this issue or redirect output of this script to a file. E.g. change your string with arguments this way:
-executionpolicy remotesigned -File D:\abc\def\powershell\Processing.ps1 2>&1 d:\output.log
Looks like that the script is executed, but something goes wrong. There are too many reasons for such behavior and it is difficult to find the root cause without a code.

What is wrong with this scheduled task?

I have a task that needs to be run at a given time. It needs to send an e-mail before it starts, copy necessary files and invoke an application.
The batch file code is as follows:
batchFile.bat
SET userName="someuser"
SET mailer="pre"
cscript //nologo "C:\pre_start_emailer.vbs" %userName% %mailer%
copy "C:\Users\list.xls" "NetworkDrive:\DocumentsList.xls" /Y
copy "C:\Users\driverScript.vbs" "NetworkDrive\Script\driverMain.svb"
D:\Programs\myapp.exe
In my task scheduler I have enabled, 'Wake the computer to run this task' and also the 'Run whether user is logged on or not' option.
If I have logged into my account, this job runs smoothly, but it returns a 0x1 result when I have my PC switched but or if I am logged off.
Any help or suggestions?
Thanks,
Venkat.

Resources