I am getting an access is denied error message when calling the DestroyWindow() function in a .net windows application, here is the code:


ArrayList RunningP;
Process IEProc;
Int32 temp;
Int32 i = 0;
Boolean b;

RunningP = new ArrayList(Process.GetProcessesByName("iexplore"));
if (RunningP.Count > 0)
{
IEProc = (Process)RunningP[i];
b = DestroyWindow(IEProc.Handle);
i = i + 1;
temp = GetLastError();
}

the variable temp is where i find error code 5 which is access is denied. I also have these delegate methods defined on this page:

[DllImport("User32.dll")]
public static extern System.Boolean DestroyWindow(IntPtr hWnd);
[DllImport("kernel32.dll")]
public static extern System.Int32 GetLastError();

I am logged on as local administrator, so not sure what is causing this error message I have search on this site and others and cant seem to find a fix for this, can anyone help?

Regards

Joe