VB程式怎麼判斷另乙個程式是否正在執行

2021-04-12 14:45:01 字數 1671 閱讀 6747

用findwindows函式查詢

private declare function findwindow lib "user32" alias "findwindowa" (byval lpclassname as string, byval lpwindowname as string) as long

private sub form_load()

dim winwnd as long, ret as string, retval as long, lpclassname as string

'ask for a window title

ret = inputbox("enter the exact window title:" + chr$(13) + chr$(10) + "note: must be an exact match")

'search the window

winwnd = findwindow(vbnullstring, ret)

if winwnd = 0 then msgbox "couldn't find the window ...": exit sub

end sub

private declare function createfile lib "kernel32" alias "createfilea" (byval lpfilename as string, byval dwdesiredaccess as long, byval dwsharemode as long, lpsecurityattributes as string, byval dwcreationdisposition as long, byval dwflagsandattributes as long, byval htemplatefile as long) as long

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

private const generic_read = &h80000000

private const generic_write = &h40000000

private const open_existing = 3

private const file_attribute_normal = &h80

private const invalid_handle_value = -1

private function isfilerun(byval pfile as string) as boolean

dim ret as long

ret = createfile(pfile, generic_read or generic_write, 0&, vbnullstring, open_existing, file_attribute_normal, 0&)

isfilerun = (ret = invalid_handle_value)

closehandle ret

end function

用法:if dir("c:/myfile.exe")<>"" and isfilerun("c:/myfile.exe") then msgbox "檔案c:/myfile.exe已執行!"

說明:由於這個函式在檔案不存在的情況下也會返回true,所以要先用dir檢查一下檔案是否存在。

iOS 呼叫另乙個程式

在 ios 裡,程式之間都是相互隔離,目前並沒有乙個有效的方式來做程式間通訊,幸好 ios 程式可以很方便的註冊自己的 url scheme,這樣就可以通過開啟特定 url 的方式來傳遞引數給另外乙個程式。例如在 ipad 上瀏覽網頁,並且 ipad 已經安裝了 hd,那麼就開啟下面這個鏈結就會在 ...

在程式在生成另乙個程式

在程式在生成另乙個程式 乙個已經初始化另乙個未初始化?僅僅如此?其實,還有乙個更簡單的方法 就是先看一下i的位址,一般來講,它的位址是40 x,那麼它在檔案中的位址就是 x 不同的編譯器可能有不同的結果,我用的是vc6.0 來到這裡,你應該知道如何指定程式裡的email或 了吧?請把下面的程式生成e...

Android乙個程式使用另乙個程式的資源

應用場景 程式a的乙個imageview使用程式b的資源。前提 知道程式b的包名。關鍵 如下 是可以呼叫其他程式的 context.context ignore security 是資源 兩個一起寫都可以 context othercontext getcontext createpackageco...