<
您还没有登录┊登录注册 当前在线:1386
源码程序系统工具编程开发图形图像网络软件应用软件多媒体类娱乐休闲驱动程序各类教程各类论文文章阅读
ASPPHPJSPASP.NETVBVF百度搜索星星练题网络文摘股市消息技能习题详细分类
当前位置:首页 \ 源码程序 \ 其它
站内搜索


如何定时关闭、重启应用程序

文件大小:15 k
运行平台:Windows9X/ME/NT/2000/XP
级别评定:
添加时间:2008-7-4 20:53:48
最后更新:2008-7-4 20:53:48
相关链接:无
所需金额:0 元
添加者:管理员

Download.1 Download.2

/ ::软件简介:: / ::相关软件:: / ::软件点评:: /::上一个::/ ::下一个:: /
管理首页
我有一个应用程序(exe)需要每隔一小时就关闭、重启一次,应该怎样做?

1.一种方法

Project1.exe   为你得应用程序 


Option   Explicit 
Private   Declare   Function   ShellExecute   Lib   "shell32.dll "   Alias   "ShellExecuteA "   _ 
    (ByVal   hWnd   As   Long,   ByVal   lpOperation   As   String,   _ 
    ByVal   lpFile   As   String,   ByVal   lpParameters   As   String,   _ 
    ByVal   lpDirectory   As   String,   ByVal   nShowCmd   As   Long)   As   Long 
Private   Declare   Function   GetDesktopWindow   Lib   "user32 "   ()   As   Long 

Private   Sub   Timer1_Timer() 
ShellExecute   GetDesktopWindow,   "open ",   "D:\test\Project1.exe ",   vbNullString,   vbNullString,   1 
Unload   Me 
End   Sub 

请问这段代码是重启的吗?即先将应用程序先关闭再启动? 
如果不是重启只是启动的话是没有用的。
2、用windows自带的任务管理

3。
以下代码保存为 "ModFindProcess.bas ": 

Attribute   VB_Name   =   "ModFindProcess " 
'************************************************************************* 
'**模   块   名:ModFindProcess 
'**说         明:进程相关操作 
'**创   建   人:马大哈   http://www.m5home.com/ 
'**日         期:2006年3月18日 
'**修   改   人: 
'**日         期:2007年1月23日 
'**描         述:改进了结束进程的条件,可以根据PID来结束 
'**版         本:V1.3 
'************************************************************************* 
Option   Explicit 

Public   Declare   Function   ProcessFirst   Lib   "kernel32 "   Alias   "Process32First "   (ByVal   hSnapshot   As   Long,   uProcess   As   PROCESSENTRY32)   As   Long 
Public   Declare   Function   ProcessNext   Lib   "kernel32 "   Alias   "Process32Next "   (ByVal   hSnapshot   As   Long,   uProcess   As   PROCESSENTRY32)   As   Long 
Public   Declare   Function   CreateToolhelpSnapshot   Lib   "kernel32 "   Alias   "CreateToolhelp32Snapshot "   (ByVal   lFlags   As   Long,   lProcessID   As   Long)   As   Long 
Public   Declare   Function   TerminateProcess   Lib   "kernel32 "   (ByVal   hProcess   As   Long,   ByVal   uExitCode   As   Long)   As   Long 
Public   Declare   Function   OpenProcess   Lib   "kernel32 "   (ByVal   dwDesiredAccess   As   Long,   ByVal   bInheritHandle   As   Long,   ByVal   dwProcessId   As   Long)   As   Long 

Public   Const   FORMAT_MESSAGE_ALLOCATE_BUFFER   =   &H100 
Public   Const   FORMAT_MESSAGE_FROM_SYSTEM   =   &H1000 
Public   Const   TH32CS_SNAPPROCESS   As   Long   =   2& 
Public   Const   PROCESS_TERMINATE   =   1 

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   *   260 
End   Type 

Private   Type   MyProcess 
        ExeName   As   String 
        PID   As   Long 
End   Type 

Public   Function   CloseProcess(Optional   ByVal   ProName   As   String,   Optional   ByVal   PID   As   Long)   As   Integer 
        '传入进程名或PID,结束相应进程 
        Dim   tPID   As   Long 
        Dim   tPHwnd   As   Long 
        Dim   ProArr()   As   String,   PIDArr()   As   Long 
        Dim   I   As   Long 
        
        Call   ListProcess(ProArr,   PIDArr) 
        For   I   =   1   To   UBound(ProArr) 
                If   PIDArr(I)   =   PID   Or   ProArr(I)   =   ProName   Then             '配对进程ID或进程名 
                        Exit   For 
                End   If 
        Next   I 
        
        If   I   >   UBound(PIDArr)   Then   Exit   Function 
        tPID   =   PIDArr(I) 
        
        tPHwnd   =   OpenProcess(PROCESS_TERMINATE,   False,   tPID) 
        Debug.Print   tPHwnd 
        If   tPHwnd   Then 
                CloseProcess   =   TerminateProcess(tPHwnd,   0) 
        End   If 
