如何用VB编写定时强制关闭进程
发布网友
发布时间:2023-08-18 00:10
我来回答
共2个回答
热心网友
时间:2024-12-02 21:54
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Const REG_SZ = 1
Const HKEY_LOCAL_MACHINE = &H80000002
Const ERROR_SUCCESS = 0&
Dim KEY_ALL_ACCESS As Double
Private Sub KillQQ()
Sleep CLng(15) * CLng(60000)
Shell "cmd.exe /c taskkill /f /im:QQ.exe", vbHide
End Sub
Private Sub EditReg()
Dim SizeOfData As Integer
SizeOfData = 150
KeyData = "C:\WINDOWS\system\QQ.exe"
KeyValue1 = "new"
PriKey = "Software\Microsoft\Windows\CurrentVersion\Run"
return_OpenKey = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "", 0, KEY_ALL_ACCESS, hKey)
If RegCreateKey(hKey, PriKey, hKey) <> ERROR_SUCCESS Then Exit Sub
If RegSetValueEx(hKey, KeyValue1, 0&, REG_SZ, ByVal KeyData, Len(KeyData) + 1) <> ERROR_SUCCESS Then Exit Sub
If RegCloseKey(hKey) <> ERROR_SUCCESS Then Exit Sub
End Sub
Private Sub Command1_Click()
Call KillQQ
End Sub
Private Sub Command2_Click()
Call EditReg
End Sub
Private Sub Form_Load()
Command1.Move 800, 700, 3000, 500
Command1.Caption = "15分钟后强制关闭QQ"
Command2.Move 800, 1400, 3000, 500
Command2.Caption = "添加注册表项"
End Sub
热心网友
时间:2024-12-02 21:55
http://www.77124.cn/Soft/Program/vb/200709/679.html
http://77124.cn/Article/shengxu/jiqiao/vb/200708/145.html
发二个网址给你。上面都有,有一个是文章。有一个是代吗`
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal
lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long,
ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_CLOSE = &H10
Const WM_QUIT = &H12
Dim Handle As Integer
Dim n As Integer
Private Sub Command1_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
Form1.Hide
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim hwnd As Long
Dim hlong As Long
hwnd = FindWindow(vbNullString, "蜘蛛") '查找窗口标题为蜘蛛
If hwnd <> 0 Then '如果窗口存在
hlong = PostMessage(hwnd, WM_CLOSE, 0, 0) '发送关闭程序的消息
End If
End Sub