I have been trying to make the scheduler work for the past two days.
I am trying to sync a folder from a remote server using WinSCP, however I do not want to keep WinSCP running continuously and am thus running it using a batch file. The batch file is below.
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="WinSCP_log.log" /ini=nul ^
/command ^
"open sftp://xxxxxxxxxxxxxxxxx -hostkey=""xxxxxxxxxxxxxxxxxxxxx""" ^
"cd /data/remotexxxxxx" ^
"lcd C:\localxxxxx" ^
"synchronize local" ^
It runs fine when I just run the batch file. When using the Windows Task Scheduler to run every 20 minutes it does not run. However, even in the Scheduler if I double click and run manually it works fine. I even tried converting the batch file to a .exe, but face the same issue there.
The Windows Task Scheduler settings are -
Program/Script: /Directory/sync_winscp.bat Arguments: Start in:
/Directory
And similarly for the .exe file
Program/Script: /Directory/sync_winscp.exe Arguments: Start in:
I also tried -
Program/Script: .../Win32/cmd.exe Arguments:
/Directory/sync_winscp.bat Start in:
It is running with highest privileges and does not have a timeout.
Update:
I also have another .bat file to call python and run a script daily which runs perfectly fine.
Edit the task and switch to the Triggers-tab.
Select the designated trigger in the list and click Edit-button.
Make sure that all of the below is true:
"Begin the task" option is set to "On a schedule" value.
Start date is today, and time is a few minutes later than current.
"Enabled" check-box is checked.
Click OK all the way out to activate the task, then verify at the next run time.
All of the above settings are important, but the key here is, the task will NOT run until it gets triggered first. In other words, it will run on schedule only AFTER it gets triggered. This is why start time must be set slightly into the future.
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 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.
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.
I have a very simple .bat file. It only has one line:
powercfg -h off
What this does is turn off the computer's ability to hibernate. It works fine when I double click the file. I can confirm this by going into the command prompt and typing "powercfg /a", which shows me that hibernate is indeed off. The problem is that this batch file doesn't seem to be running at logon even though it's in my Startup folder.
I've tested it by turning hibernate on using the command prompt ("powercfg -h on") and then actually putting my computer into hibernation. Then I turn it back on and log in to Windows. But when I open a command prompt and type "powercfg /a" it shows me that hibernate is still on. It seems the batch file doesn't run at logon even though it is in my Startup folder.
I've also tried making it run from a task scheduled to run at logon, but that didn't work either.
Some ideas:
Make sure you set the Start in and Program/script options of the batch file correctly.
If (1) doesn't work then try moving the .bat file to a directory with basic permissions.
Try to schedule the execution of the batch file like this cmd /c "c:\path\batch.bat"
Also take a look at this: Batch runs manually but not in scheduled task.
I got it to work using Task Scheduler. The problem was that I was using the trigger "At log on," when I should have chosen "On workstation unlock."
It's obvious to me now, but I didn't think of it at the time: hybernating didn't actually log me off, it only locked me out.
quick explanation:
I have a batch file converting a series of swfs to mp4s which are placed into the batch file via PHP fwrite. This is ran every hour on windows Task Scheduler. For example:
C:
cd "path\Moyea\SWF to Video SDK"
swf2videocmd "conversion_command_here"
cd "path\MySQL\bin"
mysql --host=hostip --user=user_name --password=hostpw--database=database_name --table=table --execute="UPDATE table SET processed=1 WHERE processID=44;"
This works fine, updates the SQL and runs the process. There can be as many conversions in one batch file as necessary, they're added dynamically on demand. Windows Task Scheduler runs the batch fine aswell.
I then have a secondary batch file which Task Scheduler runs at the same time - clear.bat. This clears the first one so the conversion job can start afresh with the new files next time:
D:
cd "path\youtube\"
nul > swf2mp4.bat
It clears the first batch file fine, but returns a prompt saying Windows cannot access the specified device, path or file.
In windows Task Scheduler, it can't close this prompt so the task gets stuck running, meaning the next instance of the task (hourly) can't be run. I would make it automatically close each hour, but the conversion queue may be large. All I need to do is supress the error.
Replace
nul > swf2mp4.bat
with
type nul > swf2mp4.bat
and it should work fine.