Accueil > > > LANCER UN EXECUTABLE ET ATTENDRE SA FIN
LANCER UN EXECUTABLE ET ATTENDRE SA FIN
Information sur la source
Description
Coller cette source dans un module de code VB6, la fonction LanceApp permet de lancer un executable et d'attendre quelle se termine. Une fois cette tache finie, elle retourne le code exit de l'appli lancée
Source
- Public Const INFINITE = &HFFFF
- Public Const STARTF_USESHOWWINDOW = &H1
-
- Public Enum enSW
- SW_HIDE = 0
- SW_NORMAL = 1
- SW_MAXIMIZE = 3
- SW_MINIMIZE = 6
- End Enum
-
- Public Type PROCESS_INFORMATION
- hProcess As Long
- hThread As Long
- dwProcessId As Long
- dwThreadId As Long
- End Type
-
- Public 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 Byte
- hStdInput As Long
- hStdOutput As Long
- hStdError As Long
- End Type
-
- Public Type SECURITY_ATTRIBUTES
- nLength As Long
- lpSecurityDescriptor As Long
- bInheritHandle As Long
- End Type
-
- Public Enum enPriority_Class
- NORMAL_PRIORITY_CLASS = &H20
- IDLE_PRIORITY_CLASS = &H40
- HIGH_PRIORITY_CLASS = &H80
- End Enum
-
- Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
-
- Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
-
- Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
-
-
- Public Function LanceApp(Appli As String, Arg As String, Timeout As Long, ByVal StartSize As enSW, ByVal Priority_Class As enPriority_Class) As Long
- LanceApp = 259
- Dim pclass As Long
- Dim Ret As Long
- Dim cmdline As String
- Dim sinfo As STARTUPINFO
- Dim pinfo As PROCESS_INFORMATION
- Dim sec1 As SECURITY_ATTRIBUTES
- Dim sec2 As SECURITY_ATTRIBUTES
- Dim hMutex As Long
-
- sec1.nLength = Len(sec1)
- sec2.nLength = Len(sec2)
- sinfo.cb = Len(sinfo)
- sinfo.dwFlags = STARTF_USESHOWWINDOW
- sinfo.wShowWindow = StartSize
- pclass = Priority_Class
-
- cmdline = Appli
- If (Len(Trim$(Arg)) > 0) Then
- cmdline = cmdline & " " & Arg
- End If
-
- Debug.Print " cmdLine : " & cmdline
-
- If CreateProcess(vbNullString, cmdline, sec1, sec2, False, pclass, 0&, CurDir$(), sinfo, pinfo) Then
- Debug.Print " CreateProcess OK"
- Ret = 259
- While (Ret = 259)
- WaitForSingleObject pinfo.hProcess, Timeout
- DoEvents
- If (GetExitCodeProcess(pinfo.hProcess, Ret) = 1) Then
- Debug.Print " GetExitCodeProcess OK"
- LanceApp = Ret
- Else
- Debug.Print " GetExitCodeProcess KO"
- End If
- Wend
- Else
- Debug.Print " CreateProcess KO : " & Err.LastDllError
- End If
-
-
- End Function
Public Const INFINITE = &HFFFF
Public Const STARTF_USESHOWWINDOW = &H1
Public Enum enSW
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End Enum
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Public 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 Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Enum enPriority_Class
NORMAL_PRIORITY_CLASS = &H20
IDLE_PRIORITY_CLASS = &H40
HIGH_PRIORITY_CLASS = &H80
End Enum
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Public Function LanceApp(Appli As String, Arg As String, Timeout As Long, ByVal StartSize As enSW, ByVal Priority_Class As enPriority_Class) As Long
LanceApp = 259
Dim pclass As Long
Dim Ret As Long
Dim cmdline As String
Dim sinfo As STARTUPINFO
Dim pinfo As PROCESS_INFORMATION
Dim sec1 As SECURITY_ATTRIBUTES
Dim sec2 As SECURITY_ATTRIBUTES
Dim hMutex As Long
sec1.nLength = Len(sec1)
sec2.nLength = Len(sec2)
sinfo.cb = Len(sinfo)
sinfo.dwFlags = STARTF_USESHOWWINDOW
sinfo.wShowWindow = StartSize
pclass = Priority_Class
cmdline = Appli
If (Len(Trim$(Arg)) > 0) Then
cmdline = cmdline & " " & Arg
End If
Debug.Print " cmdLine : " & cmdline
If CreateProcess(vbNullString, cmdline, sec1, sec2, False, pclass, 0&, CurDir$(), sinfo, pinfo) Then
Debug.Print " CreateProcess OK"
Ret = 259
While (Ret = 259)
WaitForSingleObject pinfo.hProcess, Timeout
DoEvents
If (GetExitCodeProcess(pinfo.hProcess, Ret) = 1) Then
Debug.Print " GetExitCodeProcess OK"
LanceApp = Ret
Else
Debug.Print " GetExitCodeProcess KO"
End If
Wend
Else
Debug.Print " CreateProcess KO : " & Err.LastDllError
End If
End Function
Conclusion
Utilisation : LanceApp(App.path & "\monExe.exe", "arg1 arg2", INFINITE, SW_NORMAL, IDLE_PRIORITY_CLASS)
Bonne Prog
@++ Crazyht
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
LISTER KEYS.KEYLISTER KEYS.KEY par Onin42
Cliquez pour lire la suite par Onin42
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|