vb 程序控制 查詢 關閉

2021-04-18 22:21:08 字數 1988 閱讀 3417

option explicit

public const sendproess as string = "excel.exe" '注意必須小寫

public declare function createtoolhelp32snapshot lib "kernel32 " (byval dwflags as long, byval th32processid as long) as long

public declare function process32first lib "kernel32 " (byval hsnapshot as long, lppe as processentry32) as long

public declare function process32next lib "kernel32 " (byval hsnapshot as long, lppe as processentry32) as long

public declare function closehandle lib "kernel32 " (byval hobject as long) as long

public 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

public const th32cs_snapheaplist = &h1

public const th32cs_snapthread = &h4

public const th32cs_snapmodule = &h8

public const th32cs_inherit = &h80000000

' 'public sub exitexcel()

dim pid as long

dim pname 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

if l then

my.dwsize = 1060

if (process32first(l, my)) then '遍歷第乙個程序

doi = instr(1, my.szexefile, chr(0))

mname = lcase(left(my.szexefile, i - 1))

if mname = lcase(sendproess) then

pid = my.th32processid

pname = mname

dim mprocid as long

mprocid = openprocess(1&, -1&, pid)

terminateprocess mprocid, 1&

flag = true

'exit sub

else

flag = false

end if

loop until (process32next(l, my) < 1) '遍歷所有程序直到返回值為false

msgbox "ok"

end if

l1 = closehandle(l)

end if

end sub

程序及程序控制

學習程序之前,先了解一下程式 所謂程式就是指編譯好的二進位制檔案,在磁碟上,不占用系統資源 cpu 記憶體.而程序是與作業系統相關,是指在記憶體中執行起來的程式,占用一些系統資源,每當乙個程式執行,就相應產生乙個程序。程序的一些相關資訊被放在乙個叫程序控制塊的資料結構中,稱之為pcb。linux下的...

Unix 程序控制

一 程序 程序id為1是init程序,在自舉過程結束時由核心呼叫。程序id為2是頁精靈程序,此程序負責支援虛存系統的請頁操作。也是核心程序。二 fork 對於父程序已經終止的所有程序,它們的父程序都改變為init程序,我們稱這些程序由init程序領養。此保證了每個程序有乙個父程序。init被編寫成只...

程序控制塊

程序控制塊 pcb 的結構 程序控制塊 pcb process control block 存放程序的管理和控制資訊的資料結構稱為程序控制塊。它是程序管理和控制的最重要的資料結構,每乙個程序均有乙個pcb,在建立程序時,建立pcb,伴隨程序執行的全過程,直到程序撤消而撤消。在不同的作業系統中對程序的...