Click here to Skip to main content
15,887,346 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey everybody,

I have found many questions like mine in different forums, but I couldn't find an answer that actually helps to solve my problem in any of them.

Basically, what I want is to open an URL through command prompt, it will open the browser, processes a webpage, and then I would like it to automatically close.

Why do I need this?
I have an application that runs on IIS. There are some routines I need to run everyday in my application. I can simply kick of these routines by running an URL similar to the showed below:

http://myapplication.com/DoStuff.aspx?

The Problem is that this is totally manual.
I was wondering if I could create a batch file calling my URL "start http://myapplication.com/DoStuff.aspx?", and then I could create a task on Windows to run that batch file everyday. That works for me except that the browser will not close automatically.
What I mean is, I could try it, but at the end of a week, I would have at least 5 windows opened.

What I have tried:

I have tried to solve it by using javascript, but I always end up getting this message:
scripts may close only the windows that were opened by it


It does not matter the javascript function I create using "window.close()", the windows won't close.

Chrome and Firefox returns that message.
IE let's me try to close the window, but it asks in a popUp if I really want to close it.
Posted
Updated 16-May-17 4:44am

1 solution

You're trying to answer the wrong question. :)

Don't try to find a way to use Javascript to close the browser window. Even if you find a hack to let you do that, it will be a bug in the browser, and will most likely be patched, breaking your script.

Instead, use a different tool to make the request. For example, Powershell can request a URL without opening it in a browser:
$url = "http://myapplication.com/DoStuff.aspx?"
$webclient = new-object System.Net.WebClient
$webclient.UseDefaultCredentials = $True
$webpage = $webclient.DownloadString($url)
 
Share this answer
 
Comments
Arthur Medeiros 17-May-17 13:27pm    
Hey Richard,
Thank you for the suggestion and for showing me the right direction to solve my problem.
That actually did not work for me, but without your suggestion I would not be looking into powershell stuff. Therefore, I used "Invoke-WebRequest".
It worked, but there is something wrong in my code with date conversion. Once I solve it, powershell might be the solution.
Richard Deeming 17-May-17 13:33pm    
Invoke-WebRequest[^] looks like a handy command. I don't think it was available when I wrote my script to "wake up" the SQL reporting services site. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900