EXECUTER UNE commande msdos

bigboss200000 Messages postés 10 Date d'inscription jeudi 30 septembre 2004 Statut Membre Dernière intervention 21 juin 2005 - 17 juin 2005 à 10:58
bigboss200000 Messages postés 10 Date d'inscription jeudi 30 septembre 2004 Statut Membre Dernière intervention 21 juin 2005 - 20 juin 2005 à 15:33
bonjour.je souhaite executer une commande msdos.
j'arrive en effet a ouvrir par exemple notepad en faisant:

Set objShell = CreateObject("WScript.Shell")

strCommand = "cmd /c notepad"
Set objExecObject = objShell.Exec(strCommand)


mais lorsque je veux executer une commmande plus complexe contenant plusieurs parametres comme ci apres:

strCommand = "cmd /c netsh interface ip set "LAN" static 10.1.8.245 255.0.0.0 10.1.20.254 2"


cela ne fonctionne pas.
peut etre que je dois déspécialisé le parametre lan (qui est entre guillemet) ou alors je dois mettre un & entre chaque parametre??
avez vous un exemple de commande msdos executant une commande complexe (avec au moins deux parametres??)
merci beaucoup!!!

5 réponses

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
17 juin 2005 à 11:23
"découpé" serait peut être plus adapté

sinon tu peux doubler les guillemets:



strCommand = "cmd /c netsh interface ip set ""LAN"" static 10.1.8.245 255.0.0.0 10.1.20.254 2"

Daniel
0
crenaud76 Messages postés 4172 Date d'inscription mercredi 30 juillet 2003 Statut Membre Dernière intervention 9 juin 2006 28
17 juin 2005 à 12:34
ERt une remarque en passant. Notepad etant un exe, tu n'as pas besoin de mettre un "cmd /c" devant pour le lancer. strCommand = "Notepad.exe" suffira

 Christophe R
0
bigboss200000 Messages postés 10 Date d'inscription jeudi 30 septembre 2004 Statut Membre Dernière intervention 21 juin 2005
20 juin 2005 à 10:21
bonjour, cela ne fonctionne toujours pas
j'ai essayé avec une commande moins complexe et j'ai fait:
Shell("ping" & "" & "10.1.8.244")
ou encore
Set objShell = CreateObject("WScript.Shell")
strCommand = "cmd /c " & "ping" & "10.1.8.24"
Set objExecObject = objShell.Exec(strCommand)

cela ne marche pas!!!!
help me
donnez moi un exemple concret de l'execution d'une commande msdos svp.merci beaucoup!!!
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
20 juin 2005 à 11:51
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long



Private Sub Command1_Click()

Dim Host As String

Dim Fnom As String

Dim Buff As String



Host = "10.1.8.244"

Fnom = "C:\Test.txt"



Shell ("cmd /c ping -n 3 " & Host & " > " & Fnom)



' boucle d'attente pour le lancement

While FindWindow(vbNullString, "C:\WINDOWS\system32\cmd.exe") = 0

DoEvents

Wend

'boucle d'attente pour la fin

While FindWindow(vbNullString, "C:\WINDOWS\system32\cmd.exe") > 0

DoEvents

Wend



'récupération du résultat

Open Fnom For Binary As #1

Buff = Space$(LOF(1))

Get #1, , Buff

Close #1

MsgBox Buff

'éventuellement suppression du fichier

Kill Fnom



End Sub


Daniel
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
bigboss200000 Messages postés 10 Date d'inscription jeudi 30 septembre 2004 Statut Membre Dernière intervention 21 juin 2005
20 juin 2005 à 15:33
merci bien
0
Rejoignez-nous