1. Sub Wscript1()
' Execute program and
' Read the output into a variable line by line
Dim sKillExcel As String
sKillExcel = "TASKKILL /F /IM plink.exe"
Shell sKillExcel, vbHide
Exit Sub
Dim ObjExec
Dim strFromProc
Set objShell = WScript.CreateObject("WScript.Shell")
Set ObjExec = objShell.Exec("cmd.exe /c dir")
Do
strFromProc = ObjExec.StdOut.ReadLine()
WScript.Echo "Output is: " & strFromProc
Loop While Not ObjExec.StdOut.AtEndOfStream
End Sub
Sub Wscript2()
'Function vFn_Sys_Run_CommandOutput(Command, Wait, Show, OutToFile,
DeleteOutput, NoQuotes)
'Run Command similar to the command prompt, for Wait use 1 or 0. Output returned
and
'stored in a file.
'Command = The command line instruction you wish to run.
'Wait = 1/0; 1 will wait for the command to finish before continuing.
'Show = 1/0; 1 will show for the command window.
'OutToFile = The file you wish to have the output recorded to.
'DeleteOutput = 1/0; 1 deletes the output file. Output is still returned to
variable.
'NoQuotes = 1/0; 1 will skip wrapping the command with quotes, some commands
wont work
' if you wrap them in quotes.
'-------------------------------------------------------------------------------
---------
On Error Resume Next
'On Error Goto 0
Set f_objShell = CreateObject("Wscript.Shell")
Set f_objFso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
'VARIABLES
If OutToFile = "" Then OutToFile = "TEMP.TXT"
tCommand = Command
If Left(Command, 1) <> """" And NoQuotes <> 1 Then tCommand = """" &
Command & """"
tOutToFile = OutToFile
If Left(OutToFile, 1) <> """" Then tOutToFile = """" & OutToFile & """"
If Wait = 1 Then tWait = True
If Wait <> 1 Then tWait = False
If Show = 1 Then tShow = 1
If Show <> 1 Then tShow = 0
'RUN PROGRAM
f_objShell.Run tCommand & ">" & tOutToFile, tShow, tWait
'READ OUTPUT FOR RETURN
Set f_objFile = f_objFso.OpenTextFile(OutToFile, 1)
tMyOutput = f_objFile.ReadAll
f_objFile.Close
2. Set f_objFile = Nothing
'DELETE FILE AND FINISH FUNCTION
If DeleteOutput = 1 Then
Set f_objFile = f_objFso.GetFile(OutToFile)
f_objFile.Delete
Set f_objFile = Nothing
End If
vFn_Sys_Run_CommandOutput = tMyOutput
If Err.number <> 0 Then vFn_Sys_Run_CommandOutput = "<0>"
Err.Clear
On Error GoTo 0
Set f_objFile = Nothing
Set f_objShell = Nothing
End Function
End Sub
Sub Laughable()
WScript.Echo execStdOut("ping google.com")
End Sub
Function execStdOut(cmd)
Dim goWSH: Set goWSH = CreateObject("WScript.Shell")
Dim aRet: Set aRet = goWSH.Exec(cmd)
execStdOut = aRet.StdOut.ReadAll()
End Function
Sub MemE()
Const WshFinished = 1
Const WshFailed = 2
strCommand = "ping.exe 127.0.0.1"
Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec(strCommand)
Select Case WshShellExec.status
Case WshFinished
strOutput = WshShellExec.StdOut.ReadAll
Case WshFailed
strOutput = WshShellExec.StdErr.ReadAll
End Select
MsgBox strOutput
Exit Sub
WScript.StdOut.Write strOutput 'write results to the command line
WScript.Echo strOutput 'write results to default output
MsgBox strOutput
End Sub
Sub lolo()
Dim myCommand
Set myCommand = CreateObject("WScript.Shell")
myCommand.Run "%comspec% /c dir >
C:UsersJthomps182Documentsdts_history_2.log"
End Sub
Sub Cheap()
Set objShell = CreateObject("WScript.Shell")
strErrorCode = objShell.Run ipconfig,0,True
WScript.Echo strErrorCode
Set objShell = CreateObject("WScript.Shell")
Set ObjExec = objShell.Exec("explorer.exe")
3. Set objShell = CreateObject("WScript.Shell")
comspec = objShell.ExpandEnvironmentStrings("%comspec%")
' ////////////////////////////////////////////////////////
Set ObjExec = objShell.Exec(comspec & " /c ipconfig")
Do
WScript.StdOut.WriteLine (ObjExec.StdOut.ReadLine())
Loop While Not ObjExec.StdOut.AtEndOfStream
WScript.StdOut.WriteLine (ObjExec.StdOut.ReadAll)
End Sub
Sub Shell2()
Function runCMD(strRunCmd)
Set objShell = WScript.CreateObject("WScript.Shell")
Set ObjExec = objShell.Exec(strRunCmd)
strOut = ""
Do While Not ObjExec.StdOut.AtEndOfStream
strOut = strOut & ObjExec.StdOut.ReadLine()
Loop
Set objShell = Nothing
Set ObjExec = Nothing
runCMD = strOut
End Function
Sub sheshe()
WScript.Echo runCMD("ping -t http:www.google/com")
'Function runCMD(strRunCmd)
Set objShell = WScript.CreateObject("WScript.Shell")
Set ObjExec = objShell.Exec(strRunCmd)
strOut = ""
Do While Not ObjExec.StdOut.AtEndOfStream
strOut = strOut & ObjExec.StdOut.ReadLine()
Loop
Set objShell = Nothing
Set ObjExec = Nothing
strOut = "ping -t http:www.google/com"
runCMD = strOut
MsgBox strOut
End Function