mullvad / windows-service-rs

Windows services in Rust
Apache License 2.0
525 stars 85 forks source link

Errors when connecting to the service controller and service status reporting #102

Closed tuchaVshortah closed 1 year ago

tuchaVshortah commented 1 year ago

When running code using this crate I get these 2 errors: Error: Winapi(Os { code: 1063, kind: Uncategorized, message: "The service process could not connect to the service controller." })

Error: Winapi(Os { code: 1053, kind: TimedOut, message: "The service did not respond to the start or control request in a timely fashion." })

The first error usually happens when attempting to start a service using service_dispatcher

The second error also happens when compiling and running examples that are supplied with crate:

Screenshot from 2023-05-13 14-49-50

pronebird commented 1 year ago

Look at https://github.com/mullvad/windows-service-rs/issues/101. I think you're trying to install the service from user, but you can only do that with admin permissions. But also you cannot run the service via cargo run. Windows services have to be started by the system.

tuchaVshortah commented 1 year ago

Hello! Thanks for your help, but it didn't work. I keep getting the error 1053. Let me explain my code: firstly, main calls a module that functions like ping_module from the examples bundled with windows_service. Most of the module is the exact copy of the example that is provided with the crate, yet I still managed to break something. I have been trying to find what went wrong for a while, but I didn't manage to do so. Please, read a bit of my code if you can and try to find what is wrong with it. I would very much appreciate your review.

Code flow:

  1. https://github.com/tuchaVshortah/arp-spoofing-detector-rs/blob/dev/src/main.rs#L31
  2. https://github.com/tuchaVshortah/arp-spoofing-detector-rs/blob/dev/src/winservice/syslog_service.rs#L26
  3. https://github.com/tuchaVshortah/arp-spoofing-detector-rs/blob/dev/src/winservice/syslog_service.rs#L33
  4. https://github.com/tuchaVshortah/arp-spoofing-detector-rs/blob/dev/src/winservice/syslog_service.rs#L44

P.s. It seems like the error happens on the second step

tuchaVshortah commented 1 year ago

The bug is fixed now and my service did successfully start. The bug was caused by incorrect CLI option parsing.

romancitodev commented 1 year ago

And how you fixed it?

tuchaVshortah commented 1 year ago

And how you fixed it?

You just have to follow all the instructions. Don't try to invent anything like I did. If you are very curious you can check source code of my project: https://github.com/tuchaVshortah/arp-spoofing-detector-rs/tree/main/src/winservice