public static void ShutDownApp(object sender, EventArgs e)
        {
            Debug.WriteLine("Ending application...");

            // This imports any residual data files.  These files would exist if:
            //  - New data files were imported for which the user was editing the master copy at the time
            //  - AND the user chose not to import these new data files during the session.
            FormMain.ImportNewDataFiles();

            // Note: This new boolean setting was introduced in Jan 2007.
            if (SysInfo.Data.Options.DataXfer.UnattendedSync)
            {
                // Note: The introduction of additional parameter handling code means that all startup switches,
                //       like "DataTransfer", must now be prefixed with a "/" or a "\" or a "-".
        #if (DEBUG)
                //Note: This next if-else clause had to be introduced because early deployments of the app were done with Debug compilations
                if (Application.StartupPath.LastIndexOf("bin\\Debug") != -1)
                {
                    RegistryTools.SetAutoStartOnConnect(SysInfo.Data.Paths.App + "bin\\Debug\\" + SysInfo.Data.Admin.AppFilename, "/DataTransfer");
                }
                else
                {
                    RegistryTools.SetAutoStartOnConnect(SysInfo.Data.Paths.App + SysInfo.Data.Admin.AppFilename, "/DataTransfer");
                }
        #else
                RegistryTools.SetAutoStartOnConnect(SysInfo.Data.Paths.App + SysInfo.Data.Admin.AppFilename, "/DataTransfer");
        #endif
            }

            // Testing has revealed that we can leave 'GuestOnly' set to 1 all the time since ActiveSync
            // seems able to distinguish the primary Pocket PC from other ones.
            // 2006-06-18 - RW - I ran into a situation where this prevented me from establishing a partnership, so we're now going to reset it as originally planned!
            RegistryTools.SetGuestOnly(false);

            // Save the SysInfo object to disk
            string sysInfoFile = SysInfo.Data.Paths.App + "SysInfo.xml";
            Tools.SaveData(sysInfoFile, SysInfo.Data, null, DataObjects.Constants.ExportFormat.XML);
            File.SetAttributes(sysInfoFile, FileAttributes.Hidden);    // This is separate because it doesn't work with the CF

            Tools.HandleTempDirectory(SysInfo.Data.Paths.Temp, false); // Tries to erase Temp folder and all files within
            Application.ExitThread();
        }