[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 785
  • Last Modified:

Enumerating ShellWindows in windows Service


I'm working on a windows service in which I need to interact with the desktop and control a browser instance. I've come across ShellWindows (from SHDocVw) in which I can enumerate sucessfully in a widows Forms Application to obtain the handle of the Intenet Explorer Browser.

The functionality I'm using is:-

   For Each window As InternetExplorer In New ShellWindows
   Next window

We need to migrate this funcitonality into a Windows service so that the processing can occur in the background and then on a given event the windows service will interact with the desktop
and then control the active Internet explorer instance.

However, when I try the code in the windows Service I get an error:-
System.IO.FileNotFoundException: The system cannot find the file specified.
   at MyService.PopBrowser.GetWindowsAndPop()

I have attempted to run the service by allowing "Allow Service to interact with desktop" in the Log On section and even using the specific account that I'm logged in on but it always gives the above error.

I know that the widows service isn't designed to cater for interacting directly with desktop processes but is there a way to make this work? It's not really an option to code any windows Form type application (i.e. such as to have a second application which will communicate with the service).

Many thanks


Many Thanks
  • 2
2 Solutions
With no sample code, it's all a guess.

My first guess is a pathing problem.  Check the default directory and see if it's not system32.
mikesung99Author Commented:

I've Put the Dll explicitly into system32 and tried to run it again but it gives the same result


and what's the code that throws the exception?

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now