0
votes

I have a bunch of vbscripts that automate the SAP GUI interactions saved in a folder. I have a master vbscript that loops through the folder and finds all the vbscripts and executes it one by one.

My problem is however there is no control back from the SAP environment stating end of procedure . so what happens is that as one script is executing the next script starts to execute since the master vbs thinks the first vbs has completed executing.

Is there a way in which i could control when subsequent vbscripts will be launched ? like look into the process and check if a cscript is running and pause briefly ?

This is my master code.

Dim myFolder : myFolder = "c:\temp"

Set fso = CreateObject("Scripting.FileSystemObject")
Set sh = CreateObject("WScript.Shell")

For Each file In fso.GetFolder(myFolder).Files

        Dim extension : extension = UCase(Right(file.Name, 3))
        Select Case extension
        Case "VBS":
            sh.Run "wscript """ & file.Path & """", 1, True

        End Select

Next
1

1 Answers

0
votes

An excerpt from next script could help (given all info although checking Caption and CommandLine could suffice). Derived from Scriptomatic utility.

' NameSpace: \root\CIMV2 Class : Win32_Process
' D:\VB_scripts_help\Scriptomatic
' 
Option Explicit
On Error GoTo 0

Dim sRes, arrComputers, objWMIService, colItems, oItem, strComputer
sRes = Wscript.ScriptName
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array(".")
  sRes = sRes & vbNewLine & "NameSpace: \root\CIMV2 Class : Win32_Process"
For Each strComputer In arrComputers
  sRes = sRes & vbNewLine & "..."
  sRes = sRes & vbNewLine & "=========================================="
  sRes = sRes & vbNewLine & "Computer: " & strComputer
  sRes = sRes & vbNewLine & "=========================================="

  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
  Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_Process WHERE Caption like '%script.exe'" _
      , "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

  For Each oItem In colItems
    sRes = sRes & vbNewLine & "Caption: " & oItem.Caption
    sRes = sRes & vbNewLine & "CommandLine: " & oItem.CommandLine
    sRes = sRes & vbNewLine & "CreationClassName: " & oItem.CreationClassName
    sRes = sRes & vbNewLine & "CreationDate: " & WMIDateStringToDate(oItem.CreationDate)
    sRes = sRes & vbNewLine & "CSCreationClassName: " & oItem.CSCreationClassName
    sRes = sRes & vbNewLine & "CSName: " & oItem.CSName
    sRes = sRes & vbNewLine & "Description: " & oItem.Description
    sRes = sRes & vbNewLine & "ExecutablePath: " & oItem.ExecutablePath
    sRes = sRes & vbNewLine & "ExecutionState: " & oItem.ExecutionState
    sRes = sRes & vbNewLine & "Handle: " & oItem.Handle
    sRes = sRes & vbNewLine & "HandleCount: " & oItem.HandleCount
    sRes = sRes & vbNewLine & "InstallDate: " & WMIDateStringToDate(oItem.InstallDate)
    sRes = sRes & vbNewLine & "KernelModeTime: " & oItem.KernelModeTime
    sRes = sRes & vbNewLine & "MaximumWorkingSetSize: " & oItem.MaximumWorkingSetSize
    sRes = sRes & vbNewLine & "MinimumWorkingSetSize: " & oItem.MinimumWorkingSetSize
    sRes = sRes & vbNewLine & "Name: " & oItem.Name
    sRes = sRes & vbNewLine & "OSCreationClassName: " & oItem.OSCreationClassName
    sRes = sRes & vbNewLine & "OSName: " & oItem.OSName
    sRes = sRes & vbNewLine & "OtherOperationCount: " & oItem.OtherOperationCount
    sRes = sRes & vbNewLine & "OtherTransferCount: " & oItem.OtherTransferCount
    sRes = sRes & vbNewLine & "PageFaults: " & oItem.PageFaults
    sRes = sRes & vbNewLine & "PageFileUsage: " & oItem.PageFileUsage
    sRes = sRes & vbNewLine & "ParentProcessId: " & oItem.ParentProcessId
    sRes = sRes & vbNewLine & "PeakPageFileUsage: " & oItem.PeakPageFileUsage
    sRes = sRes & vbNewLine & "PeakVirtualSize: " & oItem.PeakVirtualSize
    sRes = sRes & vbNewLine & "PeakWorkingSetSize: " & oItem.PeakWorkingSetSize
    sRes = sRes & vbNewLine & "Priority: " & oItem.Priority
    sRes = sRes & vbNewLine & "PrivatePageCount: " & oItem.PrivatePageCount
    sRes = sRes & vbNewLine & "ProcessId: " & oItem.ProcessId
    sRes = sRes & vbNewLine & "QuotaNonPagedPoolUsage: " & oItem.QuotaNonPagedPoolUsage
    sRes = sRes & vbNewLine & "QuotaPagedPoolUsage: " & oItem.QuotaPagedPoolUsage
    sRes = sRes & vbNewLine & "QuotaPeakNonPagedPoolUsage: " & oItem.QuotaPeakNonPagedPoolUsage
    sRes = sRes & vbNewLine & "QuotaPeakPagedPoolUsage: " & oItem.QuotaPeakPagedPoolUsage
    sRes = sRes & vbNewLine & "ReadOperationCount: " & oItem.ReadOperationCount
    sRes = sRes & vbNewLine & "ReadTransferCount: " & oItem.ReadTransferCount
    sRes = sRes & vbNewLine & "SessionId: " & oItem.SessionId
    sRes = sRes & vbNewLine & "Status: " & oItem.Status
    sRes = sRes & vbNewLine & "TerminationDate: " & WMIDateStringToDate(oItem.TerminationDate)
    sRes = sRes & vbNewLine & "ThreadCount: " & oItem.ThreadCount
    sRes = sRes & vbNewLine & "UserModeTime: " & oItem.UserModeTime
    sRes = sRes & vbNewLine & "VirtualSize: " & oItem.VirtualSize
    sRes = sRes & vbNewLine & "WindowsVersion: " & oItem.WindowsVersion
    sRes = sRes & vbNewLine & "WorkingSetSize: " & oItem.WorkingSetSize
    sRes = sRes & vbNewLine & "WriteOperationCount: " & oItem.WriteOperationCount
    sRes = sRes & vbNewLine & "WriteTransferCount: " & oItem.WriteTransferCount
    sRes = sRes & vbNewLine & "."
  Next
Next

WScript.Echo sRes

Function WMIDateStringToDate(dtmDate)
WMIDateStringToDate = ( _
  Left(dtmDate,4) & "/" & Mid(dtmDate,5,2) & "/" & Mid(dtmDate,7,2) & " " & _
  Mid (dtmDate,9,2) & ":" & Mid(dtmDate,11,2) & ":" & Mid(dtmDate,13,2))
End Function