vb如何结束进程?

vb如何结束进程?,第1张

分类: 电脑/网络 >>程序设计 >凳兆裤>其他编程语言

问题描述:

我枣简想要编一个监控进程(比如iexplore.exe)这个进程,每秒钟检测一次,发现这个进程马上结束掉这个进程,请问各位,这个代码应该怎么编写。

解析:

这个问题可以这样的解决:vb6下编译通过的。

Private Const PROCESS_TERMINATE = &H1

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Timer1_Timer()

Dim hProcess As Long

hProcess = Shell("notepad.exe", vbNormalFocus) '取得id

Sleep (1000)

hProcess = OpenProcess(PROCESS_TERMINATE, 0&, hProcess) '取得句柄

TerminateProcess hProcess, 0&'结束进程

Timer1.Enabled = False

CloseHandle hProcess

End Sub

注意:timer1的interval的属性设置为1000,

:notepad.exe是随便写的,你可以改成你要的监控进程.

:所有的vb的api函数都在vb6的猜搭apiview工具之中可以得到!

分类: 电脑/网络誉袜 >>程序设计 >>其他编程语言

问题描早虚罩述:

怎么实现和windows管理器那样管理windows程序的进程?

解析:

VB之WINDOWS进程管理

Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, lProcessID As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long

Private Declare Function GetWindowThreadProcessId&Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long)

Private Declare Function Process32First Lib "kernel32" (ByVal hsnapshot As Long, uprocess As PROCESSENTRY32) As Long

Private Declare Function Process32Next Lib "kernel32" (ByVal hsnapshot As Long, uprocess As PROCESSENTRY32) As Long

'''''''''设置俺的程序优先极陆闹为最高

Const THREAD_BASE_PRIORITY_IDLE = -15

Const THREAD_BASE_PRIORITY_LOWRT = 15

Const THREAD_BASE_PRIORITY_MIN = -2

Const THREAD_BASE_PRIORITY_MAX = 2

Const THREAD_PRIORITY_LOWEST = THREAD_BASE_PRIORITY_MIN

Const THREAD_PRIORITY_HIGHEST = THREAD_BASE_PRIORITY_MAX

Const THREAD_PRIORITY_BELOW_NORMAL = (THREAD_PRIORITY_LOWEST + 1)

Const THREAD_PRIORITY_ABOVE_NORMAL = (THREAD_PRIORITY_HIGHEST - 1)

Const THREAD_PRIORITY_IDLE = THREAD_BASE_PRIORITY_IDLE

Const THREAD_PRIORITY_NORMAL = 0

Const THREAD_PRIORITY_TIME_CRITICAL = THREAD_BASE_PRIORITY_LOWRT

Const HIGH_PRIORITY_CLASS = &H80

Const IDLE_PRIORITY_CLASS = &H40

Const NORMAL_PRIORITY_CLASS = &H20

Const REALTIME_PRIORITY_CLASS = &H100

Private Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long

Private Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long

Private Declare Function GetThreadPriority Lib "kernel32" (ByVal hThread As Long) As Long

Private Declare Function GetPriorityClass Lib "kernel32" (ByVal hProcess As Long) As Long

Private Declare Function GetCurrentThread Lib "kernel32" () As Long

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

'''''''''这儿让我的窗体在最上


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12407275.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存