ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/AnywhereTS-MSSQL/trunk/TSAdminTool/Globals.cs
(Generate patch)

Comparing trunk/TSAdminTool/Globals.cs (file contents):
Revision 115 by william, Sat Jul 14 07:18:30 2012 UTC vs.
Revision 116 by william, Sat Jul 14 08:03:33 2012 UTC

--- trunk/TSAdminTool/Globals.cs	2012/07/14 07:31:18	115
+++ trunk/TSAdminTool/Globals.cs	2012/07/14 08:03:33	116
@@ -137,7 +137,14 @@ namespace AnywhereTS
         // Get a registry string
         public static string GetATSRegValueString(string regValue)
         {
-            return GetRegValue(strATSregRoot, regValue);
+            string value = string.Empty;
+            using (log4net.NDC.Push(string.Format("key={0} name={1}", strATSregRoot, regValue)))
+            {
+                Logging.ATSAdminLog.DebugFormat(@"Getting value from Registry: {0}\{1}", strATSregRoot, regValue);
+                value = GetRegValue(strATSregRoot, regValue);
+                Logging.ATSAdminLog.DebugFormat(@"value={0}", value);
+            }
+            return value;
         }
         #endregion
 
@@ -145,7 +152,14 @@ namespace AnywhereTS
         // Get a registry integer from the application key
         public static int GetATSRegValueInt(string regValue)
         {
-            return GetRegValueInt(strATSregRoot, regValue);
+            int value = -1;
+            using (log4net.NDC.Push(string.Format("key={0} name={1}", strATSregRoot, regValue)))
+            {
+                Logging.ATSAdminLog.DebugFormat(@"Getting value from Registry: {0}\{1}", strATSregRoot, regValue);
+                value = GetRegValueInt(strATSregRoot, regValue);
+                Logging.ATSAdminLog.DebugFormat(@"value={0}", value);
+            }
+            return value;
         }
         #endregion
 
@@ -168,67 +182,81 @@ namespace AnywhereTS
         #region public static string GetRegValue(string regKey, string regValue)
         // Get a registry string
         public static string GetRegValue(string regKey, string regValue)
