Skip to Content

Hello community,

in a few posts we discuss the possibility to use multiple VBScript processes. With the Run command you can start different processes asynchronously. But after the start, you have not really a chance to synchronize the processes. Maybe via a file interface. For the process synchronization and communication offers Windows the IPC interface (Interprocess Communication).

There are different technics to synchronize and to communicate between processes, like

  • Events,
  • Semaphores,
  • FileMaps and
  • the ClipBoard
  • etc.

To use this possibilities I programmed a COM library which offers this technics. You find it here.

With COMIPC you can easily e.g. synchronize processes, look at the following example:

'-Begin-----------------------------------------------------------------

  '-Directives----------------------------------------------------------
    Option Explicit

  '-Constants-----------------------------------------------------------
    Const INFINITE = -1   

  '-Variables-----------------------------------------------------------
    Dim oIPC, hEvent, wsh, extVBS, rc

  '-Main----------------------------------------------------------------
    Set oIPC = CreateObject("COMIPC")
    If IsObject(oIPC) Then

      hEvent = oIPC.EventCreate("TestEvent", 0, 0)

      If hEvent Then

        extVBS = "Script 2.vbs"
        Set wsh = CreateObject("WScript.Shell")
        If IsObject(wsh) Then
          wsh.Run("wscript.exe " & extVBS)
          Set wsh = Nothing
        End If

        rc = oIPC.EventWait("TestEvent", INFINITE)
        rc = oIPC.EventClose(hEvent)

      End If 
      Set oIPC = Nothing
    End If

    MsgBox "End"     

'-End-------------------------------------------------------------------

 

We create an event, start a second script and wait until the event is set in the second script.

'-Begin-----------------------------------------------------------------

  '-Directives----------------------------------------------------------
    Option Explicit

  '-Variables-----------------------------------------------------------
    Dim oIPC, rc

  '-Main----------------------------------------------------------------
    Set oIPC = CreateObject("COMIPC")
    If IsObject(oIPC) Then

      MsgBox "Event"

      rc = oIPC.EventSet("TestEvent")
      Set oIPC = Nothing
    End If

'-End-------------------------------------------------------------------

 

If the event is set, in the second script, the first script will finish.

So it is e.g. possible to start different SAP GUI Scripts and to set different synchronization points. Also you can communicate between different processes via FileMap – File mapping is the association of a file’s contents with a portion of the virtual address space of a process.

Enjoy it.

Cheers
Stefan

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Evando Souza

    Hello Stefan,

    I try to use this COM library (COMIPC) .

    I copy this dll to c:\windows\system32 but when I run the script ther message:

    Activex can´t create object ‘COMIPC’

    This DLL run on Windows 64 ?

    (0) 
    1. Stefan Schnell Post author

      Hello Evando,

      thanks for your reply.

      Your OS is Windows x64, so the 32-bit (x86) libraries are in the directory SysWOW64. But it is not necessary to copy the library in this system directory. Register the library with a x86 console like this:

      1. Open a console with Windows\SysWOW64\cmd.exe.
      2. Type SET PROCESSOR_ARCHITECTURE and press enter.
      3. You must see PROCESSOR_ARCHITECTURE=x86 as answer.
      4. Change to the directory where COMIPC.dll is stored.
      5. Now type RUNDLL32 COMIPC.dll,RegisterServer %cd%

      Now you can use the library in x86 and x64 programs, but if you use VBA in a x64 Office application the code completion etc. don’t work, use the workaround from here – post from Aug. 20, 2015.

      Enjoy it and let us know your results.

      Cheers

      Stefan

      (0) 

Leave a Reply