从w3wp.exe的调用时为什么GetWindowThreadProcessId返回0 [英] Why does GetWindowThreadProcessId return 0 when called from w3wp.exe

查看:1009
本文介绍了从w3wp.exe的调用时为什么GetWindowThreadProcessId返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行下面的code, GetWindowThreadProcessId 返回0。我读过关于<一个href="http://stackoverflow.com/questions/2461171/why-does-getwindowthreadprocessid-return-0-when-called-from-a-service">the同样的问题发生与服务,但这code目前正在运行的应用程序池在IIS(即w3wp.exe的)。另外,无论是w3wp.exe的和EXCEL.EXE它试图杀死在同一个会话(会话0)运行,并作为同一用户。

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(processId.ToInt32());
    if (processXls != null)
    {
        processXls.Kill();
    }
}

显然,这code失败,因为它会试图杀死PID 0这是Excel应用程序实例,它试图杀死的系统空闲进程来代替。为什么会 GetWindowThreadProcessId 从w3wp.exe的在同一会话中作为同一个用户调用时返回0?我如何让它返回正确的PID?

Obviously this code fails since it will try to kill pid 0 which is the System Idle Process instead of the Excel Application instance it's trying to kill. Why would GetWindowThreadProcessId return 0 when called from w3wp.exe in the same session as the same user? And how do I make it return the correct pid?

在Windows Server 2008 R2标准版(64位) IIS 7.5 .NET框架4.0版 微软Office专业增强版2010(全新安装,将推出在DCOM设置为特定的用户,通过w3wp.exe的启动)

Windows Server 2008 R2 Standard (64 bit) IIS 7.5 .NET Framework v4.0 Microsoft Office Professional Plus 2010 (clean install, set to launch as specific user in DCOM setting, launched by w3wp.exe)

更新(2011-02-17 08:33 UTC): 我刚刚意识到的w3wp.exe是由中svchost.exe -k iissvcs推出对应于万维网发布服务和Windows进程激活服务,并EXCEL.EXE用的svchost.exe -k推出DCOMLAUNCH相当于DCOM服务器进程启动,所有的其中3个是服务。两者的运行作为SYSTEM在会话0虽然svchost.exe的,所以我还是不明白为什么他们或他们的孩子会在访问对方的麻烦。

UPDATE (2011-02-17 08:33 UTC): I just realized that w3wp.exe is launched by "svchost.exe -k iissvcs" which corresponds to the "World Wide Web Publishing Service" and the "Windows Process Activation Service" and EXCEL.EXE is launched by "svchost.exe -k DcomLaunch" which corresponds to "DCOM Server Process Launcher", all 3 of which are services. Both of the svchost.exe's are running as SYSTEM in session 0 though, so I still don't see why they or their children would have trouble accessing each other.

推荐答案

请参阅本的博客条目解释如何会话0隔离工作。它看起来像服务和应用程序不能互相交谈。我试图找出如何会话0被分配。我相信窗口站W3WP被分配到不一样的一个用于Excel的(我认为),它推出。

See this blog entry which explains how Session 0 isolation works. It looks like services and applications cannot talk to each other. I am trying to figure out how "session 0" is assigned. I believe the window station w3wp is assigned to is not the same as the one for the excel (I assume) it launched.

我建议避免从Web应用程序启动的Excel。您可以轻松地挂在服务器上这样做。我还记得,由于引用计数泄漏上,将最终导致服务器的消亡对Excel造成内存问题的几个问题。 :)

I recommend avoiding launching excel from a web application. You can easily hang the server doing that. I remember several issues due to reference count leaks on the excel causing memory issues that would ultimately lead to the server's demise. :)

这篇关于从w3wp.exe的调用时为什么GetWindowThreadProcessId返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