-        {
-            Microsoft.Win32.RegistryKey objRegkey;
-            
-            try
-            {
-                objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
-            }
-            catch (ArgumentNullException ex)
-            {
-                MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (22411)");
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
+        {          
+                Microsoft.Win32.RegistryKey objRegkey;
+
+                try
+                {
+                    objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
+                }
+                catch (ArgumentNullException ex)
                 {
-                    using (log4net.NDC.Push("Installation info missing."))
+                    MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (22411)");
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
                     {
-                        Logging.ATSAdminLog.Error("Error when reading from registry.");
+                        using (log4net.NDC.Push("Installation info missing."))
+                        {
+                            Logging.ATSAdminLog.Error("Error when reading from registry.");
+                        }
                     }
+                    Application.Exit();
+                    return "";
                 }
-                Application.Exit();
-                return "";
-            }
-            catch (SecurityException ex)
-            {
-                MessageBox.Show("Error when reading from registry. You do not have the necessary permission (22412). Key: "+ regKey + " Value: " + regValue + " Error details:" + ex.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
+                catch (SecurityException ex)
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    MessageBox.Show("Error when reading from registry. You do not have the necessary permission (22412). Key: " + regKey + " Value: " + regValue + " Error details:" + ex.Message);
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
                     {
-                        using (log4net.NDC.Push("Invalid users rights."))
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                         {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");
+                            using (log4net.NDC.Push("Invalid users rights."))
+                            {
+                                Logging.ATSAdminLog.Error("Error when reading from registry.");
+                            }
                         }
                     }
+                    Application.Exit();
+                    return "";
                 }
-                Application.Exit();
-                return "";
-            }
-            catch (Exception ex)
-            {
-                MessageBox.Show("Error when reading from registry (22413). Key: " + regKey + " Value: " + regValue + " Error details:" + ex.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
+                catch (Exception ex)
                 {
-                    Logging.ATSAdminLog.Error("Error when reading from registry.");                   
+                    MessageBox.Show("Error when reading from registry (22413). Key: " + regKey + " Value: " + regValue + " Error details:" + ex.Message);
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
+                    {
+                        Logging.ATSAdminLog.Error("Error when reading from registry.");
+                    }
+                    Application.Exit();
+                    return "";
                 }
-                Application.Exit();
-                return "";
-            }
-            
-            if (objRegkey != null)
-            {
-                if (objRegkey.GetValue(regValue) != null)
+
+                if (objRegkey != null)
                 {
-                    try
+                    if (objRegkey.GetValue(regValue) != null)
                     {
-                        return objRegkey.GetValue(regValue).ToString();
+                        try
+                        {
+                            return objRegkey.GetValue(regValue).ToString();
+                        }
+                        catch (Exception e)
+                        {
+                            MessageBox.Show("Error when reading from registry (22414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                            using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                            {
+                                Logging.ATSAdminLog.Error("Error when reading from registry.");
+                            }
+                            Application.Exit();
+                            return "";
+                        }
                     }
-                    catch (Exception e)
+                    else
                     {
-                        MessageBox.Show("Error when reading from registry (22414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                        using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                        MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue);
+                        using (log4net.NDC.Push(string.Format("key={0}", regKey)))
                         {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");
+                            using (log4net.NDC.Push("Value is missing"))
+                            {
+                                Logging.ATSAdminLog.Error("Error when reading from registry.");
+                            }
                         }
                         Application.Exit();
                         return "";
@@ -236,31 +264,17 @@ namespace AnywhereTS
                 }
                 else
                 {
-                    MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue);
-                    using (log4net.NDC.Push(string.Format("key={0}", regKey)))
+                    MessageBox.Show("Error when reading from registry (55221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
+                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                     {
-                        using (log4net.NDC.Push("Value is missing"))
+                        using (log4net.NDC.Push("Key is missing"))
                         {
                             Logging.ATSAdminLog.Error("Error when reading from registry.");
                         }
                     }
                     Application.Exit();
-                    return "";
-                }
-            }
-            else
-            {
-                MessageBox.Show("Error when reading from registry (55221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root);
-                using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
-                {
-                    using (log4net.NDC.Push("Key is missing"))
-                    {
-                        Logging.ATSAdminLog.Error("Error when reading from registry.");
-                    }
                 }
-                Application.Exit();
-            }
-            return ""; // No value could be retrieved from registry
+                return ""; // No value could be retrieved from registry
         }
         #endregion
 
@@ -268,78 +282,79 @@ namespace AnywhereTS
         // Get a registry integer
         public static int GetRegValueInt(string regKey, string regValue)
         {
-            Microsoft.Win32.RegistryKey objRegkey;
+          
+                Microsoft.Win32.RegistryKey objRegkey;
 
-            try
-            {
-                objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
-            }
-            catch (ArgumentNullException ex)
-            {
-                MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (22411)");
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
+                try
                 {
-                    using (log4net.NDC.Push("Installation info missing."))
-                    {
-                        Logging.ATSAdminLog.Error("Error when reading from registry.");
-                    }
+                    objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey);
                 }
-                Application.Exit();
-                return 0;
-            }
-            catch (SecurityException e)
-            {
-                MessageBox.Show("Error when reading from registry. You do not have the necessary permission (22412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                catch (ArgumentNullException ex)
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (22411)");
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
                     {
-                        using (log4net.NDC.Push("Invalid user rights."))
+                        using (log4net.NDC.Push("Installation info missing."))
                         {
                             Logging.ATSAdminLog.Error("Error when reading from registry.");
                         }
                     }
+                    Application.Exit();
+                    return 0;
                 }
-                Application.Exit();
-                return 0;
-            }
-            catch (Exception e)
-            {
-                MessageBox.Show("Error when reading from registry (22413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                catch (SecurityException e)
                 {
-                        Logging.ATSAdminLog.Error("Error when reading from registry.");                  
+                    MessageBox.Show("Error when reading from registry. You do not have the necessary permission (22412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                    {
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                        {
+                            using (log4net.NDC.Push("Invalid user rights."))
+                            {
+                                Logging.ATSAdminLog.Error("Error when reading from registry.");
+                            }
+                        }
+                    }
+                    Application.Exit();
+                    return 0;
                 }
-                Application.Exit();
-                return 0;
-            }
-
-            if (objRegkey != null)
-            {
-                if (objRegkey.GetValue(regValue) != null)
+                catch (Exception e)
                 {
-                    try
+                    MessageBox.Show("Error when reading from registry (22413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
-                        return (int)objRegkey.GetValue(regValue);
+                        Logging.ATSAdminLog.Error("Error when reading from registry.");
                     }
-                    catch (Exception e)
+                    Application.Exit();
+                    return 0;
+                }
+
+                if (objRegkey != null)
+                {
+                    if (objRegkey.GetValue(regValue) != null)
                     {
-                        MessageBox.Show("Error when reading from registry (22414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                        using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                        try
                         {
-                            using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                            return (int)objRegkey.GetValue(regValue);
+                        }
+                        catch (Exception e)
+                        {
+                            MessageBox.Show("Error when reading from registry (22414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                            using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                             {
-                                    Logging.ATSAdminLog.Error("Error when reading from registry.");                                
+                                using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                                {
+                                    Logging.ATSAdminLog.Error("Error when reading from registry.");
+                                }
                             }
+                            Application.Exit();
+                            return 0;
                         }
-                        Application.Exit();
-                        return 0;
                     }
-                }
-                else
-                {
-                    MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue);
-                 
+                    else
+                    {
+                        MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue);
+
                         using (log4net.NDC.Push(string.Format("key={0}", regKey)))
                         {
                             using (log4net.NDC.Push("Value is missing"))
@@ -347,15 +362,15 @@ namespace AnywhereTS
                                 Logging.ATSAdminLog.Error("Error when reading from registry.");
                             }
                         }
-                    
-                    Application.Exit();
-                    return 0;
+
+                        Application.Exit();
+                        return 0;
+                    }
                 }
-            }
-            else
-            {
-                MessageBox.Show("Error when reading from registry (55221). Key missing. Key: " + regKey + " Value: " + regValue);
-               
+                else
+                {
+                    MessageBox.Show("Error when reading from registry (55221). Key missing. Key: " + regKey + " Value: " + regValue);
+
                     using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                     {
                         using (log4net.NDC.Push("Key is missing"))
@@ -363,10 +378,10 @@ namespace AnywhereTS
                             Logging.ATSAdminLog.Error("Error when reading from registry.");
                         }
                     }
-                
-                Application.Exit();
-            }
-            return 0; // No value could be retrieved from registry
+
+                    Application.Exit();
+                }
+                return 0; // No value could be retrieved from registry
         }
         #endregion
 
@@ -374,87 +389,91 @@ namespace AnywhereTS
         // Set a registry integer
         public static void SetRegValue(string regKey, string regValue, int value)
         {
-            Microsoft.Win32.RegistryKey objRegkey;
-
-            try
-            {
-                objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey,true);
-            }
-            catch (ArgumentNullException e)
+            using (log4net.NDC.Push(string.Format("key={0} name={1} data={2}", regKey, regValue, value)))
             {
-                MessageBox.Show("Error when writing to registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (62411)");
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                Logging.ATSAdminLog.DebugFormat(@"Setting value in Registry: {0}\{1}={2}", regKey, regValue, value);
+                Microsoft.Win32.RegistryKey objRegkey;
+
+                try
                 {
-                        using (log4net.NDC.Push("Installation info missing"))
-                        {
-                            Logging.ATSAdminLog.Error("Error when writing to registry.");
-                        }                    
+                    objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey, true);
                 }
-                Application.Exit();
-                return;
-            }
-            catch (SecurityException e)
-            {
-                MessageBox.Show("Error when writing to registry. You do not have the necessary permission (62412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                catch (ArgumentNullException e)
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    MessageBox.Show("Error when writing to registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (62411)");
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
-                        using (log4net.NDC.Push("Invalid user rights"))
+                        using (log4net.NDC.Push("Installation info missing"))
                         {
                             Logging.ATSAdminLog.Error("Error when writing to registry.");
                         }
                     }
+                    Application.Exit();
+                    return;
                 }
-                Application.Exit();
-                return;
-            }
-            catch (Exception e)
-            {
-                MessageBox.Show("Error when reading from registry (62413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                catch (SecurityException e)
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    MessageBox.Show("Error when writing to registry. You do not have the necessary permission (62412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");                        
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                        {
+                            using (log4net.NDC.Push("Invalid user rights"))
+                            {
+                                Logging.ATSAdminLog.Error("Error when writing to registry.");
+                            }
+                        }
                     }
-                }
-                Application.Exit();
-                return;
-            }
-
-            if (objRegkey != null)
-            {
-                try
-                {
-                    objRegkey.SetValue(regValue, value);
+                    Application.Exit();
+                    return;
                 }
                 catch (Exception e)
                 {
-                    MessageBox.Show("Error when writing to registry (62414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                    MessageBox.Show("Error when reading from registry (62413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
                     using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
                         using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                         {
-                                Logging.ATSAdminLog.Error("Error when writing to registry.");                            
+                            Logging.ATSAdminLog.Error("Error when reading from registry.");
                         }
                     }
                     Application.Exit();
+                    return;
                 }
-            }
-            else
-            {
-                MessageBox.Show("Error when writing to registry (65222). Key missing. Key: " + regKey + " Value: " + regValue);
-                
+
+                if (objRegkey != null)
+                {
+                    try
+                    {
+                        objRegkey.SetValue(regValue, value);
+                    }
+                    catch (Exception e)
+                    {
+                        MessageBox.Show("Error when writing to registry (62414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                        using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                        {
+                            using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                            {
+                                Logging.ATSAdminLog.Error("Error when writing to registry.");
+                            }
+                        }
+                        Application.Exit();
+                    }
+                }
+                else
+                {
+                    MessageBox.Show("Error when writing to registry (65222). Key missing. Key: " + regKey + " Value: " + regValue);
+
                     using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                     {
                         using (log4net.NDC.Push("Key is missing"))
                         {
                             Logging.ATSAdminLog.Error("Error when writing to registry.");
-                        }                        
+                        }
                     }
-                
-                Application.Exit();
+
+                    Application.Exit();
+                }
             }
         }
         #endregion
