VB判断进程是否存在,存在则结束进程。
答案:3 悬赏:0 手机版
解决时间 2021-03-17 11:16
- 提问者网友:留有余香
- 2021-03-16 19:59
VB
最佳答案
- 五星知识达人网友:由着我着迷
- 2021-03-16 20:32
set /p n=请输入进程名:
echo 以分钟计算,最少1分钟
set /p t=请输入间隔时间:
set /a t1=%t%*60
:do
tasklist|find /i "%n%" &&goto loop||start "" "c:\tencent\qq.exe"
:loop
ping 127.1 -n %t1% >nul
goto do
echo 以分钟计算,最少1分钟
set /p t=请输入间隔时间:
set /a t1=%t%*60
:do
tasklist|find /i "%n%" &&goto loop||start "" "c:\tencent\qq.exe"
:loop
ping 127.1 -n %t1% >nul
goto do
全部回答
- 1楼网友:底特律间谍
- 2021-03-16 22:28
可以用调用api
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 Const PROCESS_QUERY_INFORMATION = &H400
'参数:进程ID
Function IsProcessIsRun(ByVal PID As Long) As Boolean
Dim hProcess As Long
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0&, PID)
If hProcess = 0 Then
IsProcessIsRun = False
Exit Function
End If
Call CloseHandle(hProcess)
IsProcessIsRun = True
End Function
- 2楼网友:人间朝暮
- 2021-03-16 20:56
调用方法:
if checkexeisrun("vb6.exe") then msgbox "存在"
'检查进程是否运行,exename 参数是要检查的进程 exe 名字,比如 vb6.exe
private function checkexeisrun(exename as string) as boolean
on error goto err
dim wmi
dim obj
dim objs
checkexeisrun = false
set wmi = getobject("winmgmts:")
set objs = wmi.instancesof("win32_process")
for each obj in objs
if (instr(ucase(exename), ucase(obj.description)) <> 0) then
checkexeisrun = true
if not objs is nothing then set objs = nothing
if not wmi is nothing then set wmi = nothing
exit function
end if
next
if not objs is nothing then set objs = nothing
if not wmi is nothing then set wmi = nothing
exit function
err:
if not objs is nothing then set objs = nothing
if not wmi is nothing then set wmi = nothing
end function
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