2

I have a series of batch files that execute some action on a windows server, and then call a web url that registers on a database that the actions are completed and when.

I call the web file like this Start "http://the_url"

It works fine, but i noticed that the browser persist in the background processes, but if I log in with the user there's no opened browser's window.

Ho can I close the browser in the same batch file? There's a better way to call an url?

Fehu
  • 381
  • 1
  • 3
  • 18

3 Answers3

3

start the process with WMIC to get its pid:

@echo off
for /f "skip=5 tokens=2 delims==; " %%a in ('wmic process call create "chrome.exe url" ') do (
    set "pid=%%a"
    goto :break
)
:break
echo %pid%
taskkill /pid %pid% /f

May be better approach is to execute directly a webrequest without a browser. Check winhttpjs.bat which is capable to execute numerous kind of http requests.

npocmaka
  • 55,367
  • 18
  • 148
  • 187
2

You are going to need the Process ID of the Browser to kill it. This might prove problematic if another browser is already open when the Start command is executed. However it is possible by iterating over the output of tasklist like this answer. Once you have this Process ID(PID) you can call taskkill to end it.

Community
  • 1
  • 1
Jason Sperske
  • 29,816
  • 8
  • 73
  • 124
0

Instead of starting a browser, you might be able to just use a Powershell command such as:

powershell Invoke-WebRequest -Uri "http://the_url/"

If performing a GET on the URL is the only thing required, this should do the trick.

Tony Hinkle
  • 4,706
  • 7
  • 23
  • 35