| 发表于:2007-12-03 16:26:526楼 得分:0 |
我怎么觉得这个代码我贴过。。搞不明白大家为什么都想知道人家的程序运行完没有。这个代码是老掉牙的了,可能老网站都关了? '等待需要api private const infinite = -1& private const synchronize = &h100000 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 declare function waitforsingleobject lib "kernel32" (byval hhandle as long, byval dwmilliseconds as long) as long '获取时间差需要api private declare function gettickcount lib "kernel32" () as long private sub form_click() 'shell "explorer http://www.dyjmgm.com/110/vote.asp", vbnormalfocus msgbox "所调用程序已经结束,该程序一共运行了:" & mwait(shell("notepad", vbnormalfocus)) & "毫秒" ' shell 函数返回值为 process id ,这里运行了记事本,当关闭记事本以后,就会弹出对话框 end sub '自定义等待函数,传入shell返回值就可以了,返回值为经过的时间 public function mwait(byval mpid as long) as long dim mtime as long mtime = gettickcount dim phnd as long ' process handle phnd = openprocess(synchronize, 0, mpid) ' 取得 process handle if phnd <> 0 then call waitforsingleobject(phnd, infinite) ' 无限等待,直到程序结束 call closehandle(phnd) '释放句柄资源 end if mwait = gettickcount - mtime end function 关键在于mwait函数,传入一个pid,既然你知道程序名,那么即使程序不是你打开的,也可以用这个函数,你先枚举进程列表,获取pid,传进去就可以了。 测试时点击一下窗体,然后关闭记事本即可看到效果。 | | |
|