End   Function 

Public   Function   FindProcess(ByVal   ProName   As   String,   Optional   ByRef   PID   As   Long)   As   Boolean 
        '传入进程名,如果进程存在,在PID里返回进程ID,函数返回True,否则返回Flase 
        'ProName:   指定进程名 
        'PID:   如果进程名存在,返回其PID 
        '返回值:   进程名存在返回TRUE,否则返回FALSE 
        Dim   ProArr()   As   String,   PIDArr()   As   Long 
        Dim   I   As   Long 
        
        Call   ListProcess(ProArr,   PIDArr) 
        For   I   =   1   To   UBound(ProArr) 
                If   ProArr(I)   =   ProName   Then 
                        PID   =   PIDArr(I) 
                        FindProcess   =   True 
                        Exit   For 
                End   If 
        Next   I 
End   Function 

Public   Function   ListProcess(ByRef   ProExeName()   As   String,   ByRef   ProPid()   As   Long) 
        '列出进程以及相应PID 
        'ProExeName():   进程名 
        'ProPid():   相应的PID 
        Dim   MyProcess   As   PROCESSENTRY32 
        Dim   mySnapshot   As   Long 
        Dim   ProData()   As   MyProcess 
        Dim   I   As   Long 
        
        ReDim   ProData(0) 
        
        MyProcess.dwSize   =   Len(MyProcess) 
        mySnapshot   =   CreateToolhelpSnapshot(TH32CS_SNAPPROCESS,   0&) 
        ProcessFirst   mySnapshot,   MyProcess 
        
        ReDim   Preserve   ProData(UBound(ProData)   +   1) 
        
        ProData(UBound(ProData)).ExeName   =   Left(MyProcess.szexeFile,   InStr(MyProcess.szexeFile,   Chr(0))   -   1) 
        ProData(UBound(ProData)).PID   =   MyProcess.th32ProcessID 
        
        'Debug.Print   ProData(UBound(ProData)).ExeName 
        
        MyProcess.szexeFile   =   " " 
        
        While   ProcessNext(mySnapshot,   MyProcess) 
                ReDim   Preserve   ProData(UBound(ProData)   +   1) 
                
                ProData(UBound(ProData)).ExeName   =   Left(MyProcess.szexeFile,   InStr(MyProcess.szexeFile,   Chr(0))   -   1) 
                ProData(UBound(ProData)).PID   =   MyProcess.th32ProcessID 
                
        '         Debug.Print   ProData(UBound(ProData)).ExeName 
                
                MyProcess.szexeFile   =   " " 
        Wend 
        
        ReDim   ProExeName(UBound(ProData)) 
        ReDim   ProPid(UBound(ProData)) 
        
        For   I   =   1   To   UBound(ProData) 
                With   ProData(I) 
                        ProExeName(I)   =   .ExeName 
                        ProPid(I)   =   .PID 
                End   With 
        Next   I 
End   Function 

使用: 

先用SHELL执行你的程序(程序最好用SHELL执行,方便),保存PID: 

hPid   =   shell( "x:\yourEXE.exe ") 

要结束时,作如下调用: 

CloseProcess   vbnullstring,hPid


4.

 yh1205 
 发表于:2007-08-02 00:47:487楼 得分:0 
帮你写一个简单的思路你看看 

'定义三个全局变量   B_Time   开始时间   S_Time   约定时间   N   时间差 
Dim   B_Time,   S_Time,   N   As   Date 

Private   Sub   Form_Load() 
'设置开始时间 
B_Time   =   Now 
'设置约定时间 
S_Time   =   "1:00:00 " 
End   Sub 

Private   Sub   Timer1_Timer() 
'计算时间差 
N   =   Now   -   B_Time 
'如果时间超过约定时间则运行 
If   N   > =   S_Time   Then 
        '加载程序 
        Shell   App.Path   +   "\yourname.exe ",   vbMaximizedFocus 
        '开始时间归位,为下一次计算做准备 
        B_Time   =   Now 
End   If 
End   Sub 

Timer1.Interval   设为1000就行了,每一秒检查一次 
 


 
CFan贫民
回复: 请问...如何定时重启一个程序
提供一个VBS的

set shell=createobject("wscript.shell")
do

相关软件
·王者软件定时运行、定时关机、定时开机、定时关闭程序


1分 0
2分 0
3分 0
4分 0
5分 0
共有 0 人打分
平均得分:0


按字符查询:ABCDEFGHIJKLMNOPQRSTUVWXYZ0~9中文
下载图示: - 附汉化补丁 - 附注册 - 会员软件 - 推荐 - 最新添加
Rainight, 星旺坡 联网备案号:41092802000212 豫ICP备19032584号-1 页面执行时间: 0.89秒
业务QQ:80571569 手机:13030322310