Exemple #1
0
 public static void Restore(LLApplication app)
 {
     if (app.IsImported)
     {
         if (app.RegistryInfo != null)
         {
             var regKeys = new List <RegistryKey>()
             {
                 RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default),
                 RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default)
             };
             foreach (var regKey in regKeys)
             {
                 if (regKey.Name == app.RegistryInfo.RegistryName)
                 {
                     var registeryKey = regKey.OpenSubKey(app.RegistryInfo.RegistryLocation, true);
                     if (registeryKey != null)
                     {
                         registeryKey.SetValue(app.RegistryInfo.RegistryKey, app.RegistryInfo.RegistryValue);
                     }
                 }
             }
         }
         else if (app.FolderInfo != null)
         {
             LLUtilities.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup), app.FullPath, app.Arguments, app.Name);
         }
     }
     else
     {
         LLUtilities.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup), app.FullPath, app.Arguments, app.Name);
     }
 }
Exemple #2
0
        private static IList <StartupItem> PopulateFolderStartupItems()
        {
            var startupItems = new List <StartupItem>();
            // check startup folder for current user
            var startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            if (Directory.Exists(startupFolder))
            {
                // only look for shortcuts, we don't want to deal with actual executables in the startup directory
                // we would have to do some weird copy to LL folder and execute there
                // we would probably have permission and locking issues as well
                var files = LLUtilities.GetFiles(startupFolder, "*.lnk");
                foreach (var file in files)
                {
                    var shortCutFile = new FileInfo(file);
                    var filePath     = file;
                    var args         = string.Empty;
                    if (file.Contains(".lnk"))
                    {
                        filePath = LLUtilities.ResolveShortcutPath(file);
                        args     = LLUtilities.ResolveShortcutArguments(file);
                    }

                    // make sure we skip LL if it is somehow in the registry
                    if (LLUtilities.LLIsTryingToRunItself(filePath))
                    {
                        continue;
                    }

                    // parse the file name in case the shortcut was bad
                    var fileInfo = new FileInfo(filePath);
                    if (fileInfo.Exists)
                    {
                        startupItems.Add(new StartupFolderItem(shortCutFile.Name, args, fileInfo.FullName, shortCutFile.FullName));
                    }
                }
            }
            return(startupItems);
        }
Exemple #3
0
        private void callback(object stateInfo)
        {
            if (LLUtilities.LLIsTryingToRunItself(App.FullPath))
            {
                Started = true;
                return;
            }

            if (!System.IO.File.Exists(App.FullPath))
            {
                Started = true; //let the launcher think it ran, even though the executable doesn't exist. This effectively swallows the error.
                return;
            }

            AppStarting(this, new AppStartingEventArgs {
                Name = App.Name
            });

            try
            {
                Process p = new Process();

                p.StartInfo.FileName  = App.FullPath;
                p.StartInfo.Arguments = App.Arguments;

                p.Start();
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("LaunchLater", "Error executing app... " + ex.ToString());
                throw new LLApplicationNotFoundException();
            }
            finally
            {
                Started = true;
                killTimer();
            }
        }
Exemple #4
0
        private static IList <StartupItem> PopulateRegistryStartupItems()
        {
            var startupItems = new List <StartupItem>();

            var regKeys = new List <RegistryKey>()
            {
                RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64),
                RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32),
                RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64),
                RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32)
            };

            // check registry
            string runKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";

            foreach (var regKey in regKeys)
            {
                if (regKey != null)
                {
                    foreach (var reg in GetRegistryItemsForKey(regKey, runKey))
                    {
                        // make sure we skip LL if it is somehow in the registry
                        if (LLUtilities.LLIsTryingToRunItself(reg.Value))
                        {
                            continue;
                        }

                        var filePath = reg.Value;

                        var pathAndArgs = filePath.Split('.');
                        filePath = (pathAndArgs[0] + ".exe").Replace('\"', ' ').Trim();

                        var argsString = string.Empty;

                        if (pathAndArgs.Length > 1)
                        {
                            argsString = pathAndArgs[1].Remove(0, 3).Trim().Replace('\"', ' ');
                        }


                        if (!File.Exists(filePath))
                        {
                            // we need to attempt to break out the path from the command arguments

                            //var inQuotes = false;
                            //var pathValues = reg.Value.Split(c =>
                            //{
                            //    if (c == '\"')
                            //        inQuotes = !inQuotes;

                            //    return !inQuotes && c == ' ';
                            //})
                            //.Select(arg => arg.Replace("\"", ""))
                            //.Where(arg => !string.IsNullOrEmpty(arg)).ToList();

                            //filePath = getFilePath(ref pathValues);
                            //pathValues.FirstOrDefault();

                            //// either we have a parsing error or the file doesn't exist, just skip it and move along
                            //if (filePath == null || !File.Exists(filePath))
                            continue;


                            //foreach (var args in pathValues)
                            //{
                            //    if (args != filePath)
                            //    {
                            //        if (argsString != string.Empty)
                            //            argsString += " ";
                            //        argsString += args;
                            //    }
                            //}
                        }

                        var existingApp = (from a in startupItems
                                           where a.FullPath == filePath
                                           select a).ToList();

                        if (existingApp.Count == 0)
                        {
                            startupItems.Add(new StartupRegistryItem(filePath, reg.Key, reg.Value, regKey.Name, runKey, argsString));
                        }
                    }
                }
            }

            return(startupItems);
        }