0

I want to p/invoke the windows api function ChangeServiceConfig2 for setting the description and/or "start delayed" flag for a service (and possibly more). Special thing about this is that it takes a pointer to different structures depending on what you want to change.

For example, to change the description text of a service, you'll need to point it to a SERVICE_DESCRIPTION structure and to change the delayed flag you'll point to a SERVICE_DELAYED_AUTO_START_INFO structure.

I have solved this by creating several overloads of the api function like this:

   private static extern bool ChangeServiceConfig2(IntPtr hService, int dwInfoLevel, [MarshalAs(UnmanagedType.Struct)] ref SERVICE_DESCRIPTION lpInfo);
   private static extern bool ChangeServiceConfig2(IntPtr hService, int dwInfoLevel, [MarshalAs(UnmanagedType.Struct)] ref SERVICE_DELAYED_AUTO_START_INFO lpInfo);

I want to ask if there's a better solution that wouldn't require another dozen or so overloads if I want to completely prototype it?

wexman
  • 1,217
  • 10
  • 19
  • Duplicate [of this](http://stackoverflow.com/questions/23270920/set-existing-service-to-auto-delayed-start)? – Christian.K Jun 06 '16 at 11:09
  • No, not really... The question is about prototyping the P/Invoke, not how to set a service to delayed start... – wexman Jun 07 '16 at 11:21
  • I understand. I figured that in that Q&A that prototyping issue had been solved: Have you checked [pinvoke.net](http://pinvoke.net/default.aspx/advapi32/ChangeServiceConfig2.html)? – Christian.K Jun 07 '16 at 11:23

1 Answers1

0

Just took a look inside the code of the ServiceInstaller class and found out that they're doing it the same way, so it cannot be all wrong...

Still open for suggestions, though.

wexman
  • 1,217
  • 10
  • 19