0

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.

user
  • 61
  • 1
  • 2
  • 10
  • What userid does the task scheduler process run under? Maybe a permissions issue? – Mr Smith Mar 17 '16 at 17:35
  • 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 Mar 17 '16 at 18:11
  • Try adding a path to debug.log –  Mar 17 '16 at 19:53
  • 2
    Why not instead download the page using a command-line HTTP client such as [cURL](https://curl.haxx.se/) or [cURLie](https://code.google.com/archive/p/curlie/) instead of using Chrome? – dolmen Mar 17 '16 at 21:05
  • 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. http://stackoverflow.com/questions/36045745/automate-daily-csv-file-download-from-website-button-click?noredirect=1 – user Mar 18 '16 at 15:29

2 Answers2

0

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.

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
  • There is no url for the file. The file is generated from a post request, and there is some kind of validation that requires the page to be loaded with javascript for it to allow the download. I previously tried to accomplish this using curl and phantomjs. I am using the TamperMonkey chrome extension to click the download button. http://stackoverflow.com/questions/36045745/automate-daily-csv-file-download-from-website-button-click?noredirect=1 – user Mar 18 '16 at 15:26
  • Oh, sorry to hear that, these websites are painful to use. However, try to use `chrome --incognito` or something from [here](http://askubuntu.com/questions/285725/google-chrome-does-not-open)(e.g. rename those files with batch) – Peter Badida Mar 18 '16 at 15:36
0

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/

user
  • 61
  • 1
  • 2
  • 10