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"
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'
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.
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.
I am running a small executable created by a third party that needs to run at regular intervals on a Windows 2008 server. This executable effectively ETLs information from one system to another and needs to run every hour or so around the clock. As part of its processing the executable launches a small Windows Forms type UI.
I have set up a scheduled task to call the file and this works ONLY if the user under which the task is configured to run is logged onto the machine (either locally or via Remote Desktop). If I set the task to run as another user, or set the task to run when the user is not logged, on the scheduled task executes and errors. I have tried running as different users including Administrator user and System user. Is there any possible workarounds (without changing the third party code which I have no access to) which would allow this code to be run without a specific user logged in.
The GUI app needs a desktop and you only get one of those for a logged in user.
This article shows how to create a task that does not require any login: https://www.scriptjunkie.us/2013/01/running-code-from-a-non-elevated-account-at-any-time/
The described procedure is as follows:
First, create a scheduled task to run your command with default options as the current user (this will by default create a scheduled task that only runs when you are logged in):
schtasks /create /tn mytask /SC HOURLY /TR "calc"
Then export the task as XML:
schtasks /query /XML /tn mytask > temp.xml
and delete the task:
schtasks /delete /tn mytask /f
Then open the xml file, and replace the line
<LogonType>InteractiveToken</LogonType>
with
<LogonType>S4U</LogonType>
This can be done with the following commands assuming powershell is on the system:
powershell -Command "Get-Content '.\temp.xml' | foreach {$_ -replace 'InteractiveToken', 'S4U' }" > new.xml
move /y new.xml temp.xml
Now recreate the task from the modified XML file:
schtasks /create /xml temp.xml /tn mytasks
and remove your temp file:
del /f /q temp.xml
It would seem that from the research I have done (and David Heffernan's answer), without affecting the source code, this is not possible.
There are some useful thoughts on How can I run a Windows GUI application on as a service? which relate to this but none give a viable workaround to this problem.
I think I have found a solution for this situation. You need to have two user accounts on the server (User1 and User2). RMD into the server under User1. Within this RMD, create your scheduled task, and set it to run under User2 account. Then, from within this RMD, you need to RMD into the server itself using User2 credentials (kind of like Inception's dream within a dream). It's important not to minimize this new RMD window; you can make it small, but it must be open. You are then free to close the original RMD session and the task will run under the User2 account, because User2 has an open desktop from your 2nd RMD session.
Protip - don't unpin the RMD window handles at the top of the RMD window - it can be a pain to close the correct RMD then. If you do, you'll need to use the Start > Log Out option all the way out of your RMDs.
I might be late in replying, but can't we use at command, without /interactive...
https://support.microsoft.com/en-us/kb/313565
As per microsoft: /interactive: Use this parameter to allow the task to interact with the desktop of the user who is logged on at the time the task runs.
There is a simple solution.
Change group to local group "users" and you will not be prompted for a password.
(Scheduled Task - General - Security Options - Change User or Group).
This looks to be an old thread, but I recently ran in to this in my organization due to UAC requirements they were not using. I am still testing this, but I believe you can still enable interactive mode on a scheduled task by using the /Change command on the task and adding the /IT flag to make it interactive. Referenced here: https://learn.microsoft.com/en-us/windows/desktop/taskschd/schtasks
schtasks /Change /tn "Task A" /IT /RP "password of user if used"
My initial tests show this to be working, however I cannot noticeably see a difference to the task in task scheduler when I do this. So, I am not sure of how to verify if it is set to do this.
I had a similar issue. My VB app would not run properly on my server unless I had "Run only when user is logged on" enabled. I forget where I found this info, but doing it allowed my VB app to run perfectly with a set user, without needing to be logged in. It allows it to interact with the Desktop.
On a Windows 2008 (or greater) server, you need to do the following:
For x64, just create this folder:
C:\Windows\SysWOW64\config\systemprofile\Desktop
For x86, just create this folder:
C:\Windows\System32\config\systemprofile\Desktop