public static void SetServiceConfig <T>(ServiceController sc, SERVICE_CONFIG_INFO infoId, T objData) { GCHandle hdata = GCHandle.Alloc(objData, GCHandleType.Pinned); try { if (0 == ChangeServiceConfig2(sc.ServiceHandle, (int)infoId, hdata.AddrOfPinnedObject())) { throw new Win32Exception(); } } finally { hdata.Free(); } }
void SetServiceConfig <T>(SERVICE_CONFIG_INFO infoId, T objData) { GCHandle hdata = GCHandle.Alloc(objData, GCHandleType.Pinned); try { WithServiceHandle( ServiceAccessRights.GENERIC_READ | ServiceAccessRights.GENERIC_WRITE, delegate(IntPtr svcHandle) { if (0 == Win32.ChangeServiceConfig2(svcHandle, (int)infoId, hdata.AddrOfPinnedObject())) { throw new Win32Exception(); } } ); } finally { hdata.Free(); } }