需要帮助才能关闭w3wp.exe [英] Need Help to close w3wp.exe

查看:284
本文介绍了需要帮助才能关闭w3wp.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我创建了一个控制台应用程序来关闭w3wp exe,下面是代码。

  public   static   void  KillProcessByNameAndUser(  string  ProcessName, string  ProcessUserName, int  HasStartedForHours )
{
Process [] foundProcesses = Process.GetProcessesByName(ProcessName);

foreach (处理p in foundProcesses)
{
p.Kill();
}
}



当我通过点击工作最终将它作为普通exe运行时,但当我在我的asp.net页面中调用它时它还关闭了w3wp exe,但它也停止了IIS应用程序池。我只需要停止w3wp.exe而不是IIS应用程序池。这就是我在asp.net页面中调用它的方式。

进程p =  new 进程() ; 
p.StartInfo.FileName = @ C:\inetpub \wwwroot \Kill \ Debug \Kill.exe;
p.Start();



请帮助asap为什么会发生这种情况以及任何解决方案。

解决方案

你必须在序列中发送excel一个WindowClose消息来强制关闭进程。



你将使用这些API函数

私有声明函数OpenProcess Libkernel32(ByVal dwDesiredAccess As Long,ByVal bInheritHandle As Long,ByVal dwProcessId As Long)As long 
Private Declare Function TerminateProcess Libkernel32(ByVal hProcess As Long,ByVal uExitCode As Long)As long
Private Declare Function CloseHandle Libkernel32(ByVal hObject As Long)As Long
Private Declare Function GetWindowThreadProcessId Libuser32(ByVal hWnd As Long,lpdwProcessId (长)$ Long
公共声明函数FindWindow Libuser32别名FindWindowA(ByVal lpClassName As String,ByVal lpWindowName As String)As Long



And它应该看起来像什么喜欢:

 //首先,查找句柄
hWindow = FindWindow(vbNullString,Excel)
//查找过程ID
GetWindowThreadProcessId (hWindow,ProcessValueID)
//终止进程
ProcessValue = OpenProcess(PROCESS_ALL_ACCESS,CLng(0),ProcessValueID)
TerminateProcess(ProcessValue,CLng(0))
CloseHandle ProcessValueID


Hi,

I have created a console application to close w3wp exe , below is the code.

public static void KillProcessByNameAndUser(string ProcessName, string ProcessUserName, int HasStartedForHours)
       {
           Process[] foundProcesses = Process.GetProcessesByName(ProcessName);
          
           foreach (Process p in foundProcesses)
           {         
               p.Kill();           
           }
        }


when I run it as a normal exe by clicking it working final, but when i call it in my asp.net page it also close the w3wp exe, but it also stopping the IIS application pool. I need only to stop the w3wp.exe not the IIS application pool. This is how I called it in my asp.net page.

Process p = new Process();
            p.StartInfo.FileName = @"C:\inetpub\wwwroot\Kill\Debug\Kill.exe";
            p.Start();


Please help asap why is that happening and any solution for this.

解决方案

you have to send excel a "WindowClose" message in Sequence to forcefully close the process.

You will be use these API functions

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


And it should be look something like:

// First, Find handle 
hWindow = FindWindow(vbNullString, "Excel")
//Find proccess ID
GetWindowThreadProcessId(hWindow, ProcessValueID)
//Kill the process
ProcessValue = OpenProcess(PROCESS_ALL_ACCESS, CLng(0), ProcessValueID)
TerminateProcess(ProcessValue, CLng(0))
CloseHandle ProcessValueID


这篇关于需要帮助才能关闭w3wp.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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