List the status of the service and services in Win-7

I have a service monitoring application that tracks the status of three other server applications - you know these green, red status elements, start, stop, etc.

The problem is that it shows an incorrect state in Windows 7, even if the user is an administrator.

The Start, Stop buttons are disabled and the setup button is turned on, the status color is gray, which is also incorrect. The Start button should be enabled with the status of the service showing green - applications are running.

If the application is launched with the option "run as administrator", then it behaves normally.

The application is written in Delphi 7 and works fine in other versions of Windows. This line of code:

OpenSCManager(PChar(sMachine), Nil, SC_MANAGER_ALL_ACCESS);

always returns 0 under Win7, causing a problem.

Any ideas and, if possible, any workarounds other than "run as administrator".

+3
source share
1 answer

Service Manager can be opened without requiring administrator privileges if limited access is requested. This line of code:

ManagerHandle := OpenSCManager(nil, SERVICES_ACTIVE_DATABASE,
  SC_MANAGER_ENUMERATE_SERVICE);

opens the database of active services to the service dispatcher, even if used with a limited user account. The returned descriptor can then be used to call EnumServicesStatusEx()to get information about running services.

Passing SC_MANAGER_ALL_ACCESSas a parameter dwDesiredAccessmeans passing SC_MANAGER_CREATE_SERVICE, and, as stated in the documentation:

, CreateService.

, , , Windows 7. , .

BTW Windows 7,

Delphi 7 Windows.

, . Windows NT ( 20 ) , .

+7

Source: https://habr.com/ru/post/1739934/


All Articles