Forums

Find answers, ask questions, and connect with our
community all around the world.

Home Forum Omnis General Forum Windows PID of running Omnis Instance

  • Windows PID of running Omnis Instance

    Posted by Stefan Diefenbacher on February 2, 2024 at 2:39 pm

    Hi,

    does someone know a smart way to gather the PID of the current Omnis instance?

    I’ve got no luck at all with the DLL method found in the mailing list.

    Regards,

    Stefan

    Alex Clay replied 2 weeks, 4 days ago 2 Members · 2 Replies
  • 2 Replies
  • Stefan Diefenbacher

    Member
    February 2, 2024 at 3:10 pm

    found a solution:

    Register DLL (“KERNEL32.DLL”,”GetCurrentProcessId”,”JV”) Returns error

    Call DLL (“KERNEL32.DLL”,”GetCurrentProcessId”) Returns pid

    Register DLL (“KERNEL32.DLL”,”GetCurrentProcessId”,”JV”,kTrue)

    • Alex Clay

      Member
      February 2, 2024 at 7:59 pm

      We do the same. Here’s our full solution that’s cross-platform for macOS and Windows. This stores the PID in a class variable since it’s static per application instance. There are a couple references to our framework (logging utility and task variable to detect platform), but this should be readable and hopefully help someone.

      If cnMyProcessID<>0

      Quit method cnMyProcessID

      End If

      If tvMacVersion

      Do $root.$runapplescript('do shell script "ps -p $$ -o ppid="',lcScriptResult) Returns lnReturn

      If lnReturn<>0

      Do uoLog.$error(con("Error ",lnReturn," trying to find my process ID. Result is: ",lcPathToMe))

      Quit method 0

      End If

      Calculate cnMyProcessID as trim(lcScriptResult,kTrue,kTrue,'"')

      Else

      Register DLL ("KERNEL32.DLL","GetCurrentProcessId","JV") Returns lnErrorCode

      Call DLL ("KERNEL32.DLL","GetCurrentProcessId") Returns cnMyProcessID

      End If

      Quit method cnMyProcessID

Log in to reply.