private static string[] expandArgs(StartupEntry startupEntry) { string[] procInfo = new string[2]; // don't bother expanding paths we know have no args if (startupEntry.Location.Type != StartupEntryType.Directory) { int exeIndex = startupEntry.Path.IndexOf(".exe"); // we may have args for an executable if (exeIndex > 0 && exeIndex + 4 != startupEntry.Path.Length) { // argh, args! procInfo[0] = startupEntry.Path.Substring(0, exeIndex + 4); procInfo[1] = startupEntry.Path.Substring(exeIndex + 5, startupEntry.Path.Length - exeIndex - 5); } else { procInfo[0] = startupEntry.Path; } } else { // no args to parse out procInfo[0] = startupEntry.Path; } return(procInfo); }
/// <summary> /// Gets the list of startup entries /// </summary> /// <returns></returns> public List <StartupEntry> GetStartupEntries() { List <StartupEntry> startupEntries = new List <StartupEntry>(); try { // the registry key containing commands that run every startup RegistryKey runRegistryKey = Registry.CurrentUser.OpenSubKey(_RUN_REGISTRY_KEY); // the registry key containing commands that run only once RegistryKey runOnceRegistryKey = Registry.CurrentUser.OpenSubKey(_RUN_ONCE_REGISTRY_KEY); string[] runValueNames = runRegistryKey.GetValueNames(); string[] runOnceValueNames = runOnceRegistryKey.GetSubKeyNames(); foreach (string valueName in runValueNames) { StartupEntry re = new StartupEntry(); re.EntryName = valueName; re.EntryCommand = runRegistryKey.GetValue(valueName).ToString(); startupEntries.Add(re); } foreach (string valueName in runOnceValueNames) { StartupEntry re = new StartupEntry(); re.EntryName = valueName; re.EntryCommand = runOnceRegistryKey.GetValue(valueName).ToString(); startupEntries.Add(re); } } catch (Exception exc) { MyDebugger.Instance.LogMessage(exc, DebugVerbocity.Exception); } return(startupEntries); }