当前位置: 网学 > 编程文档 > VB > 正文

进程死亡的自动复活

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式
tributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function WaitForInputIdle Lib "user32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long




Private Sub command1_Click()
    Dim res&
    Dim sinfo As STARTUPINFO
    Dim pinfo As PROCESS_INFORMATION
    sinfo.cb = Len(sinfo)
    sinfo.lpReserved = vbNullString
    sinfo.lpDesktop = vbNullString
    sinfo.lpTitle = vbNullString
    sinfo.dwFlags = 0
    
    Label1.Caption = "正在启动程序"
    Label1.Refresh
   '' CreateProcess函数,用于创建一个新的进程
    res = CreateProcess(DemoFile, vbNullString, 0, 0, True, _
                       NORMAL_PRIORITY_CLASS, ByVal 0&, vbNullString, sinfo, pinfo)
    If res Then
        Label1.Caption = "程序正在运行中"
        WaitForTerm pinfo
        Label1.Caption = "程序已经结束"
    Else
        Label1.Caption = "启动程序时出错,可能未正确输入" & Chr(13) & "程序名或程序所在路径。"
    End If
End Sub

Private Sub WaitForTerm(pinfo As PROCESS_INFORMATION)
    Dim res&
    Dim res1&
    '' 等待指定的进程进入空闲状态,,空闲(Idle)指的是进程准备处理一条消息、但目前暂时没有消息需要处理的一种状态
    Call WaitForInputIdle(pinfo.hProcess, INFINITE)
    Command1.Enabled = False
    Command2.Enabled = True
    Label1.Refresh
    Do
       If Flag Then Exit Do
       
        ''等待发出信号
        res = WaitForSingleObject(pinfo.hProcess, 0)
        If res <> WAIT_TIMEOUT Then      ''如果对象发出了信号
           command1_Click
                     
           Exit Do
        End If
  &
  • 上一篇资讯: MASM-打字练习程序
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号