I have an application that reads the contents of Excel files uploaded by users. After getting the data, I need to identify the process ID associated with the Excel instance to be able to kill the process. The GetWindowThreadProcessId function seems to do the trick on the development environment (OS is Windows XP Professional) and I am getting the correct process ID but when I run it on a Windows 2003 Server, I get a Win32 error saying that the window handle that I passed is invalid. Please refer to the code.
Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application();
int ExcelPId = 0;
GetWindowThreadProcessId(Excel.Hwnd, ref ExcelPId);
if (ExcelPId == 0)