正在终止VB6应用程序的前一个实例
我到处寻找正确的方法来杀死VB6应用程序的前一个实例,但没有结果。如果主服务死亡,我们需要终止正在运行的应用程序的前一个实例,然后,当服务恢复时,只应加载新实例。我试图在以下函数中退出此代码:正在终止VB6应用程序的前一个实例,vb6,Vb6,我到处寻找正确的方法来杀死VB6应用程序的前一个实例,但没有结果。如果主服务死亡,我们需要终止正在运行的应用程序的前一个实例,然后,当服务恢复时,只应加载新实例。我试图在以下函数中退出此代码: Private Sub g_cServerInterface_FatalError(Error As enSvrReturns, ErrorString As String) Dim sMsg As String Dim result As VbMsgBoxResult m_bFatalError =
Private Sub g_cServerInterface_FatalError(Error As enSvrReturns, ErrorString As String)
Dim sMsg As String
Dim result As VbMsgBoxResult
m_bFatalError = True
UnFreeze
If m_cLanguageText Is Nothing Then
GoTo TheEnd 'Form not yet loaded - not yet logged on
End If
' m_NumFatalErrors = m_NumFatalErrors + 1
' If m_NumFatalErrors > 5 Then
' Functions.DevInfo "Unable to restart Manitou.", g_cLangText_General
' End
' End If
If Error <> SVRERR_NOT_CONNECTED Or RunningInDebugger() Then
sMsg = g_cLangText_General.GetText("A system error has occurred")
If ErrorString <> "" Then
sMsg = sMsg & ":" & vbCrLf & vbCrLf & ErrorString & vbCrLf & vbCrLf
Else
sMsg = sMsg & ". "
End If
sMsg = sMsg & g_cLangText_General.GetText("Press OK to attempt to restart or Cancel to quit.")
result = DevAskOkCancel(sMsg, Nothing)
Else
' Since we've been disconnected, attempt immediately to reconnect
result = vbOK
End If
If (result = vbOK) Then
On Local Error Resume Next
If InStr(g_CommandLine, "-U") = 0 Then
g_CommandLine = g_CommandLine & " -U" & g_cUser.id
End If
If InStr(g_CommandLine, "-P") = 0 Then
g_CommandLine = g_CommandLine & " -P" & g_cUser.Password
End If
Shell App.Path & "\" & App.EXEName & " " & g_CommandLine & " -X", vbNormalFocus
DoEvents
End If
TheEnd:
If (Not RunningInDebugger()) Then
' Running as compiled executable
' Specifies the exit code for the process, and for all threads that
' are terminated as a result of this call. Use the GetExitCodeProcess
' function to retrieve the process's exit value. Use the GetExitCodeThread
' function to retrieve a thread's exit value.
CoUninitialize
ExitProcess 0
Else
' Running from the IDE
End
End If
End Sub
Private Sub g_cServerInterface_FatalError(错误为enSvrReturns,错误字符串为String)
将sMsg设置为字符串
将结果变暗为VbMsgBoxResult
m_bCatalError=真
解冻
如果m_cLanguageText什么都不是
“转到结束”表单尚未加载-尚未登录
如果结束
'm_NumCatalErrors=m_NumCatalErrors+1
'如果m_NumFatalErrors>5,则
'Functions.DevInfo“无法重新启动Manitou.”,g_cLangText_General
"完!
"完"
如果错误SVRERR\u未连接或运行indebugger(),则
sMsg=g_cLangText_General.GetText(“发生系统错误”)
如果错误字符串为“”,则
sMsg=sMsg&“:”&vbCrLf&vbCrLf&ErrorString&vbCrLf&vbCrLf
其他的
sMsg=sMsg&“
如果结束
sMsg=sMsg&g_cLangText_General.GetText(“按OK尝试重新启动,或按Cancel退出”)
结果=DevAskOkCancel(sMsg,无)
其他的
'由于我们已断开连接,请立即尝试重新连接
结果=vbOK
如果结束
如果(结果=vbOK),则
关于本地错误,请继续下一步
如果InStr(g_命令行,“-U”)=0,则
g_CommandLine=g_CommandLine&“-U”&g_cUser.id
如果结束
如果InStr(g_命令行,“-P”)=0,则
g_CommandLine=g_CommandLine&“-P”&g_cUser.Password
如果结束
Shell App.Path&“\”&App.EXEName&“&g\u命令行&“-X”,vbNormalFocus
多芬特
如果结束
最后:
如果(不运行indebugger()),则
'作为已编译的可执行文件运行
'指定进程的退出代码,以及
'作为此调用的结果而终止。使用GetExitCodeProcess
'函数来检索进程的退出值。使用GetExitCodeThread
'函数来检索线程的退出值。
协商初始化
退出进程0
其他的
'从IDE运行
终点
如果结束
端接头
请注意,我已将CouncInitialize和ExitProcess 0 API调用添加到此。当服务恢复时,如何正确终止先前加载的实例?感谢Larry私有声明函数findwindowlib“user32”_ 别名“FindWindowA”(ByVal lpClassName作为字符串_ ByVal lpWindowName(作为字符串)长度相同 私有声明函数PostMessage Lib“user32”_ 别名“PostMessageA”(ByVal hwnd,只要_ ByVal wMsg,只要_ 拜瓦尔·瓦帕兰,只要_ lpram(如有)一样长 私有Const WM_CLOSE=&H10 专用子表单_加载() 作为字符串的Dim strCap 暗淡无光 模糊的长度 strCap=Me.Caption Me.Caption=“*”和strCap lngHwnd=FindWindow(ByVal vbNullString,ByVal strCap) 如果lngHwnd为0,则 PostMessage lngHwnd,WM_CLOSE,0&,0& 如果结束 Me.Caption=strCap
End Sub当您将其称为服务时,您的意思是它作为Windows服务运行吗?是的,我认为它作为Windows服务运行。请尝试此答案。