vb 关闭打开的外部程序。
PrivateConstKEYEVENTF_EXTENDEDKEY=&H1PrivateConstKEYEVENTF_KEYUP=&H2Dimk1,k2,k3SubSen...
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Dim k1, k2, k3
Sub SendKeyToWnd(vbkey As KeyCodeConstants)
keybd_event vbkey, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event vbkey, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
End Sub
Private Sub Command6_Click()
Shell App.Path & "\1.exe", 1
SendKeyToWnd (vbKeySpace)
End Sub
打开1.exe了,我想请问隔30秒后自动关闭1.exe该加入什么代码?
关闭EXE的时候我是在游戏里,希望不要影响游戏,不会弹到桌面。
不知不觉的关闭1.exe 展开
Private Const KEYEVENTF_KEYUP = &H2
Dim k1, k2, k3
Sub SendKeyToWnd(vbkey As KeyCodeConstants)
keybd_event vbkey, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event vbkey, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
End Sub
Private Sub Command6_Click()
Shell App.Path & "\1.exe", 1
SendKeyToWnd (vbKeySpace)
End Sub
打开1.exe了,我想请问隔30秒后自动关闭1.exe该加入什么代码?
关闭EXE的时候我是在游戏里,希望不要影响游戏,不会弹到桌面。
不知不觉的关闭1.exe 展开
2个回答
展开全部
添加timer控件,intervel=30000
在timer事件里写
Call taskkill("xx.exe")'如果存在进程xx.exe,则结束xx.exe
在空白处写
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject 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 TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * 1024
End Type
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Dim pid As Long
Dim pname As String
Private Sub taskkill(ByVal taskname As String)
Dim my As PROCESSENTRY32
Dim l As Long
Dim l1 As Long
Dim flag As Boolean
Dim mName As String
Dim i As Integer
l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If l Then
my.dwSize = 1060
If (Process32First(l, my)) Then
Do
i = InStr(1, my.szExeFile, Chr$(0))
mName = LCase$(Left$(my.szExeFile, i - 1))
If mName = LCase$(taskname) Then
pid = my.th32ProcessID
pname = mName
Dim mProcID As Long
mProcID = OpenProcess(1&, -1&, pid)
TerminateProcess mProcID, 0&
flag = True
Else
flag = False
End If
Loop Until (Process32Next(l, my) < 1)
l1 = CloseHandle(l)
End If
End Sub
在timer事件里写
Call taskkill("xx.exe")'如果存在进程xx.exe,则结束xx.exe
在空白处写
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject 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 TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * 1024
End Type
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Dim pid As Long
Dim pname As String
Private Sub taskkill(ByVal taskname As String)
Dim my As PROCESSENTRY32
Dim l As Long
Dim l1 As Long
Dim flag As Boolean
Dim mName As String
Dim i As Integer
l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If l Then
my.dwSize = 1060
If (Process32First(l, my)) Then
Do
i = InStr(1, my.szExeFile, Chr$(0))
mName = LCase$(Left$(my.szExeFile, i - 1))
If mName = LCase$(taskname) Then
pid = my.th32ProcessID
pname = mName
Dim mProcID As Long
mProcID = OpenProcess(1&, -1&, pid)
TerminateProcess mProcID, 0&
flag = True
Else
flag = False
End If
Loop Until (Process32Next(l, my) < 1)
l1 = CloseHandle(l)
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
shell "taskkill /f /im 1.exe" ,vbnormalnofocus
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询