Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PSService] Question on PSService implementation #19

Open
Aorimn opened this issue Apr 3, 2018 · 1 comment
Open

[PSService] Question on PSService implementation #19

Aorimn opened this issue Apr 3, 2018 · 1 comment

Comments

@Aorimn
Copy link

Aorimn commented Apr 3, 2018

In the current implementation of PSService.ps1, the exe stub serves as the real service. When the service is started, this stub starts the PS script with the SCMStart parameter.
The PS script, when run with the SCMStart parameter, will start a new PowerShell session for the same script but with the Service parameter (let's call this one the PowerShell service-script), then return.
I've looked at your article but didn't find an explanation on why this part is implemented this way.

Starting the service in this manner makes it difficult for the exe stub to track if the PowerShell service-script is still running. So here's the idea: why not removing the SCMStart/SCMStop parameters altogether, and directly call the PowerShell service-script from the exe stub?

This would make possible the implementation of an option to restart the PS script if it fails - which would turn the exe stub into a monitoring service.
I'd also like to know what you think about this idea of a service restarting the PS script.

@Aorimn Aorimn changed the title [PSService] Question on [PSService] Question on PSService implementation Apr 3, 2018
@JFLarvoire
Copy link
Owner

Sorry for the long delay...

The PS script, when run with the SCMStart parameter, will start a new PowerShell session for the same script

When you invoke the PSService.ps1 script yourself, it runs with your own identity, in your session.
The service runs as a different user, in a different context from yours. This is why the exe stub starts a second instance of the script.

why not removing the SCMStart/SCMStop parameters altogether, and directly call the PowerShell service-script from the exe stub?

This is exactly how this works now.

I'd also like to know what you think about this idea of a service restarting the PS script.

If we can make something simple, why not?
Note that theoretically the Service Control Manager already does that automatically. I've not made any test to verify if this works or not though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants