Basically, you need to open service manages, with the manager, open a service, and then change it configuration. Three steps:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684323%28v=vs.85%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684330%28v=vs.85%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681987%28v=vs.85%29.aspx[
^].
By first step, you get the handle of the Service Manager,
SC_HANDLE
, using
OpenSCManager
, then, by second step, use it as a first parameter for the call to
OpenService
and then, finally, use the resulting handle to the service, to call
ChangeServiceConfig
.
You will need P/Invoke. If you need to learn P/Invoke, start from here:
http://en.wikipedia.org/wiki/P/Invoke[
^],
http://msdn.microsoft.com/en-us/library/Aa712982[
^].
This CodeProject can also be useful:
Essential P/Invoke[
^].
One alternative to P/Invoke is to use C++/CLI mixed-mode (managed+unmanaged) project. This project could build a DLL required by the global hooks, but it can contain some managed wrapper CLI code, so, from the standpoint of your .NET application, you can use it as a regular .NET assembly, that is, reference it. Please see:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[
^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[
^],
http://msdn.microsoft.com/en-us/library/xey702bw.aspx[
^],
http://msdn.microsoft.com/en-us/library/3bstk3k5[
^].
This way, you can write the code in C++, wrap it in C++/CLI managed class and reference the resulting module as a .NET assembly.
—SA