Windows service to change window focus - windows-services

I am trying to use a Windows Service to change between the window focus between 2 different applications (one I am currently developing, and google chrome).
Is it possible? If yes, how?

Related

Best way to find desktop idle time of a user in electron based desktop app

I want to know what are the best options when I want to find out desktop idle time through a desktop app made using electronjs.
As you want to find the idle time outside your Electron Application:
This is not possible. Listening to mouse movements, clicks that are happening somewhere on your screen while your electron application is not focused or minimized is outside the scope of electron. At least when you work in electron directly.
Of course you could write a small C++ program that monitors those event direct in the operating system and reports to electron. But that would be quite a task.

Is there a way to spawn electron Browser Windows that are just chromium browsers?

I am currently creating a multi-browser emulation software. This software serves as a way to emulate multiple users through a single machine.
I want to be able to use electron’s browser window functionality to spawn chromium web browser instances. Is there support for this? I am aware that I could simply spawn sub processes, but native support would be much more convenient. Thanks!

renderer and main process communication in electron - the right way

I'm a newbie to both Web tech and Electron! I'm trying to build a desktop app with many windows and fields - including lookup/searches and retrieving data from a DB.
I believe I have most of what I need to get the job done except how to handle the communication between windows. I.e. I need a dialog that displays a table of customers where the user selects a customer to return the data to the calling window. So I pass the search string to the lookup dialog which displays the customer list and in the dialog the user picks the customer and returns the primary key to the calling window (which will display the customer information).
I have found several ways to do this on the web. But I can't imagine that I need to keep a list of all the windows (about 90) and include a listener for each in the main.js (main process) to allow communication between the windows. There must be a better way!! Is there a simple way to setup a universal routine to process communication????
If you're opening 90 windows you're going about this the wrong way. With Electron, every window runs in its own process. This means your app is going to have nearly 100 processes running which is going to be very slow on most machines.
Electron is a platform that brings web apps to the desktop. In a web app, if you want to show 90 windows you'd show them as HTML layers in a single browser window.
I have discovered several ways to open windows and add my html, css, and javascript to each of the windows. I also have discovered a way to create a global var in the main process and have the other windows to retrieve the information from the global var. So I guess I have avoided my concern of having to keep a list of the windows. Still I'm struggling with Electron - almost nothing is straight forward. Or maybe I should say - very little matches my experience with desktop programming languages.
Johnf

can't disable some services in msconfig of windows server 2003

I found services tab in msconfig. i have tried to disable the services (eg. rpc) in msconfig. but cannot disable the services. it says it is an essential. i also found one field in the same services tab as "essential". where this essential information is stored in registry?
If a service is essential you should not disable it as it can lead to boot fail and some features of windows not working which could slow your computer down. Only do this if you are sure you know what your are doing. Follow this tutorial http://www.wikihow.com/Access-the-System-Configuration-Utility.

Why do forms fail in Windows Services

I understand that Window's Services have no desktop, and can't access any of the user's desktops directly (indeed, they can run when there is no desktop loaded). Why is it though that launching a form in a Window's Service causes an error?
A service should run without any user interaction, so there is no need for a form. If a service has to wait around for user feedback then it probably isn't going to be doing what it is supposed to.
You have to understand three related concepts: sessions, windows stations and desktops. But because there's a one-to-one relationships between sessions and stations, we can broadly ignore stations for this discussion. A session contains a station (winSta0 being the only interactive station) and stations contain one or more desktops.
Now session architecture differs according to Windows version. For NT <= 5 (XP/2003 and everything before them) services execute in session 0 along with the interactive user's apps. This is why you can configure services to interact with the desktop in these Windows NT versions - they are in the same session. For NT >= 6 (Vista, Server 2008 going forwards), services exists in session 0 but the interactive desktop is in another session. This is what's known as "service hardening", and is basically a security fix.
So since session 0 apps cannot get at the interactive console, it makes no sense for them to attempt to display a user interface of any kind.
Just to make this more confusing, Vista has a temporary kludge to cater for this situation: if an app in session 0 tries to create a dialog, Windows will trap this and present a warning to the user so they switch to a (I presume temporary) desktop where they can interact with the dialog. However this measure is explicitly temporary and you cannot rely upon it being in future Windows releases. I've seen this working in native code, but I suspect you are in managed code and the runtime is being smart enough to catch your behaviour and deliver a metaphorical slap to the hindquarters :-).
Ummm... what and whose desktop is that form going to appear on, exactly? A 'desktop' is an operating system concept: each window handle is owned by a specific desktop within a window station belonging to a single (interactive) user. The process within which the service is executing isn't going to find the user's visible desktop in its window station. For a rather dry reference, look at MSDN.
Actually, it's even nastier. You might be able to configure permissions for the service to be able to create a desktop -- but then nobody will see it! Alternatively, you could grant the process the rights to switch desktops, and confuse the heck out of the user!
There's a setting you must enable in order to allow your Windows Service to access certain folders directly (like desktop) or show forms (including MessageBox pop-ups): "Allow service to interact with desktop"
To see this, right click on My Computer => Manage => Services and Applications => Services. Double-click on a service to access its properties. On the "Log On" tab there is a checkbox for this setting.
Here is an article for how to set it programmatically in C#
[Edit] As Stephen Martin points out in the comments: this is only valid advice for pre-Vista versions of Windows.
Because if nobody is going to see the Form, nobody is going to dismiss it - running a modal dialog is a recipe for a hang - so you want it to complain loudly when this happens rather than sit there quietly until you kill the process (or look at a stack trace to determine what'd going on). (The other obvious problem is, who is going to pick the DialogResult if there is more than one possibility?) You want to know when this is happening. (Assert dialogs that dont throw if they cant show anything are a fun way of making people mad.).
In other words, because you want to know when things are confused enough in your code that a dialog is being shown within a service context.
(I'm assuming you're using Windows Forms on .NET, eve though you didnt tag it as such)
(If you have correctly configured things such that the service is allowed to interact with the desktop, you won't get an Exception)
When a Windows Service is started it is assigned to a Window Station and Desktop according to well documented, though somewhat obscure rules. As mentioned elsewhere it is not assigned to the interactive desktop (unless it is set to interact with the desktop on a pre-Vista OS) but it definitely runs in a desktop.
It is a common misconception that services cannot use UI elements. In fact many services (such as SQL Server) have in the past used hidden windows and windows messages for thread synchronization and work distribution purposes. There is no reason that a Form cannot be shown in a service. If you are getting an error it is due to something you are doing with the form or some component that is on the form. The most likely issues have to do with whether or not you need an STA thread for your form or are you creating a message pump for your form or something similar.
While you certainly can use a form in a Windows Service you almost certainly shouldn't. There will be threading issues, cross apartment call issues, possible blocking UI issues, etc. There are a very few situations where using a window in a service is a good choice but there is a better way, with no UI, in 99.99% of all cases.
Because at the time when the operating system needs to paint the window there is nothing to draw the form on.

Resources