Closed zhangshaoju1987 closed 3 years ago
Services run in session 0 and can't interact with user sessions.
You'd need to platform invoke (p/invoke) native function CreateProcessAsUser to create a new process in the user's session, then send commands to it via some method of inter-process communication (e.g. sockets).
I have same problem here. @lucent-sea I'll try to do this and then I come back again here to update comments. Thanks
Services run in session 0 and can't interact with user sessions.
You'd need to platform invoke (p/invoke) native function CreateProcessAsUser to create a new process in the user's session, then send commands to it via some method of inter-process communication (e.g. sockets).
Thank you very much. Yes, I have solved it by using the createProcessAsUser
@big-brain could you please give more details? Do you use CreateProccessAsUser with node?
I use node-window to register js as service on windows10. just like below:
var svc = new Service({ name:'joem service', description: 'background window service on windows10', script: path.join(__dirname,"service.js") });
and the service.js like this `const robotjs = require("robotjs");
setInterval(async ()=>{ console.log("run robotjs as window service in background"); console.log("robotjs=",robotjs.getMousePos()); // always return {x:0,y:0} robotjs.mouseClick(); // does not work await sleep(1000); robotjs.typeString("qm123456"); // does not work },3*1000);`
robotjs work fine in normal application, but when i use it in a background service, it does not work
Expected Behavior
behavior as it in normal application
Current Behavior
noting behavir
Possible Solution
I don't know ,please help me
Steps to Reproduce (for bugs)
npm install node-windows like upper
Context
Your Environment