Showing results 1 to 5 of 5

Thread: Read zenOn variables from Windows Service

  1. #1
    Join Date
    11.05.2017
    Posts
    3

    Default Read zenOn variables from Windows Service

    Good afternoon.
    I want to read variables value from zenOn Runtime project using zenOn API.
    I'm working with 7.60 SP 0 Build 36068 zenOn version.
    If I use a simple C# Console Application everything works correctly.
    I have an exception in the below function when I use a Windows Service:

    IApplication _zApplication = Marshal.GetActiveObject("zenOn.Application") as Application;

    Exception:
    System.Runtime.InteropServices.COMException (0x80004005). Message: Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

    Can someone help me?
    Thanks!

    Matteo
    Last edited by matteo.bernardon : 2nd November 2018 at 14:27

  2. #2
    Join Date
    15.11.2016
    Posts
    95

    Default Re: Read zenOn variables from Windows Service

    Hello,

    If you google that exception you will find some hints.
    Like this: https://stackoverflow.com/questions/12828175/exception-from-hresult-0x800401e3-mk-e-unavailable-workarounds

    My guesses:
    - Runtime is not running
    - Runtime is not accessable due to access rights
    - Runtime does not have the Objectmodel active
    - zenon API reference file is outdated

    Also: In my code I refer to "zenOn.Application" and not "IApplication".
    Not sure if that matters.

    Hope that helps.

    BR,
    Georg

  3. #3

    Default Re: Read zenOn variables from Windows Service

    Hi Matteo,

    When the zenon runtime is started as a service, it is also necessary for the console application to be started in the same session (session 0) within the same user context as the zenon runtime, in order to access the API. Windows, through something called session 0 isolation, prohibits applications in another (interactive) session to interact with applications or services in session 0.

    Also Windows restricts inter process communication through the API not only to the same session but also to the user and the user elevation level. When you start the runtime as a regular user and a console application in the same user context but with elevation (e.g. because visual studio was started with elevation and debugging was started from studio), the interaction will fail.

    Best regards,
    Mark

  4. #4
    Join Date
    11.05.2017
    Posts
    3

    Default Re: Read zenOn variables from Windows Service

    Quote Originally Posted by georgk View Post
    Hello,

    If you google that exception you will find some hints.
    Like this: https://stackoverflow.com/questions/12828175/exception-from-hresult-0x800401e3-mk-e-unavailable-workarounds

    My guesses:
    - Runtime is not running
    - Runtime is not accessable due to access rights
    - Runtime does not have the Objectmodel active
    - zenon API reference file is outdated

    Also: In my code I refer to "zenOn.Application" and not "IApplication".
    Not sure if that matters.

    Hope that helps.

    BR,
    Georg
    Hi Georg,

    thanks for the reply.
    I think that was an access rights problem.
    I forced the service to run from the same account that started the zenOn runtime but it doesn't work.
    I don't understand why.

    Best regards,

    Matteo

  5. #5
    Join Date
    11.05.2017
    Posts
    3

    Default Re: Read zenOn variables from Windows Service

    Quote Originally Posted by markclemens View Post
    Hi Matteo,

    When the zenon runtime is started as a service, it is also necessary for the console application to be started in the same session (session 0) within the same user context as the zenon runtime, in order to access the API. Windows, through something called session 0 isolation, prohibits applications in another (interactive) session to interact with applications or services in session 0.

    Also Windows restricts inter process communication through the API not only to the same session but also to the user and the user elevation level. When you start the runtime as a regular user and a console application in the same user context but with elevation (e.g. because visual studio was started with elevation and debugging was started from studio), the interaction will fail.

    Best regards,
    Mark
    Hi Mark,

    thanks for the reply.
    I understand what you say but I think that is a access rights problem.
    In my case the zenOn runtime doesn't start as a service. If I use a console application, it connects to zenOn and everything works correctly.
    When I change it in a Windows service, even if I force the service to run with the same user who ran the zenOn Runtime, I have the same Exception.
    I don't understand why.

    Best regards,

    Matteo



Similar Threads

  1. Replies: 0
    Last Post: 7th September 2018, 10:02
  2. Accessing variables in Runtime wizard and service
    By emrocon in forum Add-In Framework
    Replies: 3
    Last Post: 17th October 2017, 17:12
  3. zenOn 7.20 (SQL Service Starting)
    By salmanhassan2 in forum Editor and Runtime Setup
    Replies: 1
    Last Post: 16th September 2015, 09:12
  4. Zenon 7.11 as service
    By diemon in forum zenon Supervisor
    Replies: 5
    Last Post: 4th March 2015, 10:22
  5. Replies: 2
    Last Post: 4th July 2013, 11:45

Tags for this Thread

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •