Esempio n. 1
0
        public static void SetAutostart(bool debugMode, bool showPopup)
        {
            try
            {
                //if (!IsStartupItem(curAssembly))
                //{
                //    RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\StartupFolder", true);

                //    key.SetValue(curAssembly.GetName().Name, curAssembly.Location);

                //    Trace.TraceInformation("Autostart Setted");
                //}
                //CheckAutostartEnabled(curAssembly.GetName().Name);

                string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
                string lnkPath           = startUpFolderPath + "\\" +
                                           curAssembly.GetName().Name + ".lnk";

                if (debugMode)
                {
                    Trace.TraceInformation("Startup assembly name: {0}", curAssembly.GetName().Name);
                }

                if (!System.IO.File.Exists(lnkPath))
                {
                    WshShell wshShell = new WshShell();
                    IWshRuntimeLibrary.IWshShortcut shortcut;

                    // Create the shortcut
                    shortcut =
                        (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(lnkPath);
                    shortcut.TargetPath       = curAssembly.Location;
                    shortcut.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
                    shortcut.Description      = "Scream Control Launch";
                    shortcut.Save();

                    if (showPopup)
                    {
                        InfoPopupView infoPopup = new InfoPopupView();
                        infoPopup.Owner          = Application.Current.MainWindow;
                        infoPopup.textBlock.Text = Application.Current.FindResource(STARTUP_ADDED).ToString();
                        infoPopup.Show();
                    }

                    Trace.TraceInformation("App added to autostart");
                }
            }
            catch (Exception e)
            {
                Trace.TraceError("Something happened at Autostart set: {0}", e);
            }

            CheckAutostartEnabled(debugMode, showPopup);
        }
Esempio n. 2
0
        public static void CheckAutostartEnabled(bool debugMode, bool showPopup)
        {
            try
            {
                //string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
                //string lnkPath = startUpFolderPath + "\\" +
                //    curAssembly.GetName().Name + ".lnk";
                RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\StartupFolder", true);
                if (key != null)
                {
                    byte[] newValue = (byte[])key.GetValue(curAssembly.GetName().Name + ".lnk");
                    if (newValue != null)
                    {
                        if (newValue[0] != 2)
                        {
                            newValue[0] = 2;
                            key.SetValue(curAssembly.GetName().Name + ".lnk", newValue);

                            if (showPopup)
                            {
                                InfoPopupView infoPopup = new InfoPopupView();
                                infoPopup.Owner          = Application.Current.MainWindow;
                                infoPopup.textBlock.Text = Application.Current.FindResource(STARTUP_READDED).ToString();
                                infoPopup.Show();
                            }

                            Trace.TraceInformation("Autostart Reenabled");
                            return;
                        }
                    }
                }
                Trace.TraceWarning("No registry key found");
            }
            catch (Exception e)
            {
                Trace.TraceError("Something happened at Autostart enabling: {0}", e);
            }
        }