I know there are similar questions already out there, but none of the other solutions seem to help.
Using Windows 7, I have an executable (for this explanation, I am calling it test.exe) that takes a parameter of the current date.
Example when using the run command:
c:\test.exe 12/26/2014
The executable needs to be ran on a daily schedule.
I have the following batch file set up to run the exe with the required parameters:
#echo off
::This batch will be ran daily to start the exe program
set dateFormat=%DATE:~4,2%/%DATE:~7,2%/%DATE:~10,4%
echo Batch started %dateFormat% %Time%>> BatchLogfile.txt
set testfile=C:\test.exe
start %testfile% %dateFormat%
pause
I can run the batch successfully by double-clicking on it in explorer, but when I add it as a scheduled task it does not actually start the exe.
The batch does run and I can see the processes for the cmd and the exe, but the exe "interface" does not pop up. The echo line in the batch writes out to the log file successfully.
On the scheduled task, I am currently using cmd for the program/script and the following params:
/k "C:\test.bat"
I have also tried the following arguments unsuccessfully in the task scheduler:
C:\Windows\System32\cmd.exe
/c start "" "C:\test.bat"
/k start "C:\test.bat"
Is there anything else I should try so that the exe "interface" shows on the screen? Perhaps there is a better way to run the exe other than task scheduler?
If you want to see the GUI for test.exe, then you will need to configure the respective Windows Scheduled Task to "Run only when user is logged on". Of course then the process would only run for the configured user account.
This is available to select in the Security Options section in the General tab of the respective scheduled task.
Related
I have a simple one line bat file that runs a curl localhost:port. My curl.exe is in the same folder as the bat I don't have it installed globally. It runs fine if I double click it, it also runs fine if I right click in task scheduler and select run task. It also says it completes the "scheduled tasks" successfully but nothing happens (I'm sure of this as I'm checking data that should update if the script is run, and it doesn't happen under the scheduled/automatic scenarios). After reading lots of users issues I tried configuring in two ways (all on 5 minute updates):
Common Way
Action: Start a Program
Program/script: C:\p\updater.bat
Start in: C:\p\
Other Way
Action: Start a Program
Program/script: cmd
Add arguments: /c start "" "C:\p\updater.bat"
I have set permissions to the bat and the containing folder to allow all for all users/etc. Neither work when automatically triggered, neither error. I've tried in Server 2008 and Windows 10 (my OS) mode. Both work if I right click run task, neither automatically, any ideas?
Default working directory for scheduled script is %Windows%\system32. Try to add in first line to you updater.bat:
cd c:\p\
For diagnostic, you can add output redirect to you commands in bat file:
echo Script Started >> c:\p\log.txt
curl SomeCommand SomeCommand >>c:\p:\curloutput.txt
echo Script Ended >> c:\p\log.txt
and check files log.txt and curloutput.txt after execution of your script
I have a simple batch file set up on a 64-bit Windows Server 2008 R2. I'm trying to set it up to run under the Windows task scheduler, specifying the admin account as the user. I have no problem running the batch file manually, when logged on to the server with the same admin account. When in the Task Scheduler though, the task just Runs and hangs.
Here's the code from the batch file, moving files from a mapped drive to which the admin account has access:
DEL "O:DEL "O:\Finance file\AP\Check Run Merge\*.*" /Q
copy "O:\Finance file\AP\Invoices\ADT SECURITY_549527511_2015-05-12_655.32.pdf" "O:\Finance file\AP\Check Run Merge\142000.pdf"
copy "O:\Finance file\AP\Invoices\CENTRAL DRUG SYSTEM_244658_2015-05-08_3.50.pdf" "O:\Finance file\AP\Check Run Merge\142001.pdf"
copy "O:\Finance file\AP\Invoices\DATAFLOW BUS.SYSTEMS_156290_2015-05-20_7.50.pdf" "O:\Finance file\AP\Check Run Merge\142003.pdf"
I have just run a batch file from task scheduler using the following settings for the Action on Windows 7. The main part I got wrong the first time was not running it using cmd.exe. Also adding the /c so that the cmd closes after the batch file has run (that is probably why it takes forever).
I made my batch file write to a log file as follows so I could see that it was running:
time /t >> C:\temp\mytestlog.txt
just run it as a cmd.exe with the bat file as an arg. you could also short cut it and run that
I am trying to automate a VBScript by using Windows Task Scheduler. However, I tried to use cscript.exe + "C:\...\script.vbs" but it didn't run. I also tried to directly run the same command in CMD (cscript.exe "C:\...\script.vbs") and it worked.
What might be the problem?
EDIT :
I just tried to switch the setting to "Run only when user is logged on" from "Run whether user is logged on or not" and it worked. I am wondering if there is a way to make my task scheduled run even when the user is logged off.
After hours of research, one of Blake Morrison (from Microsoft)'s blogs came up; it mentioned that
If running a .vbs / .ps1 script, try launching it from a .cmd / .bat script
see Help! My Scheduled Task does not run…
That blog also explains a lot of rules/tips when using Task Scheduler.
So please create a .cmd/.bat file that calls for your VBScript. For example: cscript.exe YourScript.vbs would be in your .cmd/.bat script.
Write a batch file like this:
echo "Started!" > c:\foldergoeshere\log.txt
cscript.exe "C:\...\script.vbs" > c:\foldergoeshere\log.txt
echo "Stopped!" > c:\foldergoeshere\log.txt
Then schedule the batch file instead of the vbs. That will allow you to see what is happening that is preventing it from running. Any error that you would have seen executing in the console (CMD), will be instead output to that log file between "Started!" and "Stopped!"
What's the hassle all about? I don't use .cmd/.bat and script works! (Windows7 here)
My VBS script (as a scheduled task) runs well on any scenario of these 4:
cscript and option "Run only when user is logged on"
cscript and option "Run whether user is logged on or not"
wscript and option "Run only when user is logged on"
wscript and option "Run whether user is logged on or not"
It's only that on the 1st scenario I encounter the black command window flashing on my screen.
Action settings:
or
My script, which simply creates a file:
Set objFSO = CreateObject("Scripting.FileSystemObject")
filename = "C:\Temp\" & Hour(Time) & Minute(Time) & Second(Time)
Set objFile = objFSO.CreateTextFile(filename)
Greg answered this https://superuser.com/a/816073
Basically you need to create 2 folders:
You have to create a folder (or two on a 64bit-windows):
(32Bit, always) C:\Windows\System32\config\systemprofile\Desktop
(64Bit) C:\Windows\SysWOW64\config\systemprofile\Desktop
Fixed the issue for me (and I could point to the .vbs file, not bat needed).
The .vbs file is running invisibly, which is a consequence of running it with the 'logged on or not' option.
You will not be allowed to interfere with a user using the computer, which means you will be able to help yourself, but not others.
Please read the following text from the Task Scheduler Help menu:
Task Security Context
You can specify that a task should run even if the account under which the task is scheduled to run is not logged on when the task is triggered.
To do this, 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.
You can do this.
cmd as the Program.
/c start cscript //nologo "W:\Pathto with spaces\VBScript.vbs"
/c send the following to the cmd
start starts the next parameter
cscript //nologo "W:\Path with spaces\VBScript.vbs" self explanatory. Path wrapped in quotes to allow spaces in the filename.
Screenshot
Have experienced more than once that a VBScript running as planned task worked fine for months and years but suddenly would not work any more despite nothing was changed. Have tried to reactive the task using all the recipes given here and elsewhere, but no success. My workaround was to create a new planned task with all settings copied from the original one.
I tried this on Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
AKA Window 7, But in my case i first cd to the dir and then ran the .bat file to execute the .vbs file
Go to start menu
Search for run
Once it opens, Type "shell:startup" and press Enter
You'll be directed to the Start Up folder. In this folder you can put create a .bat file which you want to execute the .vbs file (You'll do this in a special way)
cd C:\the\path\were.vbs\file\located && wscript.exe start_app.vbs
What your doing is cd to the directory cd C:\the\path\were.vbs\file\located
And then run the .vbs file wscript.exe start_app.vbs
I have a batch on my C:\TEMP\batch.bat who runs an exe from a remote server (\Remote_host\App_Folder\app.exe)
My .bat content:
start /d "\\Remote_host\App_Folder\" app.exe
On double click, the batch file runs app.exe correctly. So now, I create a task in Windows Task Scheduler which triggers this batch file.
When task is launched, app.exe is not called.
Any suggestions ?
The task has to run with a specific account and make sure the checkbox "Run whether user is logged on or not." is not checked.
If checked, it will not store the password.
I have a simple batch file which calls a powershell script.
I've looked at the following 3 previous questions on the subject as well:
Run a batch file from Task Scheduler is not working with a java command
Windows Task Scheduler doesn't start batch file task
Task Scheduler not executing batch (bat) file with MSTest commands
It seems like I've tried every single combination of running the task and it still doesn't execute my powershell script.
batch file contents:
powershell.exe "E:\SIS\fileCopy.ps1"
If I run the command in the batch file manually, it runs just fine. Here are things I've tried to do to get it working:
I've change the Security options to run as System with "Run with highest priveleges" checked
I've tried every other combination of "Run only when user is logged on", "Run whether user is logged on or not" and "Run with highest priveleges"
I've tried adding the "Start in (optional" setting to the folder where the files are located.
I'm at my wits end and can't believe Microsoft hasn't figured out a way to make this easier.
You need to have task scheduler execute Powershell.exe and have the arguments be the path to your .ps1 file.
To validate your script is running properly, you should set the Security options to 'Run only when user is logged on'. It will then pop the powershell dialog when it runs. I often also use start-transcript to view the results of scheduled poweshell scripts.
After you validate the script is running correctly, you can set the security options however best fits your situation.
Use the execution policy flag to flag that instance to unrestrisicted because your powershell settings may be blocking script execution.
powershell -executionpolicy unrestricted -Command "E:\SIS\fileCopy.ps1"
I found that Task Scheduler can't run a batch file if it lives in a folder that is being synced by OneDrive. I had to move the batch file to another folder to get Task Scheduler to be able to run it.