2013-01-07 31 views
0

我是一名php開發人員,並且想使用php +一些windows api來執行任務。問另一個windows應用程序使用php關閉

任務是:很好地詢問正在運行的Windows應用程序以關閉它自己。

用php做這件事當然不是很自然,但我正在用php編寫我的小腳本,因爲這是我現在使用的語言,並且很適合。

+0

你不能這樣做,從內PHP,但你可以使用'系統'或'exec'調用一個cmdline應用程序,將爲你做這個 – pocesar

+0

我認爲php是能夠打電話給winapi – shealtiel

+0

不,除非你自定義的C擴展名爲 – pocesar

回答

1

PHP中有some支持來調用win32 API。但是,看起來這個擴展的穩定性不是很好。

我認爲您可以做的最好的方法就是使用system調用。

+0

這個漂亮的工具http://www.nirsoft.net/utils/nircmd2.html爲我完成了這項工作。它可以:nircmd closeprocess進程名稱 我使用系統調用運行它 – shealtiel

1

的php.net網站提供一些指導:

http://php.net/manual/en/book.w32api.php

w32api_deftype w32api_init_dtype w32api_ invoke_function w32api_register_function w32api_set_call_method

最乾淨的方法是發送一個WM_CLOSE消息發送到Windows程序。

我殺死一個Win32進程更殘酷但有效的方法是使用pskill.exe。

您可以在這裏下載: http://technet.microsoft.com/en-us/sysinternals/bb896683.aspx

您也可以撥打到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 
相關問題