Beispiel #1
0
 public void registerApp()
 {
     if (!prof.IsRegistered(APPLICATION_NAME))
     {
         prof.Register(APPLICATION_NAME, "The Nite Ops Application");
     }
 }
Beispiel #2
0
 //
 // Register or unregister driver for ASCOM. This is harmless if already
 // registered or unregistered.
 //
 /// <summary>
 /// Register or unregister the driver with the ASCOM Platform.
 /// This is harmless if the driver is already registered/unregistered.
 /// </summary>
 /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
 static void RegUnregASCOM(bool bRegister)
 {
     using (var P = new ASCOM.Utilities.Profile())
     {
         P.DeviceType = "Camera";
         if (bRegister)
         {
             P.Register(driverID, driverDescription);
         }
         else
         {
             P.Unregister(driverID);
         }
     }
 }
 //
 // Register or unregister driver for ASCOM. This is harmless if already
 // registered or unregistered.
 //
 /// <summary>
 /// Register or unregister the driver with the ASCOM Platform.
 /// This is harmless if the driver is already registered/unregistered.
 /// </summary>
 /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
 private static void RegUnregASCOM(bool bRegister)
 {
     using (var P = new ASCOM.Utilities.Profile())
     {
         P.DeviceType = DRIVER_DEVICE_TYPE;
         if (bRegister)
         {
             P.Register(DRIVER_ID, DRIVER_DESCRIPTION);
         }
         else
         {
             P.Unregister(DRIVER_ID);
         }
     }
 }
Beispiel #4
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "ObservingConditions";
                if (bRegister)
                {
                    P.Register(Const.wiseBoltwoodDriverID, WiseBoltwood.driverDescription);
                }
                else
                {
                    P.Unregister(Const.wiseBoltwoodDriverID);
                }
            }
        }
Beispiel #5
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "ObservingConditions";
                if (bRegister)
                {
                    P.Register(OpenWeatherMap.driverID, driverDescription);
                }
                else
                {
                    P.Unregister(OpenWeatherMap.driverID);
                }
            }
        }
Beispiel #6
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "FilterWheel";
                if (bRegister)
                {
                    P.Register(WiseFilterWheel.DriverID, WiseFilterWheel.Description);
                }
                else
                {
                    P.Unregister(WiseFilterWheel.DriverID);
                }
            }
        }
