Multiple instances and/or service

Got a good idea? You can suggest new features here.
Post Reply
PaulBags
Posts: 14
Joined: Fri Oct 21, 2016 2:49 am

Multiple instances and/or service

Post by PaulBags » Fri Dec 09, 2016 11:14 pm

I have some macros I want running even on start up with no user logged in - which means running as a service. NSSM can do this and if that's all I needed to do I'd be ok. But I also have other macros that can't be run as a service because due windows limitations there's no (or no practical) way to get GUI applications opened in a user session, and I don't think hotkeys worked either.

Now at this point I was going to have two config scripts, set up a .bat to kill the service on user login and then run eventghost with the full script. This worked. However what I also need is for eventghost to start the service again on exit, but because I'm using the webserver and because they need the same port this hand off doesn't work.

So I thought I'd run the service and the user space GUI concurrently, with each handling a different set of macros on different ports. But they don't seems to want to run together.

User avatar
kgschlosser
Site Admin
Posts: 3013
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Multiple instances and/or service

Post by kgschlosser » Sat Dec 10, 2016 12:40 am

you cannot run eventghost as a service. by definition from microsoft a service is unable to interact with a user. and what that means is that a service does not have the ability to interact with the UI. because the UI actually does not start until after the user logs in and a service starts before that. eventghost has a hidden window that is uses to receive messages from windows and the windows gui. it would not function without this. and in order to make a window the GUI has to be active. so running as a service is a no go.

there is a way to do it but would require UAC to be turned off and you would always have to log into the console. because how windows works is that technically everything is a remote desktop even if you are logged in locally to the machine. over complicated to have it run as a service.


and EG can do multiple sessions. go into the tutorials and look at the topic about command line switches.
If you like the work I have been doing then feel free to Image

PaulBags
Posts: 14
Joined: Fri Oct 21, 2016 2:49 am

Re: Multiple instances and/or service

Post by PaulBags » Sat Dec 10, 2016 2:22 am

kgschlosser wrote:you cannot run eventghost as a service. by definition from microsoft a service is unable to interact with a user. and what that means is that a service does not have the ability to interact with the UI. because the UI actually does not start until after the user logs in and a service starts before that. eventghost has a hidden window that is uses to receive messages from windows and the windows gui. it would not function without this. and in order to make a window the GUI has to be active. so running as a service is a no go.
Works fine for webserver functions, returning variables in HTML or otherwise: like getting uptime, or the status of a service, or starting a service, or shutting down.
kgschlosser wrote:there is a way to do it but would require UAC to be turned off and you would always have to log into the console. because how windows works is that technically everything is a remote desktop even if you are logged in locally to the machine. over complicated to have it run as a service.
? I can stop the service, configure the xml in user space, and restart the service. PITA, but not overly complicated (from a users standpoint anyway).
kgschlosser wrote:and EG can do multiple sessions. go into the tutorials and look at the topic about command line switches.
... http://www.eventghost.net/docs/commandline.html doesn't explain it and nor does viewtopic.php?f=13&t=8218. Multiple instances refuse to load, with -file overriding already running instances. It's possible to get multiple instances running as another user (shift+right click > run as different user, say on a .bat with xml set with -file) but it doesn't actually work.

The closest I got was turning a service on and off, but eventghost appears to execute Main.Onclose before relinquishing it's HTTP port... and I just realised I didn't try explicitly disabling the webserver before bringing the service back up. Derp.

PaulBags
Posts: 14
Joined: Fri Oct 21, 2016 2:49 am

Re: Multiple instances and/or service

Post by PaulBags » Sat Dec 10, 2016 4:44 am

Ok I got it working, it's not pretty though, and it's not multi instance. Only tested while logged in, need to check restarts and log offs.

* User xml loads with an elevated startup folder shortcut to a bat file which stops the service and then loads event ghost with the user xml. Has a Main.OnClose which disables the webserver and runs a command to start the service (elevation necessary), and an autostart that includes enabling the webserver as well as killing the cmd window that calls it (not sure why it's not exiting, I suspect the "are you sure you want to load xml?" dialog is loading invisibly)#.
* Service xml has pared down macros, the ones that'll actually work from a service. Has automatic start set in windows services, and is also started by the user xml when it exits. Disables webserver on close, and enables on autostart.

Suffice to say I already had UAC off.

# Both instances somehow create another instance about using about 5,000KB memory, which shows in task manager on the 'command line' column with 8.3 filename & the arguments '/Automate -Embedding'. I have heaps of memory but it's dirty, annoying, confusing, and worrying.


EDIT nah doesn't work on log off/log on.

User avatar
kgschlosser
Site Admin
Posts: 3013
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Multiple instances and/or service

Post by kgschlosser » Sat Dec 10, 2016 1:10 pm

this is all due to it spawning that invisible frame to capture windows messages. it is not something you can turn off. and i am not sure what wx.App requires to run. but that is also something that is always run as well and it required to show the GUI but it is also what keeps the eventghost process in "loop" so to speak. otherwise it would just exit.

now because the GUI is not loaded I do not think the wx.App will function properly.

the whole eventghost program revolves around seeing messages from windows and it uses wx to achieve a lot of it.


this is from the App.py
and you can see that is starts that instance of wxApp as well as wxFrame

Code: Select all

class App(wx.App):
    def __init__(self):
        self.onExitFuncs = []
        wx.App.__init__(self, 0)
        self.locale = wx.Locale(wx.Locale.GetSystemLanguage())
        self.shouldVeto = False
        self.firstQuery = True
        self.endSession = False
        self.frame = wx.Frame(None)
        self.hwnd = self.frame.GetHandle()
and i also know the eg.MessageReceiver uses another hidden window for grabbing all of the clipboard information.
If you like the work I have been doing then feel free to Image

Post Reply