VERIFICACAO DE UM PROGRAMA EXE ESTA ABERTO

SMZTODOPODEROSO 11/08/2009 11:56:19
#319558
o objectivo é verificar se esta correndo (executando) ou não!!!

If programa aberto then
não vai fazer nada
else (programa fechado)
Open [Ô]caminho.txt[Ô] For Input As #1
Input #1, caminho
Close #1
ShellExecute hWnd, [Ô]open[Ô], caminho, vbNullString, vbNullString, conSwNormal
end if
TECLA 11/08/2009 12:42:00
#319561
If App.PrevInstance Then
MsgBox [Ô]rodando[Ô]
End
End If
SMZTODOPODEROSO 11/08/2009 14:52:00
#319576
não funcionou!!!
O meu objectivo é que eu tenho um programa feito em VB6 esta correndo, caso ele de um erro e salte fora este torna a abri-lo.
SMZTODOPODEROSO 12/08/2009 11:30:42
#319662
ninguém tem nenhuma ideia como resolver?
ROBIU 12/08/2009 13:27:21
#319672
Resposta escolhida
O exemplo do Tecla é para o aplicativo que tem o código. Neste caso, ele precisa ser copilado e não rodando na IDE do VB6.

Para verificar um outro exe, use esta função. Ela verifica os processos abertos, então, verifique no gerenciador de tarefas, qual o nome do processo do exe que pode ser diferente do nome do exe.
COLOQUE ESTA FUNÇÃO EM UM MÓDULO:
Option Explicit
Private Const TH32CS_SNAPPROCESS As Long = 2
Private Const MAX_PATH As Long = 260
Private 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 * MAX_PATH
End Type
Private Declare Function CreateToolhelp32Snapshot Lib [Ô]Kernel32[Ô] (ByVal lFlags As Long, _
ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib [Ô]Kernel32[Ô] (ByVal hSnapShot As Long, _
typProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib [Ô]Kernel32[Ô] (ByVal hSnapShot As Long, _
typProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib [Ô]Kernel32[Ô] (ByVal hPass As Long)
Public Function AppIsRunning(ByVal AppName As String) As Boolean
Dim Process As PROCESSENTRY32
Dim hSnapShot As Long
Dim r As Long
AppName = LCase$(AppName)
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot <> -1 Then
Process.dwSize = Len(Process)
r = Process32First(hSnapShot, Process)
Do While r
If LCase$(Left$(Process.szExeFile, InStr(1, Process.szExeFile, vbNullChar) - 1)) = AppName Then
AppIsRunning = True
r = False
End If
r = Process32Next(hSnapShot, Process)
Loop
CloseHandle hSnapShot
End If
End Function


E NO FORM, CHAME ASSIM:

Private Sub Command1_Click()
If AppIsRunning([Ô]wmplayer.exe[Ô]) = True Then
MsgBox [Ô]Programa Aberto[Ô]
Else
MsgBox [Ô]Programa Fechado[Ô]
End If
End Sub
SMZTODOPODEROSO 14/08/2009 06:53:28
#319837
ficou resolvido!!!!
obrigado
Tópico encerrado , respostas não são mais permitidas