Cannot stop Windows Service (built in C++ using MSDN sample)

Vadymyr 1 Reputation point

I used to create a simple service using C++ and Visual Studio 2017.
I can install, start, change the description. But I cannot stop it. I tried one of the solutions found on the internet:
change DWORD ServicesPipeTimeout to 180000
but that doesn't help.
When I try to stop it using Control Panel\Services, I get:
"Windows could not stop the <servicename> service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion."
I can provide the full solution, it's x86.
I tried 2 different virtual machines (Windows 7 32-bit Ultimate and 32-bit Starter) and got the same result.
Please help to solve this issue.

A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,724 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,412 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,519 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RLWA32 40,021 Reputation points

    Using HKEY_CURRENT_USER in a service is a mistake. Refer to predefined-keys.

    If I replace the call to ReadStringFromRegistry with a call to OutputDebugString then the service will stop properly. So it seems to me that ReadStringFromRegistry with HKEY_CURRENT_USER is probably the cause of the problem.

    1 person found this answer helpful.