Private Sub Command2_Click()
'commande dos, fenêtre cachée, synchrone
ShellAndWait "cmd /c dir c: /P", WshHide, True
'commande dos, fenêtre cachée, synchrone
ShellAndWaitNoRef "cmd /c dir c: /S ", 0, True
End Sub
Private Sub ShellAndWait(ByVal PathName As String, _
Optional ByVal WindowStyle As WshWindowStyle = WshMinimizedFocus, _
Optional ByVal WaitOnReturn As Boolean = False)
'nécessite une référence projet à la bibliothèque
'Windows Script Host Object Model (wshom.ocx)
Dim wshTemp As IWshRuntimeLibrary.IWshShell
'instancie l'objet WShell
Set wshTemp = New IWshShell_Class
'lance la commande
wshTemp.Run PathName, WindowStyle, WaitOnReturn
'affiche la boite de dialogue de fin
MsgBox "Fin"
'libère l'objet
Set wshTemp = Nothing
End Sub
Private Sub ShellAndWaitNoRef(ByVal PathName As String, _
Optional ByVal WindowStyle As Integer = 2, _
Optional ByVal WaitOnReturn As Boolean = False)
'ne nécessite pas de référence projet à la bibliothèque
'Windows Script Host Object Model (wshom.ocx)
Dim wshTemp As Variant
'instancie l'objet WShell
Set wshTemp = CreateObject("WScript.Shell")
'lance la commande
wshTemp.Run PathName, WindowStyle, WaitOnReturn
'affiche la boite de dialogue de fin
MsgBox "Fin"
'libère l'objet
Set wshTemp = Nothing
End Sub