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

Service install silently fails on Windows 11 #338

Open
longzheng opened this issue Feb 13, 2023 · 4 comments
Open

Service install silently fails on Windows 11 #338

longzheng opened this issue Feb 13, 2023 · 4 comments

Comments

@longzheng
Copy link

longzheng commented Feb 13, 2023

Issue:
When using svc.install(); the service fails to install in Windows 11 without any warning or error.

How To Reproduce:

  1. Start with a blank Windows 11 environment (e.g. use "Windows Sandbox")
  2. Install node
  3. Create project with npm install node-windows
  4. Run sample service install script
var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'Hello World',
  description: 'The nodejs.org example web server.',
  script: 'C:\\path\\to\\helloworld.js',
  nodeOptions: [
    '--harmony',
    '--max_old_space_size=4096'
  ]
  //, workingDirectory: '...'
  //, allowServiceLogon: true
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
  svc.start();
});

svc.install();

Expected Behavior:
Service is installed.

Or, error is emitted.

Actual Behavior:
Service is not installed.

Even adding an error event handler, there is no error emitted.

svc.on('install',function(){
  svc.start();
});

svc.on('error', (err) => {
  console.log(err)
})

svc.install();

Desktop:
Windows 11 22H2

image

Additional context:
I believe the issue is related to the very old version of winsw.exe bundled with the project. https://github.com/coreybutler/node-windows/tree/master/bin/winsw

If I try to run winsw.exe directly (but providing it a sample .xml to install a service), it fails. However if I use a newer version of winsw.exe from https://github.com/winsw/winsw/releases/tag/v2.12.0 then the service is installed correctly.

I believe this PR attempting to upgrade WinSW #268 might address this issue (EDIT: Nope, unfortunately that version of WinSW doesn't work either. I tested 2.12.0 directly and works https://github.com/winsw/winsw/releases/tag/v2.12.0.

@longzheng
Copy link
Author

After a bit more debugging, turns out #268 does work in Windows 11 however not in Windows 11's Windows Sandbox.

When installing the service in Windows Sandbox, I noticed this error in my wrapper.log file when trying to install the service.

2023-02-16 21:09:15,090 INFO  - Starting ServiceWrapper in the CLI mode
2023-02-16 21:09:16,028 FATAL - Unhandled exception
System.Management.ManagementException: Provider load failure 
   at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
   at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()
   at WMI.WmiRoot.ClassHandler.Invoke(Object proxy, MethodInfo method, Object[] args)
   at winsw.WrapperService.Run(String[] _args, ServiceDescriptor descriptor)
   at winsw.WrapperService.Main(String[] args)

I confirmed by updating winsw.exe to v2.12.0 fixes installations in Windows Sandbox (and in Windows 11).

@coreybutler
Copy link
Owner

It does look like upgrading winsw will fix this. The new winsw.exe is 17MB though (instead of 58kb), so the project increases its footprint for each service significantly. People using this on mobile Windows devices may be impacted by such a change. So, if this were included, it would have to be a major change (potentially breaking for some). I don't have any metrics to know how many people are using this in a sandbox, so it's hard to tell whether this change benefits the project or opens a can of worms... especially considering #317.

@longzheng
Copy link
Author

longzheng commented Feb 16, 2023

After a bit more testing, looks like we don't necessarily need WinSW-x64.exe which I believe is the one with .NET Core bundled. WinSW.NET461.exe seems to work in Windows 11 (and Windows 10) is 641KB, which is still larger but not as scary as 17MB.

I appreciate your plans for an entirely different solution but I think maybe bumping WinSW is a good interim solution otherwise this library's primary purpose silently fails.

@asdf23
Copy link

asdf23 commented Mar 11, 2024

This is silently failing for me in Windows 10. How can I upgrade this? Perhaps this is a new/different issue?

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

3 participants