using System; using System.Collections.Generic; using System.Text; using System.Reflection; // For path (assembly) using System.IO; // For Path using System.Security; // Security Exception using System.Windows.Forms; // Message Box using System.Text.RegularExpressions; // For validate MAC address namespace AnywhereTS { public static class ATSGlobals { // Version public const string strDatabaseVersion = "1.0.0.3"; // The version string for the ATS database //[SerializableAttribute] public struct Color; // Registry keys public static string strATSregRoot; // Registry root for AnywhereTS public static string strTFTPD32RegRoot; // Registry root for TFTPD32 public const string strRegDHCPconfig = "DHCP"; // DCHP config in registry public const string strRegTFTPconfig = "TFTP"; // TFTP root directory in registry public const string strRegTFTP_root = "TFTP_root"; // TFTP root directory in registry public const string strRegManagedMode = "ManagedMode"; // Reg key for managed mode. public const string strRegConfigured = "Configured"; // Reg key for indicating of ATS is configured. public const string strRegTerminalServer = "TerminalServer"; // Reg key for terinal server config. public const string strRegRunFirstTime = "RunFirstTime"; // Reg key for first time run. public const string strRegAdminVersion = "AdminVersion"; // Reg key for Admin version. Indicates that Admin app is intalled on this computer and the version of the admin app. // Help public static string helpFile; // The ATS help file // Directories static public string strTFTPdir; // The TFP root directory, including final "\" static public string strExecPath; // The directory for the application exe-file static public string strHelpFilePath; // The path (incl filname) to the application help file // Other global variables static public int managedMode; // 0=Not definied, 1=Managed, 2=Unmanged static public int configured; // 0=ATS not configured, 1=ATS is configured, 2=Configured for control panel only. static public int dhcpConfig; // 0=Use internal DHCP, 1=Other DHCP static public int tftpConfig; // 0=Use internal TFTP, 1=Other TFTP static public int terminalServerConfig; // 0=Terminal server on this computer, 1=No terminal server on this computer. static public int runFirstTime; // 1=The application (or new version of it) is newly installed and the first time run procedures should be run. 0=The application has already been run. static public bool isPro=true; // True = we are running the Pro version. Always true for the open source version. static public bool isEval=true; //True if evalversion of client Non pro feature static public string SelectedGraphicsAdaptersFile; // Name of the file for graphics adapters that corresponds to the users selection of linux kernel static public string SelectedNicAdaptersFile; // Name of the file for network adapters that corresponds to the users selection of linux kernel static public string SelectedSoundAdaptersFile; // Name of the file for sound adapters that corresponds to the users selection of linux kernel static public string ApplicationName; // The name of the application. Used everywhere except for in about box and main window bar. Can be either original or an OEM name. static public string ApplicationTitle = ApplicationName; // The title of the application, used for the main window bar and about box. //File names public const string GraphicsAdaptersA = "Graphics30.ats"; //The file containing the list of all graphics adapters public const string NicAdaptersA = "Nic30.ats"; // The file containing the list of all network adapters public const string SoundAdaptersA = "Sound30.ats"; // The file containing the list of all sound adapters // Client connect time options public static int[,] ScreenResolutions = new int[,] { { 640, 480 }, { 800, 600 }, { 1024, 600 }, { 1024, 768 }, { 1152, 864 }, { 1280, 768 }, { 1280, 800 }, { 1280, 960 }, { 1280, 1024 }, { 1368, 768 }, { 1400, 1050 }, { 1440, 900 }, { 1440, 1050 }, { 1600, 1000 }, { 1600, 1024 }, { 1600, 1200 }, { 1680, 1050 }, { 1792, 1344 }, { 1856, 1392 }, { 1920, 1080 }, { 1920, 1200 }, { 1920, 1440 } }; // Constructor static ATSGlobals() { ApplicationName = "Anywhere" + "TS"; // The name of the application. Used everywhere except for in about box and main window bar. Can be either original or an OEM name. // Set registry root // This is how we find the OS on run time // on 32 bit OS IntPtr.Size = 4 // on 64 bit OS IntPtr.Size = 8 if (IntPtr.Size == 8) { // 64 bit OS strATSregRoot = @"SOFTWARE\Wow6432Node\" + ATSGlobals.ApplicationName + @"\ts-config"; } else { // 32 bit OS strATSregRoot = @"SOFTWARE\" + ATSGlobals.ApplicationName + @"\ts-config"; } // Set registry root for TFTPD32 // This is how we find the OS on run time // on 32 bit OS IntPtr.Size = 4 // on 64 bit OS IntPtr.Size = 8 if (IntPtr.Size == 8) { // 64 bit OS strTFTPD32RegRoot = @"SOFTWARE\Wow6432Node\TFTPD32"; } else { // 32 bit OS strTFTPD32RegRoot = @"SOFTWARE\TFTPD32"; } helpFile = "AnywhereTS.chm"; // The ATS help file if (GetATSRegValueInt(strRegRunFirstTime) == 1) { // We are runnning this version for the first time, write the needed registry values CreateRegistryValues(); } strExecPath = Path.GetDirectoryName(Application.ExecutablePath); strHelpFilePath = strExecPath + @"\" + helpFile; // Get TFTP config tftpConfig = GetATSRegValueInt(strRegTFTPconfig); // Get TFTP root strTFTPdir = GetATSRegValueString(strRegTFTP_root); // Get DHCP config dhcpConfig = GetATSRegValueInt(strRegDHCPconfig); configured = GetATSRegValueInt(strRegConfigured); managedMode = GetATSRegValueInt(strRegManagedMode); runFirstTime = GetATSRegValueInt(strRegRunFirstTime); // Currently only the 3.0 version of the drivers are supported SelectedGraphicsAdaptersFile = GraphicsAdaptersA; SelectedNicAdaptersFile = NicAdaptersA; SelectedSoundAdaptersFile = SoundAdaptersA; } // Get a registry string public static string GetATSRegValueString(string regValue) { return GetRegValue(strATSregRoot, regValue); } // Get a registry integer from the application key public static int GetATSRegValueInt(string regValue) { return GetRegValueInt(strATSregRoot, regValue); } // Set a registry integer in the the application key public static void SetATSRegValue(string regValue, int value) { SetRegValue(strATSregRoot, regValue, value); } // Set a registry string in the the application key public static void SetATSRegValue(string regValue, string value) { SetRegValue(strATSregRoot, regValue, value); } // 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()))) { using (log4net.NDC.Push("Installation info missing.")) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } 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()))) { using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue))) { using (log4net.NDC.Push("Invalid users rights.")) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } } 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()))) { Logging.ATSAdminLog.Error("Error when reading from registry."); } Application.Exit(); return ""; } if (objRegkey != null) { if (objRegkey.GetValue(regValue) != null) { 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 ""; } } else { MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue); using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue))) { using (log4net.NDC.Push("Value 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 } // Get a registry integer public static int GetRegValueInt(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()))) { using (log4net.NDC.Push("Installation info missing.")) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } 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()))) { 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; } 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()))) { Logging.ATSAdminLog.Error("Error when reading from registry."); } Application.Exit(); return 0; } if (objRegkey != null) { if (objRegkey.GetValue(regValue) != null) { try { 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()))) { using (log4net.NDC.Push(string.Format("key={0} value={1}", regKey, regValue))) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } Application.Exit(); return 0; } } else { MessageBox.Show("Error when reading from registry (55222). Value missing. Key: " + regKey + " Value: " + regValue); 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("Value is missing")) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } } Application.Exit(); return 0; } } else { MessageBox.Show("Error when reading from registry (55221). Key missing. Key: " + regKey + " Value: " + regValue); 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("Key is missing")) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } } Application.Exit(); } return 0; // No value could be retrieved from registry } // 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) { 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("Installation info missing")) { Logging.ATSAdminLog.Error("Error when writing to registry."); } } 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()))) { 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; } 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()))) { 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); } 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(); } } // 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) { 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(string.Format("key={0} value={1}", regKey, regValue))) { Logging.ATSAdminLog.Error("Error when writing to registry."); } } 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()))) { 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; } 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()))) { 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); } 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("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("Key is missing")) { Logging.ATSAdminLog.Error("Error when writing to registry."); } } } Application.Exit(); } } // Check if a registry int value exists public static bool RegValueExists(string regKey, string regValue) { Microsoft.Win32.RegistryKey objRegkey; try { objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey); } catch (ArgumentNullException) { MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (29411)"); 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("Installation info missing")) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } } Application.Exit(); return false; } catch (SecurityException e) { MessageBox.Show("Error when reading from registry. You do not have the necessary permission (29412). 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 false; } catch (Exception e) { MessageBox.Show("Error when reading from registry (29413). 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 false; } if (objRegkey != null) { if (objRegkey.GetValue(regValue) != null) { return true; // We could retrive the value } else { return false; // No value found } } else { MessageBox.Show("Error when reading from registry (59221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root); 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("Key is missing")) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } } Application.Exit(); } return false; // No value could be retrieved from registry } // Validate MAC a MAC address. public static string IsValidMAC(string macAddress) { macAddress = macAddress.Replace(":", ""); macAddress = macAddress.ToUpper(); string result = ""; Regex rx = new Regex("([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])", RegexOptions.IgnoreCase); Match m = rx.Match(macAddress); result = m.Groups[0].Value; if (result.Length == 17) { return result; } else { rx = new Regex("([0-9a-fA-F][0-9a-fA-F]){5}([0-9a-fA-F][0-9a-fA-F])", RegexOptions.IgnoreCase); Match m2 = rx.Match(macAddress); result = m2.Groups[0].Value; if (result.Length == 12) { return result; } return result; } } // Try to extract a mac address from an ATS client name in the format 'ATSxxxxxxxxxxxx', where xxxxxxxxxx is a mac address. public static string GetMacFromATSname(string name) { string strMac; if (name.Length != 15) { return ""; // Not an ATS name } if (!name.StartsWith("ATS")) { return ""; // Not an ATS name } strMac = ATSGlobals.IsValidMAC(name.Substring(3)); if (strMac == "") { return ""; // Not an ATS name } // We have a MAC address return strMac; } // Create all needed registry values public static void CreateRegistryValues() { // Create registry values for ATS Admin Application CreateRegistryValue(strATSregRoot, "CheckUpdate", 1); CreateRegistryValue(strATSregRoot, strRegConfigured, 0); CreateRegistryValue(strATSregRoot, ProSupport.strRegDatabaseDir, ""); CreateRegistryValue(strATSregRoot, ProSupport.strRegDatabaseServer, ""); CreateRegistryValue(strATSregRoot, ProSupport.strRegDestDir, ""); CreateRegistryValue(strATSregRoot, strRegDHCPconfig , 0); CreateRegistryValue(strATSregRoot, strRegManagedMode, 1); CreateRegistryValue(strATSregRoot, strRegTerminalServer, 0); CreateRegistryValue(strATSregRoot, strRegTFTPconfig, 0); CreateRegistryValue(strATSregRoot, strRegTFTP_root,""); // Check if the admin app is intalled on this computer and if so, add reg values for TFTP 32 if (RegValueExists(strATSregRoot, strRegAdminVersion)) { // The admin app is installed, define keys for TFTP32. These should not be installed for the control panel. // Create registry values for TFTPD32 CreateRegistryValue(strTFTPD32RegRoot, "BaseDirectory", ""); CreateRegistryValue(strTFTPD32RegRoot, "Beep", 0); CreateRegistryValue(strTFTPD32RegRoot, "DirText", 0); CreateRegistryValue(strTFTPD32RegRoot, "Hide", 0); CreateRegistryValue(strTFTPD32RegRoot, "LastWindowPos", "60 49 860 642 "); CreateRegistryValue(strTFTPD32RegRoot, "LocalIP", ""); CreateRegistryValue(strTFTPD32RegRoot, "MaxRetransmit", 6); CreateRegistryValue(strTFTPD32RegRoot, "Negociate", 1); CreateRegistryValue(strTFTPD32RegRoot, "PXECompatibility", 0); CreateRegistryValue(strTFTPD32RegRoot, "SaveSyslogFile", ""); CreateRegistryValue(strTFTPD32RegRoot, "SecurityLevel", 1); CreateRegistryValue(strTFTPD32RegRoot, "Services", 2); CreateRegistryValue(strTFTPD32RegRoot, "ShowProgressBar", 0); CreateRegistryValue(strTFTPD32RegRoot, "TftpLogFile", ""); CreateRegistryValue(strTFTPD32RegRoot, "TftpPort", 69); CreateRegistryValue(strTFTPD32RegRoot, "Timeout", 3); CreateRegistryValue(strTFTPD32RegRoot, "UnixStrings", 1); CreateRegistryValue(strTFTPD32RegRoot, "VirtualRoot", 1); CreateRegistryValue(strTFTPD32RegRoot, "WinSize", 0); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionNumber1", 0); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionNumber2", 0); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionValue1", ""); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "AddOptionValue2", ""); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "BootFile", "client.zpxe"); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "DNS", 16834314); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "DomainName", ""); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "Gateway", 16834314); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "IP_Pool", 335601418); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "Mask", 65535); CreateRegistryValue(strTFTPD32RegRoot + @"\DHCP", "PoolSize", 200); } } // If a registry key does not exist, create it with the given default value public static void CreateRegistryValue(string regKey, string regValue, int value) { Microsoft.Win32.RegistryKey objRegkey; try { objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey); } catch (ArgumentNullException e) { MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)"); 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("Installation info missing")) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } } Application.Exit(); return; } catch (SecurityException e) { MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). 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; } catch (Exception e) { MessageBox.Show("Error when reading from registry (92413). 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) { if (objRegkey.GetValue(regValue) == null) { // No reg value, create one SetRegValue(regKey, regValue, value); } } else { MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root); 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(); } } // If a registry key does not exist, create it with the given default value public static void CreateRegistryValue(string regKey, string regValue, string value) { Microsoft.Win32.RegistryKey objRegkey; try { objRegkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regKey); } catch (ArgumentNullException e) { MessageBox.Show("Error when reading from registry. Installation info missing, please run the " + ATSGlobals.ApplicationName + " installation program. (92411)"); 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("Installation info missing")) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } } Application.Exit(); return; } catch (SecurityException e) { MessageBox.Show("Error when reading from registry. You do not have the necessary permission (92412). 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 users rights")) { Logging.ATSAdminLog.Error("Error when reading from registry."); } } } Application.Exit(); return; } catch (Exception e) { MessageBox.Show("Error when reading from registry (92413). 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) { if (objRegkey.GetValue(regValue) == null) { // No reg value, create one SetRegValue(regKey, regValue, value); } } else { MessageBox.Show("Error when reading from registry (95221). Key missing. Key: " + regKey + " Value: " + strRegTFTP_root); 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(); } } // Extract two integers from a string, separated by a character // Result: True = extraction ok, false = invalid string. // twointegers: String with two integers, separated by a character // separator: the character separating the strings // value1: (out) The first integer in the string // value2: (out) The second integer in the string public static bool ExtractIntegers(string twointegers, char separator, out int value1, out int value2) { string[] parts; value1 = 0; // Default value2 = 0; // Default parts = twointegers.Split(separator); if (parts.Length != 2) { return false; } // Convert and return value1 = Convert.ToInt32(parts[0]); // Default value2 = Convert.ToInt32(parts[1]); // Default return true; } } // Class ATSGlobals } // Namespace Anywhere TS