@@ -463,86 +482,90 @@ namespace AnywhereTS
         // Set a registry string
         public static void SetRegValue(string regKey, string regValue, string value)
         {
-            Microsoft.Win32.RegistryKey objRegkey;
-
-            try
-            {
-                objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey, true);
-            }
-            catch (ArgumentNullException e)
+            using (log4net.NDC.Push(string.Format("key={0} name={1} data={2}", regKey, regValue, value)))
             {
-                MessageBox.Show("Error when writing to registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (62411)");
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                Logging.ATSAdminLog.DebugFormat(@"Setting value in Registry: {0}\{1}={2}", regKey, regValue, value);
+                Microsoft.Win32.RegistryKey objRegkey;
+
+                try
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
-                    {
-                        Logging.ATSAdminLog.Error("Error when writing to registry.");
-                    }
+                    objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey, true);
                 }
-                Application.Exit();
-                return;
-            }
-            catch (SecurityException e)
-            {
-                MessageBox.Show("Error when writing to registry. You do not have the necessary permission (62412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                catch (ArgumentNullException e)
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    MessageBox.Show("Error when writing to registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (62411)");
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
-                        using (log4net.NDC.Push("Invalid user rights"))
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                         {
                             Logging.ATSAdminLog.Error("Error when writing to registry.");
                         }
                     }
+                    Application.Exit();
+                    return;
                 }
