0

I know that a web browser is a GUI control But here is a problem:

I have a Windows service and I want it to grab a web page from Internet and let the JavaScript code to be executed and then processes the result on that page and keeps Cookies.

is there any way to simulate Web Browser or Create a Hidden window and assign a web browser to it from inside windows service ?

Zeid
  • 59
  • 1
  • 8

1 Answers1

2

Using a GUI control in session 0 will likely fail. You can enable the Allow service to interact with desktop setting for the service. This won't result in the control being visible on the desktop, but it will let the interactive desktop API calls in the service succeed. Whether this works for you, I cannot predict. It's your best hope of getting something out of a GUI control in a service. But do not be surprised if even that does not work.

What you should do though is to perform your tasks without a GUI at all. There are headless browsers that are designed for use in services/daemons. For instance PhantomJS, but there are others. This old question has an excellent set of links: Headless Browser and scraping - solutions

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • This is a good solution but non of them works with Delphi Windows Service Application And i need something to add to my windows service. – Zeid Feb 06 '14 at 11:24
  • What do you mean? You can certainly use many of these tools with Delphi. Why do you think otherwise? – David Heffernan Feb 06 '14 at 11:26
  • How can I include and use One of them .... Would you please give me a sample code in delphi ? – Zeid Feb 06 '14 at 12:45
  • 1
    *Would you please give me a sample code in delphi?* No, I cannot do that. This is not a quick 5 minute job. Integrating a headless browser will take days or weeks. Therefore you cannot expect somebody to make the code for you in an SO answer. If that's too hard for you to do, then you need to use one of the less ideal options. For instance, stop using a service and run your program on the logged in, interactive user desktop. – David Heffernan Feb 06 '14 at 12:51
  • tanks for your time david – Zeid Feb 06 '14 at 12:57
  • As David suggested, I made a stand alone form application with zero dimensions and without Toolbar or any extra thing, and I connected it to my windows service using Windows registry. every thing is good and running. – Zeid Feb 10 '14 at 00:12