posted on Monday, October 29, 2007 7:10 PM |

Why did I create a delayed startup program?  After I saw all the stuff my manager had booting up on his computer, I thought this may be useful.  His computer really wasn't terribly usable for a good 10 minutes after a reboot so I decided to spend a few minutes and create him a nice program while I'm at a .Net User Group meeting (they had free food and it was 1 floor up in my building).  My theory is most of the programs in your startup folder aren't actually needed asap.  I don't need OneNote open right away, I don't need a bunch of other stuff right away.  The nice thing is now I can have Visual Studio, Outlook, IE, and a few other programs I run everyday not impact me restarting my computer's bootup time since they'll do a gradual loading sequence.

Why isn't there an application to do the configuration file?  Because I'd hope someone could decipher 3 lines of XML.

Here is the source code (and the .zip file) and the installer

Source Code:

[STAThread]
static void Main()
{
    string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
    string delayedStartupFolder = GetSetting("DelayedStartupFolderName", "Delayed Startup");

    int TimeDelayBeforeStartingSeconds = GetSetting("TimeDelayBeforeStartingSeconds", 10);
    int TimeDelayPerProcesssSeconds = GetSetting("TimeDelayPerProcesssSeconds", 5);

    DirectoryInfo di = new DirectoryInfo(startupPath);

    Thread.Sleep(TimeDelayBeforeStartingSeconds * 1000);
    string delayedFolder = Path.Combine(di.Parent.FullName, delayedStartupFolder);
    if (Directory.Exists(delayedFolder))
    {
        di = new DirectoryInfo(delayedFolder);

        FileInfo[] files = di.GetFiles();
        foreach (FileInfo file in files)
        {
            if (file.Extension.ToLower() != ".ini")
            {
                Process.Start(file.FullName);
                Thread.Sleep(TimeDelayPerProcesssSeconds * 1000);
            }
        }
    }
}

private static int GetSetting(string key, int defaultValue)
{
    int.TryParse(ConfigurationManager.AppSettings[key], out defaultValue);

    return defaultValue;
}

private static string GetSetting(string key, string defaultValue)
{
    return ConfigurationManager.AppSettings[key] ?? defaultValue;
}

App.Config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="DelayedStartupFolderName" value="Delayed Startup"/>
        <add key="TimeDelayBeforeStartingSeconds" value="10"/>
        <add key="TimeDelayPerProcesssSeconds" value="5"/>
    </appSettings>
</configuration>
Tags [ General ]

Your Comments.

  • # re: Delayed Startup

    Do you have instructions on how to get your program to work? I kind of get the code, but am not sure where to start.

    Left by Paul Abke at 8/13/2008 7:09 AM
  • # re: Delayed Startup

    Paul, what do you need help on exactly? If you opt for the installer, you just need to have a folder called "Delayed Startup" in your menu. Put all shortcuts that you want to start up after your system has.

    If you want the time delays bigger, modify the app.config file.

    Left by Clint Rutkas at 8/13/2008 11:42 AM
Post Comment
Title *
Name *
Email
Url
Comment *  
Please add 4 and 3 and type the answer here: