oShellRun1

Runs a WScript.Shell command with wait until finish and returns 0, 1, 2 or -1 based on output of that cmd.
Used in specific situation, but can be customized, still little rough

Function oShellRun1(ShellCmd, LogFile, Optional CmdOk = "Installation completed successfully", Optional CmdNotOk = "Installation failed")
 ' Runs ShellCmd
 ' Needs to log results in LogFile
 ' Returns 0 if cmd did not run for some reason
 ' Returns 1 if CmdOk found in Logfile
 ' Returns 2 if CmdNotOk found in LogFile
 ' Returns -1 if error found (shell line not found)
 ' Waits for line to finish
 Set oShell = CreateObject("WScript.shell")
 oShellRun1 = 0
 If IsThere1(LogFile, True, True) Then Kill LogFile
 DoEvents
 oShell.Run ShellCmd, 1, True
 DoEvents
 If Not IsThere1(LogFile, True, True) Then Exit Function
 FullFile = ""
 Close
 Open LogFile For Input As #1
 Do Until EOF(1)
  Line Input #1, St1
  FullFile = FullFile & vbCrLf & St1
 Loop
 Close
 Kill LogFile
 Pass1 = InStr(1, FullFile, CmdOk, vbTextCompare) ' Done, yay
 Pass2 = InStr(1, FullFile, CmdNotOk, vbTextCompare) ' Not completed
 If Pass2 > 0 Then
  oShellRun1 = 2
 ElseIf Pass1 > 0 Then
  oShellRun1 = 1
 End If
End Function

ShellCmd, LogFile, Optional CmdOk, Optional CmdNotOk

Views 482 Downloads 146

'IsThere1', 'WSript', 'shell', 'run', 'cmd', 'dos', 'commands', 'wait', 'log', 'needs work'

ANmarAmdeen
324
Components VBA
Revisions

v1.0

Needs