0

I currently have a .bat file that I run through Windows Task Scheduler that consists of the following:

start http://.../script.php
SLEEP 60
taskkill /im /f "C:\Program Files (x86)\Internet Explorer\iexplore.exe"

What I intend to do is run the script, wait a minute because it takes some time to complete, then kill any Internet Explorer processes that are running in the background to avoid wasting resources. I've already tried setting up a task that just runs the script with php.exe, but that one didn't work. The only thing the .php script does is update a database table. I've checked the task manager every time I've run this thing and the iexplore.exe processes still remain. While I was waiting to post this, I tried modifying the .bat file as follows:

start http://.../script.php
SLEEP 60
taskkill.exe /im /f iexplore.exe /t

Though this seemed to have some effect in that no iexplore.exe processes were running, the script failed to run as well. I tried removing /t at the end of the third line but this failed to yield any results.

The system adds iexplore.exe*32 processes every time after the first run, and I'm not sure how to kill them properly. I need this whole thing to run automatically, without any need for a user to close windows or confirm anything. What am I doing wrong?

user3521737
  • 283
  • 1
  • 4
  • 17
  • Sounds like the user that is executing the cron script doesn't have the privileges necessary to kill the process. – Ohgodwhy Dec 10 '15 at 17:52
  • That doesn't make sense though. I modified the file once again, putting the taskkill command before opening the page. That way, it kills any previous processes and then starts a new one, then repeats this thirty minutes later. I don't get what's going on. – user3521737 Dec 10 '15 at 17:56
  • Launching Internet Explorer might be useful if you want the person between the chair and keyboard to view or interact with the page. I can't see how it's anything but a waste of resources in this situation, though. If I were you, I'd just script an XMLHTTPRequest. See if you can [modify this script](http://stackoverflow.com/a/15419314/1683264) to suit your evil plans. That would be much less resource intensive than launching IE, more suitable for running as a headless scheduled task, and it exits when finished. No need to `taskkill` anything. – rojo Dec 10 '15 at 17:57
  • Note: _iexplore.exe *32_, is only for display purposes (to let the user know that the process is 32bit), the process image file name is still _iexplore.exe_. – CristiFati Dec 10 '15 at 18:03

1 Answers1

0

Instead of using IE, use a command line utility which can access a web page. This is solid a tool I have used in the past: http://noeld.com/programs.asp?cat=misc#download

Your command could then just be:

Download http://.../script.php /notime /output:result.txt

This will send a request to the server for the specified page and download the results to the local result.txt file.

Have Windows Task Scheduler control the interval and execution times.

Jason Faulkner
  • 6,378
  • 2
  • 28
  • 33
  • Does this download a copy of the file to the machine? I'm running the scheduler on the server for our site and I don't want to cause performance issues by filling it with multiple copies of the same thing. – user3521737 Dec 10 '15 at 21:17
  • @user3521737 - It downloads the result of the call (the "view source" of the page that the user would see in a browser). In my example above, `result.txt` would continually be overwritten so it wouldn't create more than 1 file. – Jason Faulkner Dec 10 '15 at 21:40
  • One last note of clarification. Would I put that command into my .bat file? I get that it's taking the place of the browser opening and closing, but you mentioned that the statement above is used via the command line. – user3521737 Dec 10 '15 at 22:36
  • @user3521737 - You can use it as a single command or as part of a batch file. – Jason Faulkner Dec 11 '15 at 14:07