-                Application.Exit();
-                return;
-            }
-            catch (Exception e)
-            {
-                MessageBox.Show("Error when reading from registry (62413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
-                using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                catch (SecurityException e)
                 {
-                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                    MessageBox.Show("Error when writing to registry. You do not have the necessary permission (62412). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                    using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                    {
+                        using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                         {
-                            Logging.ATSAdminLog.Error("Error when reading from registry.");
-                        }                   
-                }
-                Application.Exit();
-                return;
-            }
-
-            if (objRegkey != null)
-            {
-                try
-                {
-                    objRegkey.SetValue(regValue, value);
+                            using (log4net.NDC.Push("Invalid user rights"))
+                            {
+                                Logging.ATSAdminLog.Error("Error when writing to registry.");
+                            }
+                        }
+                    }
+                    Application.Exit();
+                    return;
                 }
                 catch (Exception e)
                 {
-                    MessageBox.Show("Error when writing to registry (62414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                    MessageBox.Show("Error when reading from registry (62413). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
                     using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
                     {
                         using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                         {
-                                Logging.ATSAdminLog.Error("Error when writing to registry.");                           
+                            Logging.ATSAdminLog.Error("Error when reading from registry.");
                         }
                     }
                     Application.Exit();
+                    return;
                 }
-            }
-            else
-            {
-                MessageBox.Show("Error when writing to registry (65222). Key missing. Key: " + regKey + " Value: " + regValue);
-            using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+
+                if (objRegkey != null)
+                {
+                    try
+                    {
+                        objRegkey.SetValue(regValue, value);
+                    }
+                    catch (Exception e)
+                    {
+                        MessageBox.Show("Error when writing to registry (62414). Key: " + regKey + " Value: " + regValue + " Error details:" + e.Message);
+                        using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
+                        {
+                            using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
+                            {
+                                Logging.ATSAdminLog.Error("Error when writing to registry.");
+                            }
+                        }
+                        Application.Exit();
+                    }
+                }
+                else
+                {
+                    MessageBox.Show("Error when writing to registry (65222). Key missing. Key: " + regKey + " Value: " + regValue);
+                    using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue)))
                     {
                         using (log4net.NDC.Push("Key is missing"))
                         {
                             Logging.ATSAdminLog.Error("Error when writing to registry.");
                         }
                     }
