如何退出外部exe程序?
我用下面的方法调用了外部程序:
DECLARE INTEGER ShellExecute IN shell32.DLL INTEGER HWND,STRING lpszOP,STRING lpszFile,STRING lpszParams,STRING lpszDir,INTEGER fsshowcmd
DECLARE INTEGER GetDesktopWindow IN win32api
HWND = GetDesktopWindow()
lpszOP = "open"
* 指定要打开的文件名
lpszFile ="c:\A.EXE"
lpszParams = ""
lpszDir = "c:\temp"
fsshowcmd = 1 &&0表示隐藏,1正常方式、2最小化方式、3最大化方式。
* 执行ShellExecute命令
LNRETURN = ShellExecute(HWND, lpszOP,lpszFile, lpszParams, lpszDir,fsshowcmd)
但是退出A.EXE这个程序怎么写?谢谢!!
[解决办法]
2:Exit_ProFileName='calc.exe' && calc.exe为计算器的系统进程名称If GetAllProcessID('Process_CurTable') Select Pth32ProcessID Into Array Exit_id From Process_CurTable Where Alltrim(Upper(PszExeFile))=Upper(Exit_ProFileName) If ExitProcessId(Exit_id) Messagebox('结束进程成功!',64,'信息提示') Else Messagebox('结束进程失败!',16,'信息提示') EndifEndif* -------------------------------------* 枚举当前所有进程* -------------------------------------Function GetAllProcessID ( lpProcTable ) lpProcTable = Iif(Parameters()=1 And Type([lpProcTable])=[C], lpProcTable, [AllProclists] ) Declare Integer CreateToolhelp32Snapshot In kernel32 Integer lFlags, Integer lProcessID Declare Integer Process32First In kernel32 Integer hSnapShot, String @PROCESSENTRY32_uProcess Declare Integer Process32Next In kernel32 Integer hSnapShot, String @PROCESSENTRY32_uProcess Declare Integer CloseHandle In kernel32 Integer hObject Declare Integer GetLastError In kernel32 Crea Cursor (lpProcTable) (PdwSize N(3), PcntUsage N(12), ; Pth32ProcessID N(12), Pth32DefaultHeapID N(12), ; Pth32ModuleID N(12), PcntThreads N(12), ; Pth32ParentProcessID N(12), PpcPriClassBase N(3), ; PdwFlags N(3), PszExeFile C(254) ) lnHand = 0 lnHand = CreateToolhelp32Snapshot(3,0) If lnHand>0 dwSize = Num2Dword(296) cntUsage = Num2Dword(0) th32ProcessID = Num2Dword(0) th32DefaultHeapID = Num2Dword(0) th32ModuleID = Num2Dword(0) cntThreads = Num2Dword(0) th32ParentProcessID = Num2Dword(0) pcPriClassBase = Num2Dword(0) dwFlags = Num2Dword(0) szExeFile = Repli(Chr(0), 260) lcTitle = dwSize + cntUsage + th32ProcessID + th32DefaultHeapID ; + th32ModuleID + cntThreads + th32ParentProcessID ; + pcPriClassBase + dwFlags + szExeFile If Process32First(lnHand,@lcTitle) > 0 && 第一个进程是 kernel32.dll,没必要列出 Do While Process32Next(lnHand,@lcTitle)> 0 Insert Into (lpProcTable) (PdwSize, PcntUsage, Pth32ProcessID, Pth32DefaultHeapID, ; Pth32ModuleID, PcntThreads, Pth32ParentProcessID, ; PpcPriClassBase, PdwFlags, PszExeFile) ; VALUES ( ; Dword2Num(Substr(lcTitle, 1,4)), ; Dword2Num(Substr(lcTitle, 5,4)), ; Dword2Num(Substr(lcTitle, 9,4)), ; Dword2Num(Substr(lcTitle,13,4)), ; Dword2Num(Substr(lcTitle,17,4)), ; Dword2Num(Substr(lcTitle,21,4)), ; Dword2Num(Substr(lcTitle,25,4)), ; Dword2Num(Substr(lcTitle,29,4)), ; Dword2Num(Substr(lcTitle,33,4)), ; SUBSTR(Substr(lcTitle, 37), 1, At(Chr(0),Substr(lcTitle, 37))-1) ) Enddo Endif = CloseHandle(lnHand) Return .T. Else Return .F. EndifEndfuncFunction Num2Dword ( lpnNum ) Declare Integer RtlMoveMemory In kernel32 As RtlCopyDword String @pDeststring, Integer @pVoidSource, Integer nLength lcDword = Space(4) = RtlCopyDword(@lcDword, Bitor(lpnNum,0), 4) Return lcDwordEndfuncFunction Dword2Num ( tcDword ) Declare Integer RtlMoveMemory In kernel32 As RtlCopyNum Integer @DestNumeric, String @pVoidSource, Integer nLength lnNum = 0 =RtlCopyNum(@lnNum, tcDword, 8) Return lnNumEndfunc* -------------------------------------* 从 ProcessId 关闭进程* -------------------------------------Function ExitProcessId ( lpnProcessId ) Declare Integer TerminateProcess In kernel32 Integer hProcess , Integer uExitCode Declare Integer OpenProcess In kernel32 Integer dwDesiredAccess, Integer binheritHandle, Integer dwProcessId Declare Integer GetCurrentProcessId In kernel32 If lpnProcessId = GetCurrentProcessId() Return .F. Else hproc = OpenProcess(2035711, 0, lpnProcessId) && 从进程 ID 获得进程句柄 If hproc = 0 Return .F. Else = TerminateProcess(hproc, 0) && 关闭进程 Return .T. Endif EndifEndfunc