Les Snippets

Connexion

Exécuter une commande DOS en console cachée

Niveau requis pour utiliser/comprendre cette source : 2 ( Initié )
Créé le 30/04/2007 13:45:38 et initié par rvblog [Liste]
Vue : 22742
Catégorie(s) : Fichier / Disque, Système, Divers
Langages dispo pour ce code :
- VB6, VBA
- VBScript
- Javascript



Langage : VB6 , VBA
Date ajout : 30/04/2007
Posté par rvblog [Liste]

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


Remarque :
Testé sous W2K, NT 4.0
Langage : VBScript
Date ajout : 30/04/2007
Posté par rvblog [Liste]

'Appel de la procédure
ExecAndWait

Sub ExecAndWait
Dim wshShell
 'l'objet WScript.Shell est aussi accessible, en VB6,
 ' via la référence IWshRunTimeLibrary.IWshShell (wshom.ocx)
 Set wshShell = CreateObject("WScript.Shell")
 'Run( bstrCommand As String
 ' , [pvarWindowsStyle]
 ' , [pvarWaitOnReturn]) As Long
 wshShell.Run "cmd /c dir c: /s", 0, True
 MsgBox "Fin"
 Set wshShell = Nothing
End Sub

'Documentation
'WshWindowStyle
' WshHide = 0
' WshNormalFocus = 1
' WshMinimizedFocus = 2
' WshMaximizedFocus = 3
' WshNormalNoFocus = 4
' WshMinimizedNoFocus = 6


Remarque :
Mettez le tout dans un fichier Test.vbs, et exécutez-le.
Testé sous W2k, NT 4.0
Langage : Javascript
Date ajout : 09/06/2007
Posté par yousfane [Liste]
function ExecAndWait(){
var wshShell = new ActiveXObject("WScript.Shell");
wshShell.Run ("java.exe fichier class", 0, true);
}
ExecAndWait()
Remarque :
Mettez le nom du fichier class à executer à la place de "fichier class"

Snippets en rapport avec : Lancer, Exécuter, Commande, Synchrone, Exécutable



Codes sources en rapport avec : Lancer, Exécuter, Commande, Synchrone, Exécutable

{JAVA / J2EE} COMMENT LANCER UNE COMMANDE SYSTEME A PARTIR D'UN SIMPLE CODE JAVA
prend une chaine de caractere et l'execute NB : le code ne marche pas directement il faut initialis...

{Delphi} EXÉCUTER UNE COMMANDE DOS SANS QUITTER SON APPLICATION SOUS WINDOWS
Copie un fichier en passant par la commande Copy du DOS, en utilisant un fichier batch. Utile évent...

{JAVA / J2EE} COMMENT LANCER UNE PAGE WEB DEPUIS UNE APPLICATION JAVA
Ben tout simplement, ca permet de lancer une page web locale ou distante depuis une application jav...

{Visual Basic, VB6, VB.NET, VB 2005} VBSCRIPT --> CONVERSION DE FICHIER TEXTE EN FICHIER EXCEL PAR LIGNE DE COMMANDE
Ce script, lancé en ligne de commande dos, permet de convertir un fichier texte en fichier excel. ...

{Visual Basic, VB6, VB.NET, VB 2005} SLYSPY(MINI-RAT)
Un client, caché s'inscrivant dans le registre au démarrage et consommant peu de mémoire permet d'ac...

{Visual Basic, VB6, VB.NET, VB 2005} PROGRAMME DE BASE VELLEMAN K8000 (VB 2005 EXPRESS EDITION)
La source fournie sur disquette avec ma carte K8000 ne fonctionnait pas. Voici un programme de ba...

{C# / C#.NET} GENESIS ("EXÉCUTER" EN C# ET AMÉLIORÉ)
Voici un de mes programmes les plus réussis, question stabilité, performance et apparence. Il consis...

{Assembleur} "MORTIMER": UN HOBBY OS
Mortimer 0.7 est un petit système d'exploitation, il tient sur une disquette c'est un système par...

{C / C++ / C++.NET} FAIRE GLISSER LA SOURIS
Bonjour. Cette Source pourrait faire partie d'une Blague : Une fois le Programme Lancé, votre So...

{PHP} EXÉCUTER UN SCRIPT AU-DELÀ DU TIMEOUT DE PHP
Ce script montre une méthode permettant d'exécuter un script au-delà du timeout de PHP. J'en suis...