-                
-                Application.Exit();
+
+                    Application.Exit();
+                }
             }
         }
         #endregion
@@ -749,7 +772,7 @@ namespace AnywhereTS
         {
             using (log4net.NDC.Push(string.Format("key={0} name={1} data={2}",regKey, regValue, value)))
             {
-                Logging.ATSAdminLog.InfoFormat(@"Creating value in Registry: {0}\{1}={2}", regKey, regValue, value);
+                Logging.ATSAdminLog.DebugFormat(@"Creating value in Registry: {0}\{1}={2}", regKey, regValue, value);
                 Microsoft.Win32.RegistryKey objRegkey;
 
                 try
@@ -821,7 +844,6 @@ namespace AnywhereTS
 
                     Application.Exit();
                 }
-                Logging.ATSAdminLog.InfoFormat(@"Created value in Registry: {0}\{1}={2}", regKey, regValue, value);
             }
         }
 #endregion
@@ -832,7 +854,7 @@ namespace AnywhereTS
         {
             using (log4net.NDC.Push(string.Format("key={0} name={1} data={2}", regKey, regValue, value)))
             {
-                Logging.ATSAdminLog.InfoFormat(@"Creating value in Registry: {0}\{1}={2}", regKey, regValue, value);
+                Logging.ATSAdminLog.DebugFormat(@"Creating value in Registry: {0}\{1}={2}", regKey, regValue, value);
                 Microsoft.Win32.RegistryKey objRegkey;
 
                 try
@@ -903,7 +925,6 @@ namespace AnywhereTS
 
                     Application.Exit();
                 }
-                Logging.ATSAdminLog.InfoFormat(@"Created value in Registry: {0}\{1}={2}", regKey, regValue, value);
             }
         }
         #endregion