Why does GetWindowThreadProcessId return 0 when called from w3wp.exe
问题 When running the following code, GetWindowThreadProcessId returns 0. I've read about the same problem happening with a service, but this code is being run as an Application Pool in IIS (namely, w3wp.exe). Also, both w3wp.exe and the EXCEL.EXE it is trying to kill are running in the same session (session 0), and as the same user. if (appClassXls != null) { IntPtr processId = default(IntPtr); GetWindowThreadProcessId(appClassXls.Hwnd, out processId); Process processXls = Process.GetProcessById