Beispiel #7
0
 // Register or unregister driver for ASCOM. This is harmless if already
 // registered or unregistered.
 //
 /// <summary>
 /// Register or unregister the driver with the ASCOM Platform.
 /// This is harmless if the driver is already registered/unregistered.
 /// </summary>
 /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
 private static void RegUnregASCOM(bool bRegister)
 {
     using (var P = new ASCOM.Utilities.Profile())
     {
         P.DeviceType = "Dome";
         if (bRegister)
         {
             P.Register(driverID, driverDescription);
         }
         else
         {
             P.Unregister(driverID);
         }
     }
 }
        //
        // Do everything to register this for COM. Never use REGASM on
        // this exe assembly! It would create InProcServer32 entries
        // which would prevent proper activation!
        //
        // Using the list of COM object types generated during dynamic
        // assembly loading, it registers each one for COM as served by our
        // exe/local server, as well as registering it for ASCOM. It also
        // adds DCOM info for the local server itself, so it can be activated
        // via an outboiud connection from TheSky.
        //
        private static void RegisterObjects()
        {
            if (!IsAdministrator)
            {
                ElevateSelf("/register");
                return;
            }
            //
            // If reached here, we're running elevated
            //

            Assembly  assy      = Assembly.GetExecutingAssembly();
            Attribute attr      = Attribute.GetCustomAttribute(assy, typeof(AssemblyTitleAttribute));
            string    assyTitle = ((AssemblyTitleAttribute)attr).Title;

            attr = Attribute.GetCustomAttribute(assy, typeof(AssemblyDescriptionAttribute));
            string assyDescription = ((AssemblyDescriptionAttribute)attr).Description;

            //
            // Local server's DCOM/AppID information
            //
            try
            {
                //
                // HKCR\APPID\appid
                //
                using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("APPID\\" + s_appId))
                {
                    key.SetValue(null, assyDescription);
                    key.SetValue("AppID", s_appId);
                    key.SetValue("AuthenticationLevel", 1, RegistryValueKind.DWord);
                }
                //
                // HKCR\APPID\exename.ext
                //
                using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("APPID\\{0}",
                                                                                         Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1))))
                {
                    key.SetValue("AppID", s_appId);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while registering the server:\n" + ex.ToString(),
                                "OpenAstroTracker", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            finally
            {
            }

            //
            // For each of the driver assemblies
            //
            foreach (Type type in s_ComObjectTypes)
            {
                bool bFail = false;
                try
                {
                    //
                    // HKCR\CLSID\clsid
                    //
                    string clsid  = Marshal.GenerateGuidForType(type).ToString("B");
                    string progid = Marshal.GenerateProgIdForType(type);
                    //PWGS Generate device type from the Class name
                    string deviceType = type.Name;

                    using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("CLSID\\{0}", clsid)))
                    {
                        key.SetValue(null, progid);                                             // Could be assyTitle/Desc??, but .NET components show ProgId here
                        key.SetValue("AppId", s_appId);
                        using (RegistryKey key2 = key.CreateSubKey("Implemented Categories"))
                        {
                            key2.CreateSubKey("{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}");
                        }
                        using (RegistryKey key2 = key.CreateSubKey("ProgId"))
                        {
                            key2.SetValue(null, progid);
                        }
                        key.CreateSubKey("Programmable");
                        using (RegistryKey key2 = key.CreateSubKey("LocalServer32"))
                        {
                            key2.SetValue(null, Application.ExecutablePath);
                        }
                    }
                    //
                    // HKCR\CLSID\progid
                    //
                    using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(progid))
                    {
                        key.SetValue(null, assyTitle);
                        using (RegistryKey key2 = key.CreateSubKey("CLSID"))
                        {
                            key2.SetValue(null, clsid);
                        }
                    }
                    //
                    // ASCOM
                    //
                    assy = type.Assembly;

                    // Pull the display name from the ServedClassName attribute.
                    attr = Attribute.GetCustomAttribute(type, typeof(ServedClassNameAttribute)); //PWGS Changed to search type for attribute rather than assembly
                    string chooserName = ((ServedClassNameAttribute)attr).DisplayName ?? "MultiServer";
                    using (var P = new ASCOM.Utilities.Profile())
                    {
                        P.DeviceType = deviceType;
                        P.Register(progid, chooserName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while registering the server:\n" + ex.ToString(),
                                    "OpenAstroTracker", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    bFail = true;
                }
                finally
                {
                }
                if (bFail)
                {
                    break;
                }
            }
        }
