【问题标题】:execute sequential vbscripts for SAP gui automation为 SAP gui 自动化执行顺序 vbscript
【发布时间】:2015-07-15 15:13:17
【问题描述】:

我有一堆 vbscripts 可以自动执行保存在文件夹中的 SAP GUI 交互。我有一个主vbscript,它遍历文件夹并找到所有vbscripts并一一执行。

但是,我的问题是 SAP 环境无法控制程序结束。所以发生的情况是,当一个脚本正在执行时,下一个脚本开始执行,因为主 vbs 认为第一个 vbs 已完成执行。

有没有一种方法可以控制后续 vbscript 何时启动?喜欢查看进程并检查 cscript 是否正在运行并短暂暂停?

这是我的主代码。

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

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    下一个脚本的摘录可能会有所帮助(考虑到所有信息,尽管检查 CaptionCommandLine 就足够了)。派生自 Scriptomatic 实用程序。

    ' 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-08
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      相关资源
      最近更新 更多