VFP 结束进程 !

yrt888 2008-06-13 01:59:13
我是用这种方法来结束进程的: RUN /N TASKKILL /F /PID 进程ID

现在想问一下,在VFP下有没有同等功效(强制性)的方法呢?谢谢各位大侠!
...全文
125 7 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yrt888 2008-06-14
冰刃果然厉害,开着禁止新进程,不小程序出错!
  • 打赏
  • 举报
回复
yrt888 2008-06-13
是啊,我也知道我的那种方法很方便,不过我现在尝试先打开冰刃,启用冰刃的防止创建新进程的功能来浏览网页,有时候上了一些有问题的网页,系统内存或虚拟内存会迅速消耗,这是我的小程序就使用我的上述办法,来结束马桶浏览器,现在想了一想,我的方法是利用DOS的,会不会冰刃不让我执行了,若是程序内部的命令就应该可以执行的!
  • 打赏
  • 举报
回复
十豆三 2008-06-13
Declare Integer WinExec in kernel32 string, integer
MyCommand="TASKKILL /F /PID "+进程ID
= WinExec (MyCommand,0)
Clear Dlls

这样就不会有Command窗口了。
  • 打赏
  • 举报
回复
yrt888 2008-06-13
正在尝试!。。。
  • 打赏
  • 举报
回复
十豆三 2008-06-13
所以你的方法最简单。
  • 打赏
  • 举报
回复
十豆三 2008-06-13
VFP中如何结束(系统)进程?

*-----------------------------------------

参考文章:
http://www.onlyred.com/computer/system/windows/200512/96.html

-----------------------------------------------------------------

方法一:可以结束除System、SMSS.EXE和CSRSS.EXE外所有进程

******只有System、SMSS.EXE和CSRSS.EXE不能结束。前两个是纯内核态的,最后那个是Win32子系统

Exit_ProFileName='sqlservr.exe' && sqlservr.exe为要结束的系统进程名称
IF GetAllProcessID('Process_CurTable')
SELECT Pth32ProcessID INTO ARRAY Exit_id FROM Process_CurTable WHERE ALLTRIM(UPPER(PszExeFile))=UPPER(Exit_ProFileName)
lcString='RUN /N7 ntsd -c q -p '+ALLTRIM(STR(Exit_id))
&lcString
ENDIF

* -------------------------------------
* 枚举当前所有进程
* -------------------------------------
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.
ENDIF
ENDFUNC

FUNCTION 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 lcDword
ENDFUNC

FUNCTION Dword2Num ( tcDword )
DECLARE INTEGER RtlMoveMemory IN kernel32 AS RtlCopyNum INTEGER @DestNumeric, STRING @pVoidSource, INTEGER nLength
lnNum = 0
=RtlCopyNum(@lnNum, tcDword, 8)
RETURN lnNum
ENDFUNC






-----------------------------------------------------------------

方法二:可以结束非系统进程

Exit_ProFileName='QQ.exe' && QQ.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,'信息提示')
ENDIF
ENDIF

* -------------------------------------
* 枚举当前所有进程
* -------------------------------------
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.
ENDIF
ENDFUNC

FUNCTION 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 lcDword
ENDFUNC

FUNCTION Dword2Num ( tcDword )
DECLARE INTEGER RtlMoveMemory IN kernel32 AS RtlCopyNum INTEGER @DestNumeric, STRING @pVoidSource, INTEGER nLength
lnNum = 0
=RtlCopyNum(@lnNum, tcDword, 8)
RETURN lnNum
ENDFUNC

* -------------------------------------
* 从 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
ENDIF
ENDFUNC
  • 打赏
  • 举报
回复
十豆三 2008-06-13
VFP本身没有,需要用到API
  • 打赏
  • 举报
回复
相关推荐
发帖
VFP

2545

社区成员

VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
帖子事件
创建了帖子
2008-06-13 01:59
社区公告
暂无公告