2013-01-24 3 views

Répondre

1

Il est difficile de répondre à la question avec des détails si moins, mais quand même ... permet d'essayer

Exemple Le code ci-dessous va illustrer 2 façons de stocker la sortie de la ligne de commande dans une variable de votre vbs. WScript.Echo est utilisé comme preuve (afficher le résultat).

'** VAR#1 (using Exec & StdOut) ---------- 
Dim ObjExec 
Dim strFromProc 

Set objShell = CreateObject("WScript.Shell") 
Set ObjExec = objShell.Exec("%comspec% /c " _ 
    & "netstat -a | find /c " & Chr(34) & "TCP" & Chr(34)) 

Do Until ObjExec.Stdout.atEndOfStream 
    strFromProc = strFromProc & ObjExec.StdOut.ReadLine & vbNewLine 
Loop 

WScript.Echo strFromProc ' display result from variable strFromProc 

Set objShell = Nothing 
Set ObjExec = Nothing 

'** VAR#2 (using Run) -------------------- 
Const cLogFile = "result.txt" 

Set objShell = CreateObject("WScript.Shell") 
objShell.Run "%comspec% /c netstat -a | find /c " _ 
    & Chr(34) & "TCP" & Chr(34) & ">" & cLogFile, 0, True 

Dim oFile, Result 
With CreateObject("Scripting.FileSystemObject") 
    If .FileExists(cLogFile) Then 
     Set oFile = .OpenTextFile(cLogFile) 
     Result = oFile.ReadLine 
     oFile.Close 
     Set oFile = .GetFile(cLogFile) 
     oFile.Delete 
    End If 
End With 

WScript.Echo Result ' display result from variable Result 

Set oFile = Nothing 
Set objShell = Nothing 
Questions connexes