Example #1
0
        public static void RunRegistryTest()
        {
            string value = string.Empty;

            try
            {
                WindowsRegistry.pfRegistryValue retValue;
                //bool regEntryExists = false;

                retValue    = WindowsRegistry.GetRegistryValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name01", "default value is this");
                _msg.Length = 0;
                _msg.Append("Registry read: ");
                _msg.Append(retValue.regValue);
                Program._messageLog.WriteLine(_msg.ToString());

                _str.Length = 0;
                _str.Append("Updated Value ");
                _str.Append(DateTime.Now.ToString("HH_mm_ss"));
                retValue    = WindowsRegistry.SetRegistryValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name01", (string)_str.ToString());
                _msg.Length = 0;
                _msg.Append("Registry write: ");
                _msg.Append(retValue.regValue);
                _msg.Append(" is the value that was set.");
                Program._messageLog.WriteLine(_msg.ToString());

                _str.Length = 0;
                _str.Append("Modified Value ");
                _str.Append(DateTime.Now.ToString("HHmmss"));
                retValue    = WindowsRegistry.SetRegistryValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name02", (string)_str.ToString());
                _msg.Length = 0;
                _msg.Append("Registry write: ");
                _msg.Append(retValue.regValue);
                _msg.Append(" is the value that was set.");
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Name01 ");
                if (WindowsRegistry.RegistryValueNameExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name01"))
                {
                    _msg.Append("exists.");
                }
                else
                {
                    _msg.Append("does not exist.");
                }
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Name01 for Testprog55 ");
                if (WindowsRegistry.RegistryValueNameExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog55", "Name01"))
                {
                    _msg.Append("exists.");
                }
                else
                {
                    _msg.Append("does not exist.");
                }
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Name02 ");
                if (WindowsRegistry.RegistryValueNameExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name02"))
                {
                    _msg.Append("exists.");
                }
                else
                {
                    _msg.Append("does not exist.");
                }
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Name02 Delete result: ");
                if (WindowsRegistry.DeleteRegistryValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name02"))
                {
                    _msg.Append("Succeeded");
                }
                else
                {
                    _msg.Append("Failed");
                }
                Program._messageLog.WriteLine(_msg.ToString());


                _msg.Length = 0;
                _msg.Append("DeleteRegistrySubKey Testprog2: ");
                if (WindowsRegistry.DeleteRegistrySubKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog2"))
                {
                    _msg.Append("Succeeded");
                }
                else
                {
                    _msg.Append("Failed");
                }
                Program._messageLog.WriteLine(_msg.ToString());


                _msg.Length = 0;
                _msg.Append("CreateRegistrySubKey Testprog2: ");
                if (WindowsRegistry.CreateRegistrySubKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog2"))
                {
                    _msg.Append("Succeeded");
                }
                else
                {
                    _msg.Append("Failed");
                }
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Registry SubKey Testprog2 was ");
                if (WindowsRegistry.RegistrySubKeyExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog2"))
                {
                    _msg.Append("found.");
                }
                else
                {
                    _msg.Append("not found.");
                }
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("CreateRegistrySubKey: ");
                if (WindowsRegistry.CreateRegistrySubKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing2"))
                {
                    _msg.Append("Succeeded");
                }
                else
                {
                    _msg.Append("Failed");
                }
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Registry SubKey was ");
                if (WindowsRegistry.RegistrySubKeyExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing2"))
                {
                    _msg.Append("found.");
                }
                else
                {
                    _msg.Append("not found.");
                }
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("DeleteRegistrySubKey: ");
                if (WindowsRegistry.DeleteRegistrySubKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing2"))
                {
                    _msg.Append("Succeeded");
                }
                else
                {
                    _msg.Append("Failed");
                }
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Registry SubKey was ");
                if (WindowsRegistry.RegistrySubKeyExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing2"))
                {
                    _msg.Append("found.");
                }
                else
                {
                    _msg.Append("not found.");
                }
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                ;
            }
        } //end RunRegistryTest