procedure TForm1.Button1Click(Sender: TObject);
var
Num_of_Services: longint;
begin
servicemanager.Access := $0001;
ServiceManager.Connect;
//Num_of_Services:= servicemanager.InstanceSize; //nope that didn't return the correct number of services
//Num_of_Services:=servicemanager.ComponentCount; //This always returned 0?
for count :=0 to Num_of_Services -1 do
begin
memo1.text:= memo1.text + try to do something to do with servicemanager.GetEnumerator or
maybe servicemanager.Services; not really sure?
end;
ServiceManager.free;
end;
I can often drop to the API's themselves and overcome Microsoft's strange datatypes, at least sometimes, as hwind etc are just integers. I do really hate when a Microsoft API return a pointer to the data I need, which happens in this case, but I think that's taken care of an repackaged by tservicemanager.
But if anyone can tell me how to get good at figuring out what makes up the ever going PAscal datatypes I keep seeing, such as TComponentEnumaerator's and TserviceEnteries etc, then let me know.
function ServiceStateName (statusCode: Integer): String; begin case statusCode of SERVICE_STOPPED: Result := 'Stopped'; SERVICE_RUNNING: Result := 'Running'; SERVICE_PAUSED : Result := 'Paused'; end; end;
servicemanager1.Access := SC_MANAGER_ALL_ACCESS;
There are several more statuses available, why are you not converting all of them? At the very least, I would suggest returning statusCode as-is if a match is not found, eg:
Just to nitpick, but SC_MANAGER_ALL_ACCESS is asking for too many permissions that you don't really need just to get the statuses. All you need in this case is SC_MANAGER_ENUMERATE_SERVICE. Don't ask for more permissions than you actually need.
servicemanager1.Access := SC_MANAGER_ENUMERATE_SERVICE;
Principle of least privilege (https://en.wikipedia.org/wiki/Principle_of_least_privilege)
Enhance security with the principle of least privilege (https://docs.microsoft.com/en-us/azure/active-directory/develop/secure-least-privileged-access)
The principle of least privilege (POLP) requires giving each user, service and application only the permissions needed to perform their work and no more.
No need to post two links, let alone such garbage sources -- W*kipedia and M$'s site. Then again, given the state of certain search engines, and the Internet in general, what can one do?
To experienced Freepascal people:Please don't be. IMO, that's the purpose of having this forum. No one was born knowing everything.
Sorry to ask such silly questions.
Please don't be. IMO, that's the purpose of having this forum. No one was born knowing everything.Indeed, absolutely.
question