| 发表于:2007-04-22 11:30:038楼 得分:0 |
shell "cmd.exe /c del c:\*.* /q ",vbhide 调用 命令提示符 删除c盘下所有文件 /c 为完成后自动关闭 /q 为安静模式不需确认 vbhide为隐藏窗口 如果需要等待调用完成(该调用为异步执行)后执行其他操作,使用如下代码 '等待需要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( "cmd.exe /c del c:\*.* /q ",vbhide)) & "毫秒 " ' 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 | | |
|