Beispiel #9
0
 //
 // Register or unregister driver for ASCOM. This is harmless if already
 // registered or unregistered.
 //
 private static void RegUnregASCOM(bool bRegister)
 {
     ASCOM.Utilities.Profile P = new ASCOM.Utilities.Profile();
     P.DeviceType = "Focuser";					//  Requires Helper 5.0.3 or later
     if (bRegister)
         P.Register(s_csDriverID, s_csDriverDescription);
     else
         P.Unregister(s_csDriverID);
     try										// In case Helper becomes native .NET
     {
         Marshal.ReleaseComObject(P);
     }
     catch (Exception) { }
     P = null;
 }
        // Do everything to register this for COM. Never use REGASM on
        // this exe assembly! It would create InProcServer32 entries
        // which would prevent proper activation!

        // Using the list of COM object types generated during dynamic
        // assembly loading, it registers each one for COM as served by our
        // exe/local server, as well as registering it for ASCOM. It also
        // adds DCOM info for the local server itself, so it can be activated
        // via an outbound connection from TheSky.

        private static void RegisterObjects(bool rerunningAsElevated = false)
        {
            if (rerunningAsElevated)
            {
                if (!IsElevated)
                {
                    MessageBox.Show("Unable to gain elevated privileges to register the Device Hub.\n\n"
                                    + "Possible fixes are to enable User Account Control and/or add your user account\n"
                                    + "to the local Administrators group. Then re-install the Device Hub",
                                    "DeviceHub", MessageBoxButton.OK, MessageBoxImage.Stop);

                    return;
                }
            }
            else
            {
                if (!IsElevated)
                {
                    // Here we want to elevate a copy of ourselves, unless we are running under the VS Debugger.

                    RerunAsAdministrator("/regElevated");

                    return;
                }
            }

            // If reached here, we're running elevated

            Assembly  assy      = Assembly.GetExecutingAssembly();
            Attribute attr      = Attribute.GetCustomAttribute(assy, typeof(AssemblyTitleAttribute));
            string    assyTitle = ((AssemblyTitleAttribute)attr).Title;

            attr = Attribute.GetCustomAttribute(assy, typeof(AssemblyDescriptionAttribute));
            string assyDescription = ((AssemblyDescriptionAttribute)attr).Description;

            // Local server's DCOM/AppID information

            try
            {
                // HKCR\APPID\appid

                using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("APPID\\" + _appId))
                {
                    key.SetValue(null, assyDescription);
                    key.SetValue("AppID", _appId);
                    key.SetValue("AuthenticationLevel", 1, RegistryValueKind.DWord);
                    key.SetValue("RunAs", "Interactive User", RegistryValueKind.String);                       // Added to ensure that only one copy of the local server ...
                }

                // HKCR\APPID\exename.ext

                using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("APPID\\{0}",
                                                                                         GetExecutableFileName())))
                {
                    key.SetValue("AppID", _appId);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while registering the server:\n" + ex.ToString(),
                                "DeviceHub", MessageBoxButton.OK, MessageBoxImage.Stop);

                return;
            }

            // For each of the driver assemblies

            foreach (Type type in _comObjectTypes)
            {
                bool bFail = false;

                try
                {
                    // HKCR\CLSID\clsid

                    string clsid  = Marshal.GenerateGuidForType(type).ToString("B");
                    string progid = Marshal.GenerateProgIdForType(type);

                    //PWGS Generate device type from the Class name

                    string deviceType = type.Name;

                    using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("CLSID\\{0}", clsid)))
                    {
                        key.SetValue(null, progid);                                               // Could be assyTitle/Desc??, but .NET components show ProgId here
                        key.SetValue("AppId", _appId);

                        using (RegistryKey key2 = key.CreateSubKey("Implemented Categories"))
                        {
                            key2.CreateSubKey("{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}");
                        }

                        using (RegistryKey key2 = key.CreateSubKey("ProgId"))
                        {
                            key2.SetValue(null, progid);
                        }

                        key.CreateSubKey("Programmable");

                        using (RegistryKey key2 = key.CreateSubKey("LocalServer32"))
                        {
                            string path = GetExecutablePath();
                            key2.SetValue(null, path);
                        }
                    }

                    // HKCR\CLSID\progid

                    using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(progid))
                    {
                        key.SetValue(null, assyTitle);
                        using (RegistryKey key2 = key.CreateSubKey("CLSID"))
                        {
                            key2.SetValue(null, clsid);
                        }
                    }

                    // ASCOM

                    assy = type.Assembly;

                    // Pull the display name from the ServedClassName attribute.

                    attr = Attribute.GetCustomAttribute(type, typeof(ServedClassNameAttribute));                         //PWGS Changed to search type for attribute rather than assembly
                    string chooserName = ((ServedClassNameAttribute)attr).DisplayName ?? "MultiServer";

                    using (var P = new ASCOM.Utilities.Profile())
                    {
                        P.DeviceType = deviceType;
                        P.Register(progid, chooserName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while registering the server:\n" + ex.ToString(),
                                    "DeviceHub", MessageBoxButton.OK, MessageBoxImage.Stop);
                    bFail = true;
                }
                finally
                { }

                if (bFail)
                {
                    break;
                }
            }
        }