Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php请求另一个windows应用程序关闭_Php_Windows_Winapi - Fatal编程技术网

使用php请求另一个windows应用程序关闭

使用php请求另一个windows应用程序关闭,php,windows,winapi,Php,Windows,Winapi,我是一名php开发人员,希望使用php+一些windows api来执行任务 任务是:要求正在运行的windows应用程序自行关闭 用php这样做当然不是很自然,但我正在用php编写我的小脚本,因为这是我现在使用的语言,而且我非常熟悉。php支持调用win32 API。然而,看起来扩展的稳定性不是很好 我认为您最好使用该调用。php.net网站提供了一些指导: w32api_定义类型 w32api_init_数据类型 w32api_uu调用函数 w32api_寄存器_函数 w32api\u集合

我是一名php开发人员,希望使用php+一些windows api来执行任务

任务是:要求正在运行的windows应用程序自行关闭

用php这样做当然不是很自然,但我正在用php编写我的小脚本,因为这是我现在使用的语言,而且我非常熟悉。

php支持调用win32 API。然而,看起来扩展的稳定性不是很好


我认为您最好使用该调用。

php.net网站提供了一些指导:

w32api_定义类型 w32api_init_数据类型 w32api_uu调用函数 w32api_寄存器_函数 w32api\u集合\u调用\u方法

最干净的方法是向Windows程序发送WM_CLOSE消息

我认为杀死Win32进程更残忍但有效的方法是使用pskill.exe

你可以在这里下载:

也可以按如下方式调用vbscript程序:

' ProcessKillLocal.vbs
' Sample VBScript to kill a program
' Author Guy Thomas http://computerperformance.co.uk/
' Version 2.7 - December 2010
' ------------------------ -------------------------------' 
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill 
strComputer = "."
'YOU NEED TO REPLACE calc.exe WITH THE APP YOU WISH TO KILL
strProcessKill = "'calc.exe'" 

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next 
WSCript.Echo "Just killed process " & strProcessKill _
& " on " & strComputer
WScript.Quit 
' End of WMI Example of a Kill Process 

你不能从PHP内部这样做,但是你可以使用
system
exec
调用一个cmdline应用程序来为你做这件事。我认为PHP能够调用winapino,除非你为它做一个自定义的C扩展。这个很好的工具为我做了这项工作。它可以:nircmd closeprocess processname我通过系统调用运行它