Lancement d'un executable sans qu'on le voit dans la barre des taches

Thanos_the_yopper Messages postés 309 Date d'inscription vendredi 9 janvier 2004 Statut Membre Dernière intervention 5 mars 2009 - 28 mai 2004 à 14:30
cs_Nanto Messages postés 32 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 21 décembre 2009 - 17 juin 2004 à 17:37
voila, je lance un executable à partir de mon programme VB6 avec ce code là :

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Const STILL_ACTIVE = &H103
Private Const PROCESS_QUERY_INFORMATION = &H400

Public Sub ShellWait(ByVal JobToDo As String)
    Dim hProcess As Long, RetVal As Long
    
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, vbMinimizedNoFocus))
    Do
        GetExitCodeProcess hProcess, RetVal
        DoEvents
        Sleep 100
    Loop While RetVal = STILL_ACTIVE
End Sub


et en fait, quand je fais ça, on voit la fenetre DOS dans la barre des taches de windows ... est-ce qu'il y aurait un moyen pour la masquer directement avec VB ? Ou est-ce qu'il faut forcement compiler l'exe appelé pour qu'il n'apparaisse pas ?

Final Fantasy Memories Venez découvrir les origines d'une saga

1 réponse

cs_Nanto Messages postés 32 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 21 décembre 2009
17 juin 2004 à 17:37
Bonjour,

pour lancer un prog utilise plutot la procedure "createprocess"
dans laquelle tu peux utiliser des infos pour cacher, minimiser... la fenêtre du prog lancée, ex :

'Exécution de programmes externes
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal Object As Long) As Long

Private Const NORMAL_PRIORITY_CLASS As Long = &H20&
Private Const INFINITE As Long = -1&
Private Const STARTF_USESHOWWINDOW As Long = &H1
Public Const SW_HIDE As Long = 0
Public Const SW_NORMAL As Long = 1
Public Const SW_MAXIMIZE As Long = 3
Public Const SW_MINIMIZE As Long = 6

'cette fonction éxécute un prog externe en lui passant
'comme param le chemin du prog, et son status (maxi,
'mini,'caché)
Public Function fExec(ByRef p_sProg As String, Optional ByVal p_lStatus As Long) As Boolean
Dim piProc As PROCESS_INFORMATION
Dim siStart As STARTUPINFO
Dim lRet As Long

Err.Clear
On Error GoTo GestErr

siStart.cb = Len(siStart)
siStart.dwFlags = STARTF_USESHOWWINDOW
siStart.wShowWindow = p_lStatus
lRet = CreateProcessA(0&, p_sProg, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, siStart, piProc)
If lRet = 0 Then
fExec = False
Exit Function
End If
DoEvents
lRet = WaitForSingleObject(piProc.hProcess, INFINITE)
DoEvents
lRet = CloseHandle(piProc.hProcess)
fExec = True
Exit Function

GestErr:
MsgBox Err.Number & " " & Err.Description
fExec = False
End Function

voilà @ plus
Nanto
0
Rejoignez-nous