Error while using SHDocVw.InternetExplorer in C#2.0

854 Views Asked by At

all,

I have code in C# 2.0 like this:

 SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
 foreach (SHDocVw.InternetExplorer ie in shellWindows)
 {
  //.........
 }

It is console exe for a 64bit Windows Server 2008 R2 Standard with sp1, IE9. Basically it launches IE and download a file, then process that file. When I run it manually, such as double click or from Command console, it works just fine. However, when I set up a Scheduled Task through Task Scheduler, it throws the error at the first line above:

Retrieving the COM class factory for component with CLSID {9BA05972-F6A8-11CF-A442-00A0C90A8F39} failed due to the following error: 8000401a.

I think it must be a permission issue,but I couldn't figure out how to fix it. Any ideas?

Thanks.

1

There are 1 best solutions below

0
On

I suspect this is to do with access to the desktop. As shdocvw has a UI, it requires permission to get the desktop handle. When it creates a window it must have a parent window and the desktop window handle is king (or Queen).

However, a scheduled task (for any user) cannot get the desktop handle unless the user is already logged-in in the foreground.