EnumServicesStatus - Usage?

Hi folks,

can anyone help with this code:

- i can get access to the services database, strat and stop services etc, but can't figure out how i am supposed to use this EnumServicesStatus function!!


LPCTSTR servername;
SERVICE_STATUS service_status;
LPCSTR servicename;

char outputbuffer[128];

servername = strdup("server");

sprintf(outputbuffer, "Unspecified Error");

SC_HANDLE server_handle = OpenSCManager(

      ENUM_SERVICE_STATUS *service_status = (ENUM_SERVICE_STATUS *)malloc(65535);
      DWORD bytesneeded;
      DWORD numberreturned;
      DWORD resumehandle;
      DWORD services_buffersize = 65535;

            sprintf(outputbuffer, "got %d services, need %d bytes, resumehandle = %d", numberreturned, bytesneeded, resumehandle);
            sprintf(outputbuffer, "Failed to list services");
            returncode = 60;
else sprintf(outputbuffer, "Faled to get server handle");

LVL 37
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Look into the sample code provided with the following articles.

NT Simple Service Manager

WindowsNT Simple Service Manager (2)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
meverestAuthor Commented:
thanks for the blindingly fast response.

as it turns out, i came back here to remove the question as i figured it out by myself (read the docs man! ;-)

the answer was that resumehandle MUST be set to zero for the first call, did that and it worked just like it's sposed to! :)

anyway, i accept your answer not so much for the content (which i didn't have to look at), but for the quick reply! ;-)

I have to say that your question is very vague. You didn't tell us what error you got or what you didn't understand. You just told us that you did not know how to use the function. So, I gave you complete samples. Ask a complete and clear question next time. By the way, this question should have been posted to the Windows programming topic area. It has nothing to do with C++ language.
meverestAuthor Commented:
and i thank you for that! :)

and thanks for the tip too - i will post in that group next time i have a similar question.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.