0
votes

I have a batch file that opens a webpage in chrome, and then moves and renames a file that is downloaded from the website. The batch file works when I manually run it. The file does not work when I set the file to run in the windows task scheduler

set date=%DATE:~10,4%_%DATE:~4,2%_%DATE:~7,2%
chrome "http://www.example.com/download_page" >>debug.log 2>&1
timeout 10
move "C:\Users\user\Downloads\export.csv" "C:\path\to\moved\file%date%.csv" >>debug.log 2>&1

Here is the error message that shows up in debug.log

[21396:15752:0317/101540:ERROR:process_singleton_win.cc(335)] Lock file can not be created! Error code: 32 [21396:15752:0317/101540:ERROR:chrome_browser_main.cc(1356)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption.

2
What userid does the task scheduler process run under? Maybe a permissions issue?Mr Smith
I have tried to run the task as both my Windows Domain network user and a local user that both have admin rights on this computer. I also checked the box that says run with highest privileges. How do I check the userid of the process?user
Try adding a path to debug.loguser6017774
Why not instead download the page using a command-line HTTP client such as cURL or cURLie instead of using Chrome?dolmen
I tried a php curl solution originally. The download is triggered from a post request. There is some type of validation that requires the page be loaded with javascript for the post request to return the file. See the original question I posted here for more info. stackoverflow.com/questions/36045745/…user

2 Answers

0
votes

I recommend you using built-in tools such as bitsadmin, though some people whine about how it's depreciated and the next thing you'll see is powershell/vbs alternative.

Bitsadmin downloads it for you so you'd need no timeout 10 if you won't run it in another instance. Sometimes it can take a second to get to the full download speed. Only disadvantage I see is automatic cls of your cmd screen, therefore the way with start bitsadmin and then you could check for %errorlevel% equ 0 for succesful download.

bitsadmin.exe /transfer "<name_of_job>" "<url>" "<where to save>"

This way even your move seems unnecessary. Check bitsadmin /? for more info.

0
votes

I stopped trying to run Chrome in the windows task scheduler. Instead I installed the chrome extension Crontabs. I setup Crontabs to open the page at a certain time then close the tab after a few minutes. I continued to use the Windows Task Scheduler to move the downloaded file. I had to disable sleep/hibernate for this to work while I am away from my computer.
http://www.crontabs.org/