public static void RunComServer(IEnumerable <Type> comObjectTypes) { if (comObjectTypes == null) { throw new ArgumentNullException(nameof(comObjectTypes)); } RegistrationServices services = new RegistrationServices(); List <int> registrationCookies = new List <int>(); try { foreach (var type in comObjectTypes) { if (!type.IsSubclassOf(typeof(OutOfProcessComObject))) { throw new ArgumentException($"Out-of-process COM type {type.FullName} must subclass {nameof(OutOfProcessComObject)}."); } int cookie = services.RegisterTypeForComClients(type, RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); registrationCookies.Add(cookie); } ServerRunning = true; Application.Run(); } finally { ServerRunning = false; foreach (var cookie in registrationCookies) { services.UnregisterTypeForComClients(cookie); } } }
static void Main(string[] args) { const int UpgradedVersion = 49; // increment every release Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); #if DEBUG MessageBox.Show("Debug me", "DigiRite.exe"); #endif int settingsVersion = Properties.Settings.Default.SavedVersion; if (settingsVersion < UpgradedVersion) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.SavedVersion = UpgradedVersion; } CustomColors.CommonBackgroundColor = Properties.Settings.Default.Background; CustomColors.TxBackgroundColor = Properties.Settings.Default.TxBackground; if ((args.Length >= 1) && args[0].ToUpper() == "-EMBEDDING") { var regServices = new RegistrationServices(); int cookie = regServices.RegisterTypeForComClients( typeof(Ft8Auto), RegistrationClassContext.LocalServer, RegistrationConnectionType.SingleUse); applicationContext = new NoShowFormAppContext(); Application.Run(applicationContext); regServices.UnregisterTypeForComClients(cookie); } else { Application.Run(new MainForm(1)); } }
/// <summary> /// Registers the activator type as a COM server client so that Windows can launch your activator. /// </summary> public static void RegisterActivator <T>() where T : NotificationActivator { #if NET45 var regService = new RegistrationServices(); regService.RegisterTypeForComClients( typeof(T), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); _registeredActivator = true; #elif NETCOREAPP3_1 //Ole32.GetRunningObjectTable(0, out IRunningObjectTable rot); //Guid id = typeof(T).GUID; //CreateClassMoniker(ref id,out IMoniker moniker); //rot.Register(1, instance, moniker); ClassFactory factory = new ClassFactory(typeof(T)); IntPtr iunknow = Marshal.GetIUnknownForObject(factory); CoRegisterClassObject( typeof(T).GUID, factory, 4, 0, out uint id); _registeredActivator = true; #endif }
static void RunComServer() { Console.WriteLine("Starting Service"); try { _cookie = _reg_services.RegisterTypeForComClients( typeof(COMService), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); // Remove SD to simulate a more privileged process. RawSecurityDescriptor sd = new RawSecurityDescriptor("D:"); byte[] sd_bytes = new byte[sd.BinaryLength]; sd.GetBinaryForm(sd_bytes, 0); if (!SetKernelObjectSecurity(new IntPtr(-1), DACL_SECURITY_INFORMATION, sd_bytes)) { throw new Win32Exception(); } Console.WriteLine("Registered COM Class {0}", typeof(COMService).GUID); Console.ReadLine(); _reg_services.UnregisterTypeForComClients(_cookie); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.Message); } }
/// <summary> /// This method register this process as the COM server for the specified /// background task class until this process exits or is terminated. /// /// The process that is responsible for handling a particular background /// task must call RegisterTypeForComClients on the IBackgroundTask /// derived class. So long as this process is registered with the /// aforementioned API, it will be the process that has instances of the /// background task invoked. /// </summary> static void RegisterProcessForBackgroundTask(Type backgroundTaskClass) { RegistrationServices registrationServices = new RegistrationServices(); registrationServices.RegisterTypeForComClients(backgroundTaskClass, RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); }
public static void Initialize() { var regService = new RegistrationServices(); int cookie = regService.RegisterTypeForComClients( typeof(NotificationActivator), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); }
public static void Enable() { RegistrationServices = new RegistrationServices(); Cookie = RegistrationServices.RegisterTypeForComClients( typeof(NotificationActivator), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse ); }
private static void RegisterActivator(Type activatorType) { // Register type var regService = new RegistrationServices(); regService.RegisterTypeForComClients( activatorType, RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); }
/// <summary> /// Registers the activator type as a COM server client so that Windows can launch your activator. /// </summary> /// <typeparam name="T">Your implementation of NotificationActivator. Must have GUID and ComVisible attributes on class.</typeparam> public static void RegisterActivator <T>() where T : NotificationActivator { // Register type var regService = new RegistrationServices(); regService.RegisterTypeForComClients( typeof(T), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); _registeredActivator = true; }
/// <summary> /// Registers COM CLSID and EXE in LocalServer32 registry, and registers the activator type as a COM server client. /// When your EXE isn't running and an activation comes in, you will be launched with command line flags of -ToastActivation and -Embedded. /// </summary> /// <typeparam name="T">Your implementation of NotificationActivator. Must have GUID and ComVisible attributes on class.</typeparam> /// <param name="exePath">A custom EXE path.</param> public static void RegisterComServerAndActivator <T>(string exePath) where T : NotificationActivator { RegisterComServer <T>(exePath); // Register type var regService = new RegistrationServices(); regService.RegisterTypeForComClients( typeof(T), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); }
/// <summary> /// Registers the activator type as a COM server client so that Windows can launch your activator. /// </summary> /// <typeparam name="T">Your implementation of NotificationActivator. Must have GUID and ComVisible attributes on class.</typeparam> public static void RegisterActivator <T>() where T : NotificationActivatorBase { if (!OsVersion.IsTenOrNewer) { return; } if (_cookie.HasValue) { return; } // Register type var regService = new RegistrationServices(); _cookie = regService.RegisterTypeForComClients( typeof(T), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); }
public static void Regist() { RegistrationServices registrationServices = new RegistrationServices(); ComObject.cookie = registrationServices.RegisterTypeForComClients(typeof(ComObject), RegistrationClassContext.LocalServer | RegistrationClassContext.RemoteServer, RegistrationConnectionType.MultipleUse); }
internal static void RegisterCOMServer() { _services = new RegistrationServices(); _cookie = _services.RegisterTypeForComClients(typeof(DeploymentServiceCom), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); }
public static void Initialize() { regService = new RegistrationServices(); cookie = regService.RegisterTypeForComClients(typeof(ActivationHandler), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); }
public static void Initialize(string appId) { cookie = regService.RegisterTypeForComClients(typeof(NotificationActivator), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); RegisterAppForNotificationSupport(appId); }
private static void RegisterActivator() { RegistrationServices regService = new RegistrationServices(); regService.RegisterTypeForComClients(typeof(NotificationActivator), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse); }