/// <summary>
        /// Getting Hardware Master information against IP address
        /// </summary>
        /// <param name="Tempaddr"></param>
        /// <returns></returns>
        public static string[] GetHwMasterInfo(System.Net.IPHostEntry Tempaddr)
        {
            string[] Ipaddr = new string[2];
            try
            {
                System.Net.IPAddress[] TempAd = Tempaddr.AddressList;
                foreach (IPAddress TempA in TempAd)
                {
                    Ipaddr[0] = TempA.ToString();

                    byte[] ab  = new byte[6];
                    int    len = ab.Length;

                    // This Function Used to Get The Physical Address
                    int    r   = SendARP((int)TempA.Address, 0, ab, ref len);
                    string mac = BitConverter.ToString(ab, 0, 6);

                    Ipaddr[1] = mac;
                }
            }
            catch (Exception ex)
            {
                WriteTextFile.WriteErrorLog("Hardware Master Information ERROR:");
                WriteTextFile.WriteErrorLog("==========================================");
                WriteTextFile.WriteErrorLog(ex);
            }
            return(Ipaddr);
        }
Esempio n. 2
0
        /// <summary>
        /// Fetch and Return Active Directory Printer information List against given Domain name
        /// </summary>
        /// <param name="domainName"></param>
        /// <returns></returns>
        public static List <DeviceInfo> PrintersInfoList(string domainName)
        {
            var deviceInfoList = new List <DeviceInfo>();

            try
            {
                using (var ds = new DirectorySearcher())
                {
                    ds.SearchRoot = new DirectoryEntry("LDAP://" + domainName);
                    ds.Filter     = "(|(&(objectCategory=printQueue)(name=*)))";

                    ds.PropertiesToLoad.Add("printername");
                    ds.PropertiesToLoad.Add("portname");
                    //ds.PropertiesToLoad.Add("servername");
                    //ds.PropertiesToLoad.Add("cn");
                    //ds.PropertiesToLoad.Add("name");
                    //ds.PropertiesToLoad.Add("printsharename");
                    ds.ReferralChasing = ReferralChasingOption.None;
                    ds.Sort            = new SortOption("name", SortDirection.Descending);

                    using (var src = ds.FindAll())
                    {
                        foreach (SearchResult sr in src)
                        {
                            var deviceInfo = new DeviceInfo();
                            deviceInfo.DevType     = "Devices";
                            deviceInfo.DevCategory = "Printer";
                            deviceInfo.ComType     = "Printer";
                            //WriteTextFile.WriteErrorLog(sr.GetDirectoryEntry().Name);
                            foreach (DictionaryEntry p in sr.Properties)
                            {
                                var propName       = p.Key;
                                var propCollection = (ResultPropertyValueCollection)p.Value;
                                var propValue      = propCollection.Count > 0 ? propCollection[0] : "";
                                if (propName.ToString() == "printername")
                                {
                                    deviceInfo.ComName = propValue.ToString();
                                }
                                else if (propName.ToString() == "portname")
                                {
                                    deviceInfo.IP = propValue.ToString();
                                }
                                //WriteTextFile.WriteErrorLog(propName.ToString());
                                //WriteTextFile.WriteErrorLog(propValue.ToString());
                            }
                            deviceInfoList.Add(deviceInfo);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteTextFile.WriteErrorLog("Printers Info List ERROR");
                WriteTextFile.WriteErrorLog("==========================================");
                WriteTextFile.WriteErrorLog(ex);
                deviceInfoList = null;
            }
            return(deviceInfoList);
        }
Esempio n. 3
0
        /// <summary>
        /// Fetch and Return Active Directory Users information List against given Domain name
        /// </summary>
        /// <param name="stringDomainName"></param>
        /// <returns></returns>
        public static List <DomainUsersInfo> FindUsersInformation(string stringDomainName, string username, string pass)
        {
            List <DomainUsersInfo> LstUsers = new List <DomainUsersInfo>();
            DomainUsersInfo        objDomainUsersInfo;

            if (string.IsNullOrWhiteSpace(stringDomainName))
            {
                stringDomainName = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
            }

            if (stringDomainName != null)
            {
                PrincipalContext PrincipalContext1 = new PrincipalContext(ContextType.Domain, stringDomainName, username, pass);
                WriteTextFile.WriteErrorLog("DomainName:" + stringDomainName);
                UserPrincipal     UserPrincipal1 = new UserPrincipal(PrincipalContext1);
                PrincipalSearcher searchUser     = new PrincipalSearcher(UserPrincipal1);

                foreach (UserPrincipal result in searchUser.FindAll())
                {
                    objDomainUsersInfo = new DomainUsersInfo();

                    //objDomainUsersInfo.SiteId = siteId;
                    //objDomainUsersInfo.ScheduleId = scheduleId;
                    objDomainUsersInfo.SamAccountName         = result.SamAccountName;
                    objDomainUsersInfo.DisplayName            = result.DisplayName;
                    objDomainUsersInfo.Name                   = result.Name;
                    objDomainUsersInfo.GivenName              = result.GivenName;
                    objDomainUsersInfo.Surname                = result.Surname;
                    objDomainUsersInfo.Description            = result.Description;
                    objDomainUsersInfo.Enabled                = result.Enabled;
                    objDomainUsersInfo.EmployeeId             = result.EmployeeId;
                    objDomainUsersInfo.LastPasswordSet        = result.LastPasswordSet;
                    objDomainUsersInfo.LastBadPasswordAttempt = result.LastBadPasswordAttempt;
                    objDomainUsersInfo.LastLogon              = result.LastLogon;

                    User User1 = new User(result.SamAccountName, result.DisplayName, result.Name, result.GivenName, result.Surname,
                                          result.Description, result.Enabled, result.EmployeeId, result.LastPasswordSet, result.LastBadPasswordAttempt, result.LastLogon);
                    Users1.Add(User1);

                    LstUsers.Add(objDomainUsersInfo);
                }
                searchUser.Dispose();
                //      ExporttoCSV();
            }
            else
            {
                //  File.WriteAllText(string.Format(System.Environment.CurrentDirectory + "\\Error.csv"), "This computer is not a member of domain");
            }
            return(LstUsers);
        }
Esempio n. 4
0
        /// <summary>
        /// Fetch and Return Active Directory Device information List against given Domain name
        /// </summary>
        /// <param name="domainName"></param>
        /// <returns></returns>
        public static List <DeviceInfo> DeviceInfoList(string domainName)
        {
            int DevicesCount = 0;
            DirectorySearcher mySearcher;
            var deviceInfoList = new List <DeviceInfo>();

            try
            {
                var entry = new DirectoryEntry("LDAP://" + domainName);

                // For Windows Servers
                mySearcher = new DirectorySearcher(entry)
                {
                    Filter = ("(objectClass=computer)")
                };
                foreach (SearchResult resEnt in mySearcher.FindAll())
                {
                    string cmpName               = resEnt.GetDirectoryEntry().Name.Substring(3);
                    string sFilter               = "(&(objectCategory=computer)(name=" + cmpName + "))";
                    var    directorySearch       = new DirectorySearcher(entry, sFilter);
                    var    directorySearchResult = directorySearch.FindOne();
                    var    deComp      = directorySearchResult.GetDirectoryEntry();
                    var    cmpOs       = deComp.Properties["operatingSystem"].Value.ToString();
                    string devType     = OSType.GetDeviceType(cmpOs);
                    string devCategory = OSType.GetCMPCategory(cmpOs);
                    string cmpType     = OSType.GetCMPType(cmpOs);
                    var    deviceInfo  = new DeviceInfo
                    {
                        DevType     = devType,
                        DevCategory = devCategory,
                        ComType     = cmpType,
                        ComName     = cmpName,
                        ComOS       = cmpOs
                    };
                    deviceInfoList.Add(deviceInfo);
                    DevicesCount++;
                    WriteTextFile.WriteErrorLog(DevicesCount + ") Machine Type: " + devType + " | " + "cat: " + devCategory + " | " + "CMP Type: " + cmpType + " | " + "CmpName: " + cmpName + " | Cmp OS:" + cmpOs);
                }
            }
            catch (Exception ex)
            {
                WriteTextFile.WriteErrorLog("Device Info List ERROR");
                WriteTextFile.WriteErrorLog("==========================================");
                WriteTextFile.WriteErrorLog(ex);
                deviceInfoList = null;
            }
            return(deviceInfoList);
        }
Esempio n. 5
0
        public static void ExpectSSH(string address, string login, string password)
        {
            try
            {
                SshClient sshClient = new SshClient(address, 22, login, password);

                sshClient.Connect();
                IDictionary <Renci.SshNet.Common.TerminalModes, uint> termkvp = new Dictionary <Renci.SshNet.Common.TerminalModes, uint>();
                termkvp.Add(Renci.SshNet.Common.TerminalModes.ECHO, 53);

                ShellStream shellStream = sshClient.CreateShellStream("xterm", 80, 24, 800, 600, 1024, termkvp);


                //Get logged in
                string rep = shellStream.Expect(new Regex(@"[$>]")); //expect user prompt
                WriteTextFile.WriteErrorLog(rep);

                //send command
                shellStream.WriteLine("sudo");
                rep = shellStream.Expect(new Regex(@"([$#>:])")); //expect password or user prompt
                WriteTextFile.WriteErrorLog(rep);

                //check to send password
                if (rep.Contains(":"))
                {
                    //send password
                    shellStream.WriteLine(password);
                    rep = shellStream.Expect(new Regex(@"[$#>]")); //expect user or root prompt
                    WriteTextFile.WriteErrorLog(rep);
                }

                sshClient.Disconnect();
            }//try to open connection
            catch (Exception ex)
            {
                WriteTextFile.WriteErrorLog(ex);
            }
        }
Esempio n. 6
0
        public static void ReadCsvFile(string filePath)
        {
            string        currentLine = string.Empty;
            List <string> columns     = new List <string>();

            try
            {
                if (filePath != "")
                {
                    DataTable newdt = new DataTable();
                    using (StreamReader sr = new StreamReader(filePath))
                    {
                        // currentLine will be null when the StreamReader reaches the end of file
                        int     linenumber = 1;
                        DataRow workRow    = null;
                        while ((currentLine = sr.ReadLine()) != null)
                        {
                            //Replace statement to remove special characters from current line.
                            currentLine = currentLine.Replace("\"\"\"", "\"");
                            currentLine = currentLine.Replace(",\"\"", ",\"");
                            currentLine = currentLine.Replace("\"\",", "\",");
                            if (currentLine[currentLine.Length - 1].ToString() == "\"")
                            {
                                currentLine = currentLine.Remove(currentLine.Length - 1);
                            }
                            //Regular expression...
                            Regex    CSVParser = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
                            String[] Fields    = CSVParser.Split(currentLine);
                            int      i         = 0;
                            workRow = newdt.NewRow();
                            foreach (var field in Fields)
                            {
                                if (linenumber == 1)
                                {
                                    newdt.Columns.Add(field, typeof(string));
                                    columns.Add(field);
                                }
                                else
                                {
                                    workRow[i] = CleanInput(field);
                                    i++;
                                }
                                // log.writelog(field.ToString());
                            }
                            newdt.Rows.Add(workRow);
                            linenumber++;
                        }
                        //  int count = 0;
                        foreach (DataRow row in newdt.Rows)
                        {
                            foreach (DataColumn dc in newdt.Columns)
                            {
                                WriteTextFile.WriteErrorLog(row[dc].ToString());
                            }
                        }
                    }
                }
                else
                {
                    string msg = "There is no file to upload. Click Browse CSV file button, select file and try again";
                    Console.WriteLine(msg);
                }
            }
            catch (Exception ex)
            {
                WriteTextFile.WriteErrorLog(ex);
            }
        }
        public static Hw_DetailInfoDTO getprinterDetail(string ip)
        {
            oHw_DetailInfoDTO = new Hw_DetailInfoDTO();

            string[] Ipaddr        = new string[7];;
            String   snmpAgent     = ip.ToString(); // printer IP
            String   snmpCommunity = "public";      //printer community
                                                    // int snmpPeerPort = 9100;

            SimpleSnmp snmp = new SimpleSnmp(snmpAgent, snmpCommunity);

            Dictionary <Oid, AsnType> ResultPrinterDetail = snmp.Get(SnmpVersion.Ver1, new string[] { "1.3.6.1.4.1.11.2.3.9.1.1.7.0" });
            Dictionary <Oid, AsnType> resultPrinterMode   = snmp.Get(SnmpVersion.Ver1, new string[] { "1.3.6.1.2.1.43.16.5.1.2.1.1" });
            Dictionary <Oid, AsnType> resultMAC           = snmp.Get(SnmpVersion.Ver1, new string[] { "1.3.6.1.1.1.1.22" });

            // System info
            Dictionary <Oid, AsnType> resultSystemInfo = snmp.Get(SnmpVersion.Ver1, new string[] { "1.3.6.1.2.1.1.5.0" });
            Dictionary <Oid, AsnType> resultSysDesc    = snmp.Get(SnmpVersion.Ver1, new string[] { "1.3.6.1.2.1.2.2.1.2.1" });


            // Serial No
            Dictionary <Oid, AsnType> resultSerialNo   = snmp.Get(SnmpVersion.Ver1, new string[] { "1.3.6.1.2.1.43.5.1.1.17.1" });
            Dictionary <Oid, AsnType> resultPhyAddress = snmp.Get(SnmpVersion.Ver1, new string[] { "1.3.6.1.2.1.2.2.1.6.1" });


            //  Dictionary<Oid, AsnType> result2 = snmp.Get(SnmpVersion.Ver2, new string[] { "1.3.6.1.4.1.11.2.3.9.1.1.7.0" });
            //  Dictionary<Oid, AsnType> result = snmp.Get(SnmpVersion.Ver2, "1.3.6.1.2.1.43.16.5.1.2.1.1");
            //  1.3.6.1.4.1.11.2.3.9.1
            if (resultPrinterMode == null)
            {
                return(null);
            }
            else
            {
                oHw_DetailInfoDTO.isConnected = true;

                List <string> printerInfo             = SNMP.GetName(ResultPrinterDetail, ip);
                List <string> PrinterMode             = SNMP.GetName(resultPrinterMode, ip);
                List <string> _resultSystemInfo       = SNMP.GetName(resultSystemInfo, ip);
                List <string> _resultSystemInfoSerial = SNMP.GetName(resultSerialNo, ip);

                Ipaddr[0] = printerInfo[0];
                //      oHw_DetailInfoDTO.HwCaption = printerInfo[0]; // Printer Name

                //   Ipaddr[1] = printerInfo[1];
                oHw_DetailInfoDTO.HwCaption = _resultSystemInfo[0]; // Domain Name
                oHw_DetailInfoDTO.HwCaption = "";

                oHw_DetailInfoDTO.HwDescription = PrinterMode[0];
                oHw_DetailInfoDTO.HwSerialNo    = _resultSystemInfoSerial[0];

                //    Ipaddr[2] = printerInfo[2]; // Printer MAC
                Ipaddr[3] = "Devices";
                Ipaddr[4] = "Printers";
                Ipaddr[5] = "  ";
                Ipaddr[6] = "  ";
                // items = new ListViewItem(Ipaddr);

                // System.Windows.Forms.ListViewItem TempItem = new ListViewItem(Ipaddr);

                // Found Printer Detail
                listPrintersInformation.Add("Printer IP: " + ip);
                WriteTextFile.WriteErrorLog("Printer IP: " + ip);

                listPrintersInformation.Add("Printer Name: " + printerInfo[0]);
                WriteTextFile.WriteErrorLog("Printer Name: " + printerInfo[0]);

                string[] data = SNMPPrinterInfo(snmp, ip.ToString());



                return(oHw_DetailInfoDTO);
                // return Ipaddr;
            }
            // return items;
            // return oHw_DetailInfoDTO;
            //return Ipaddr;
        }
        public static string[] SNMPPrinterInfo(SimpleSnmp snmp, string i)
        {
            string SerialNo = "";
            //Dictionary<Oid, AsnType> result = snmp.Get(SnmpVersion.Ver2, new string[] { "1.3.6.1.2.1.43.16.5.1.2.1.1" });
            // Printer Detail
            Dictionary <Oid, AsnType> result = snmp.Get(SnmpVersion.Ver1, new string[] { "1.3.6.1.4.1.11.2.3.9.1.1.7.0" });

            //Dictionary<Oid, AsnType> result2 = snmp.Get(SnmpVersion.Ver2, new string[] { "1.3.6.1.4.1.11.2.3.9.1" });
            if (result == null)
            {
            }
            else
            {
                string[] IpaddrDet = new string[20];
                int      c         = 0;
                foreach (KeyValuePair <Oid, AsnType> kvp in result)
                {
                    IpaddrDet[c] = string.Format("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
                    try
                    {
                        string[] outputWithEqual = IpaddrDet[c].Split('=');
                        string[] outputWithComma = outputWithEqual[2].Split(';');


                        //                    snmp Version 1
                        if (outputWithComma.Length > 7)
                        {
                            if (IpaddrDet[c].Contains("MFG"))
                            {
                                var MFG = outputWithComma[0];
                                oHw_DetailInfoDTO.HwManufacturer = MFG; // Add MFG info into HW_Detailinfo

                                listPrintersInformation.Add(MFG);
                                WriteTextFile.WriteErrorLog(MFG);
                            }
                            if (IpaddrDet[c].Contains("CMD"))
                            {
                                var CMD = outputWithComma[2];
                                oHw_DetailInfoDTO.ListOfAvailableLanguages = CMD; // Add CMD info into HW_Detailinfo

                                listPrintersInformation.Add(CMD);
                                WriteTextFile.WriteErrorLog(CMD);
                            }
                            //if (IpaddrDet[c].Contains("CLS"))
                            //{
                            //    var MFG = outputWithComma[2];
                            //}
                            //if (IpaddrDet[c].Contains("CMD"))
                            //{
                            //    var CMD = outputWithComma[2];
                            //    oHw_DetailInfoDTO.ListOfAvailableLanguages = CMD; // Add Desc info into HW_Detailinfo

                            //    listPrintersInformation.Add(CMD);
                            //    WriteTextFile.WriteErrorLog(CMD);
                            //}
                            if (IpaddrDet[c].Contains("MDL"))
                            {
                                var MDL = outputWithComma[1];
                                oHw_DetailInfoDTO.HwModelNo = MDL; // Add Model info into HW_Detailinfo
                                oHw_DetailInfoDTO.HwCaption = MDL; // Add Model info into HW_Detailinfo

                                listPrintersInformation.Add(MDL);
                                WriteTextFile.WriteErrorLog(MDL);
                            }
                            if (IpaddrDet[c].Contains("CLS"))
                            {
                                var data = outputWithComma[3];
                                oHw_DetailInfoDTO.HwDescription = data; // Add Class info into HW_Detailinfo

                                listPrintersInformation.Add(data);
                                WriteTextFile.WriteErrorLog(data);
                            }
                            if (IpaddrDet[c].Contains("DES"))
                            {
                                var data = outputWithComma[4];
                                oHw_DetailInfoDTO.HwDescription = data; // Add HwDescription info into HW_Detailinfo

                                listPrintersInformation.Add(data);
                                WriteTextFile.WriteErrorLog(data);
                            }

                            if (IpaddrDet[c].Contains("LEDMDIS"))
                            {
                                var data = outputWithComma[6];
                                oHw_DetailInfoDTO.HwDescription = data; // Add HwDescription info into HW_Detailinfo
                                SerialNo = data;
                                listPrintersInformation.Add(data);
                                WriteTextFile.WriteErrorLog(data);
                            }
                            if (IpaddrDet[c].Contains("SN"))
                            {
                                var data = outputWithComma[7];
                                oHw_DetailInfoDTO.HwSerialNo = data; // Add HwDescription info into HW_Detailinfo
                                SerialNo = data;
                                listPrintersInformation.Add(data);
                                WriteTextFile.WriteErrorLog(data);
                            }
                        }



                        //                    snmp Version 2
                        //if (outputWithComma.Length > 5)
                        //{
                        //    if (IpaddrDet[c].Contains("MFG"))
                        //    {
                        //        var MFG = outputWithComma[0];
                        //        oHw_DetailInfoDTO.HwManufacturer = MFG; // Add MFG info into HW_Detailinfo

                        //        listPrintersInformation.Add(MFG);
                        //        WriteTextFile.WriteErrorLog(MFG);
                        //    }
                        //    if (IpaddrDet[c].Contains("CMD"))
                        //    {
                        //        var CMD = outputWithComma[1];
                        //        oHw_DetailInfoDTO.ListOfAvailableLanguages = CMD; // Add CMD info into HW_Detailinfo

                        //        listPrintersInformation.Add(CMD);
                        //        WriteTextFile.WriteErrorLog(CMD);
                        //    }
                        //    //if (IpaddrDet[c].Contains("CLS"))
                        //    //{
                        //    //    var MFG = outputWithComma[2];
                        //    //}
                        //    //if (IpaddrDet[c].Contains("CMD"))
                        //    //{
                        //    //    var CMD = outputWithComma[2];
                        //    //    oHw_DetailInfoDTO.ListOfAvailableLanguages = CMD; // Add Desc info into HW_Detailinfo

                        //    //    listPrintersInformation.Add(CMD);
                        //    //    WriteTextFile.WriteErrorLog(CMD);
                        //    //}
                        //    if (IpaddrDet[c].Contains("MDL"))
                        //    {
                        //        var MDL = outputWithComma[3];
                        //        oHw_DetailInfoDTO.HwModelNo = MDL; // Add Model info into HW_Detailinfo
                        //        oHw_DetailInfoDTO.HwCaption = MDL; // Add Model info into HW_Detailinfo

                        //        listPrintersInformation.Add(MDL);
                        //        WriteTextFile.WriteErrorLog(MDL);
                        //    }
                        //    if (IpaddrDet[c].Contains("CLS"))
                        //    {
                        //        var data = outputWithComma[4];
                        //        oHw_DetailInfoDTO.HwDescription = data; // Add Class info into HW_Detailinfo

                        //        listPrintersInformation.Add(data);
                        //        WriteTextFile.WriteErrorLog(data);
                        //    }
                        //    if (IpaddrDet[c].Contains("DES"))
                        //    {
                        //        var data = outputWithComma[5];
                        //        oHw_DetailInfoDTO.HwDescription = data; // Add HwDescription info into HW_Detailinfo

                        //        listPrintersInformation.Add(data);
                        //        WriteTextFile.WriteErrorLog(data);
                        //    }
                        //}



                        //if (IpaddrDet[c].Contains("DES"))
                        //{
                        //    var MFG = outputWithComma[6];
                        //    IpaddrDet[c].Contains("DES");
                        //}

                        //string[] columns = IpaddrDet[c].Split(';');
                        //List<string> list = new List<string>();
                        //for (int ig = 0; ig < columns.Length; ig++)
                        //{
                        //    string[] data = columns[ig].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                        //    list.Add(data[1]); //this will add middle data
                        //}
                        //string newText = String.Join(",", list.ToArray());
                        //var outputWithCollon = outputWithComma[c].Split(':');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    c++;
                }
                List <string> printerInfo = SNMP.GetName(result, i);
                string[]      Ipaddr      = new string[7];
                Ipaddr[0] = printerInfo[0];
                //Ipaddr[1] = printerInfo[1];
                Ipaddr[1] = printerInfo[0];
                //Ipaddr[2] = printerInfo[2];
                Ipaddr[2] = printerInfo[0];
                Ipaddr[3] = "Printers";
                //Ipaddr[4] = printerInfo[2];
                Ipaddr[4] = printerInfo[0];
                Ipaddr[5] = "";
                Ipaddr[6] = "";
                return(Ipaddr);
            }
            return(null);
        }
        public static Hw_DetailInfoDTO ReadRemoteRegistryusingWmi(string machineName, string username, string pass)
        {
            // Network Discovery Info
            var LstHw_DetailInfoDTO            = new List <Hw_DetailInfoDTO>();
            Hw_DetailInfoDTO oHw_DetailInfoDTO = new Hw_DetailInfoDTO();
            var oHw_DetailInfoResponse         = new Hw_DetailInfoResponse();
            var oHw_DetailInfoRequest          = new Hw_DetailInfoRequest();

            #region  Connection

            var programs          = new List <string>();
            var connectionOptions = new ConnectionOptions
            {
                Username      = username,
                Password      = pass,
                Impersonation = ImpersonationLevel.Impersonate
            };
            var MachineName = machineName;

            var IsLocal = false;
            IsLocal = Utils.IsLocalIpAddress(MachineName);

            ManagementScope ms;
            if ((IsLocal == false) && !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(pass))
            {
                ms = new ManagementScope("\\\\" + MachineName + "\\root\\cimv2", connectionOptions);
            }
            else if (IsLocal == true && machineName == Environment.MachineName)
            {
                // Local Machine
                ms = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2");
            }
            else if (IsLocal == true)
            {
                ms = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2");
            }
            else
            {
                return(null);
            }

            bool      result = false;
            Ping      ping   = new Ping();
            PingReply pingReply;
            string    pingMsg = "";
            try
            {
                pingReply = ping.Send(MachineName, 1000);
                if (pingReply.Status == IPStatus.Success)
                {
                    result = true;
                }

                pingMsg = "IP Ping Status: " + pingReply.Status;
            }
            catch
            {
                result  = false;
                pingMsg = "You IP have Some issue";
            }


            try
            {
                if (result)
                {
                }
                else
                {
                    WriteTextFile.WriteErrorLog("Not Connected due to: Machine " + pingMsg);
                    oHw_DetailInfoDTO.isConnected   = false;
                    oHw_DetailInfoDTO.HwDescription = "Connection Exception: " + pingMsg;
                    return(oHw_DetailInfoDTO);
                }
                ms.Connect();
                WriteTextFile.WriteErrorLog("Connected Successfully");
                oHw_DetailInfoDTO.HwDescription = "Connection: Machine Connected Successfully";
                oHw_DetailInfoDTO.isConnected   = true;
            }
            catch (Exception ex)
            {
                WriteTextFile.WriteErrorLog("Not Connected due to: " + ex.Message + ex.StackTrace);
                oHw_DetailInfoDTO.isConnected   = false;
                oHw_DetailInfoDTO.HwDescription = "Connection Exception: " + ex.Message;
                return(oHw_DetailInfoDTO);
            }

            #endregion

            #region Fetching Operating System Information

            WriteTextFile.WriteErrorLog("====================Operating System Started=====================");
            var oq    = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
            var query = new ManagementObjectSearcher(ms, oq);
            try
            {
                var queryCollection = query.Get();
                foreach (var o in queryCollection)
                {
                    var    mo   = (ManagementObject)o;
                    string text = mo.GetText(TextFormat.Mof);
                    WriteTextFile.WriteErrorLog("Operating System: " + mo["Caption"]);
                    oHw_DetailInfoDTO.OS = mo["Caption"].ToString();

                    WriteTextFile.WriteErrorLog("Version: " + mo["Version"]);
                    oHw_DetailInfoDTO.BiosVersion = mo["Version"].ToString();

                    WriteTextFile.WriteErrorLog("BuildType: " + mo["BuildType"]);
                    WriteTextFile.WriteErrorLog("Manufacturer : " + mo["Manufacturer"]);

                    WriteTextFile.WriteErrorLog("Computer Name : " + mo["csname"]);
                    oHw_DetailInfoDTO.HwCaption = mo["csname"].ToString();

                    WriteTextFile.WriteErrorLog("Operating System Architecture : " + mo["OSArchitecture"]);
                    oHw_DetailInfoDTO.HwSystemType = mo["OSArchitecture"].ToString();

                    WriteTextFile.WriteErrorLog("InstallDate: " + mo["InstallDate"]);
                    WriteTextFile.WriteErrorLog("Windows Serial Number : " + mo["SerialNumber"]);
                    //oHw_DetailInfoDTO.BiosSerialNo = mo["SerialNumber"].ToString();

                    WriteTextFile.WriteErrorLog("Windows Directory : " + mo["WindowsDirectory"]);

                    WriteTextFile.WriteErrorLog("Status: " + mo["Status"]);
                    oHw_DetailInfoDTO.BiosVersion = mo["Version"].ToString();

                    WriteTextFile.WriteErrorLog("NumberOfUsers: " + mo["NumberOfUsers"]);
                    WriteTextFile.WriteErrorLog("RegisteredUser: "******"RegisteredUser"]);
                    WriteTextFile.WriteErrorLog("NumberOfLicensedUsers: " + mo["NumberOfLicensedUsers"]);
                    WriteTextFile.WriteErrorLog("NumberOfProcesses: " + mo["NumberOfProcesses"]);
                    WriteTextFile.WriteErrorLog("ServicePackMajorVersion: " + mo["ServicePackMajorVersion"]);
                    WriteTextFile.WriteErrorLog("ServicePackMinorVersion: " + mo["ServicePackMinorVersion"]);
                }
                WriteTextFile.WriteErrorLog("====================Operating System Ended=====================");

                #endregion



                #region objects Running software
                /// Running Softwares List
                ///  Dataabse column must be identity increment
                ///

                var LstHw_Sw_RunningDTO    = new List <Hw_Sw_RunningDTO>();
                var oHw_Sw_RunningResponse = new Hw_Sw_RunningResponse();
                var oHw_Sw_RunningRequest  = new Hw_Sw_RunningRequest();

                #endregion objects Running software

                #region Process List Information
                try
                {
                    WriteTextFile.WriteErrorLog("====================Process List Started=====================");
                    oq              = new ObjectQuery("SELECT * FROM Win32_Process");
                    query           = new ManagementObjectSearcher(ms, oq);
                    queryCollection = query.Get();
                    foreach (var o in queryCollection)
                    {
                        try
                        {
                            var mo = (ManagementObject)o;
                            //create child node for operating system

                            Console.WriteLine("Process Name: " + mo["Name"] +
                                              " | Caption: " + mo["Caption"] +
                                              " | Description: " + mo["Description"] +
                                              " | Priority: " + mo["Priority"] +
                                              " | PeakVirtualSize: " + mo["PeakVirtualSize"] +
                                              " | ProcessId: " + mo["ProcessId"] +
                                              " | ParentProcessId: " + mo["ParentProcessId"] +
                                              " | CreationDate: " + mo["CreationDate"] +
                                              " | ExecutablePath: " + mo["ExecutablePath"]);

                            WriteTextFile.WriteErrorLog("Process Name: " + mo["Caption"] +
                                                        " | Caption: " + mo["Caption"] +
                                                        " | Description: " + mo["Description"] +
                                                        " | Priority: " + mo["Priority"] +
                                                        " | PeakVirtualSize: " + mo["PeakVirtualSize"] +
                                                        " | ProcessId: " + mo["ProcessId"] +
                                                        " | ParentProcessId: " + mo["ParentProcessId"] +
                                                        " | CreationDate: " + mo["CreationDate"] +
                                                        " | ExecutablePath: " + mo["ExecutablePath"]);


                            var oHw_Sw_RunningDTO = new Hw_Sw_RunningDTO();
                            oHw_Sw_RunningDTO.HwMasterInfoId = oHw_DetailInfoDTO.HwMasterInfoId;

                            oHw_Sw_RunningDTO.SwName        = mo["Caption"].ToString();
                            oHw_Sw_RunningDTO.SwDescription = mo["Description"].ToString();
                            oHw_Sw_RunningDTO.LicenceNo     = mo["ProcessId"].ToString();
                            try
                            {
                                string dateString = mo["CreationDate"].ToString().Substring(0, 8); // Modified from MSDN
                                oHw_Sw_RunningDTO.InstalledDate = DateTime.ParseExact(dateString, "yyyyMMdd", null);
                                Console.WriteLine(oHw_Sw_RunningDTO.InstalledDate);
                            }
                            catch (Exception)
                            {
                            }
                            try
                            {
                                oHw_Sw_RunningDTO.PathName = mo["ExecutablePath"].ToString();
                            }
                            catch (Exception)
                            {
                            }
                            oHw_Sw_RunningDTO.LicenceNo = mo["ThreadCount"].ToString();
                            oHw_Sw_RunningDTO.SerialNo  = mo["ProcessId"].ToString();
                            oHw_Sw_RunningDTO.Status    = mo["Priority"].ToString();

                            LstHw_Sw_RunningDTO.Add(oHw_Sw_RunningDTO);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteTextFile.WriteErrorLog("---Process List Exception---\n" + ex.Message + ex.StackTrace);
                    // ignored
                }
                WriteTextFile.WriteErrorLog("====================Process List Ended=====================");
                oHw_DetailInfoDTO.LstHw_Sw_RunningDTO = LstHw_Sw_RunningDTO;

                #endregion

                #region Computer System


                WriteTextFile.WriteErrorLog("====================Computer System Started=====================");
                oq              = new ObjectQuery("SELECT * FROM Win32_ComputerSystem");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();
                foreach (var o in queryCollection)
                {
                    try
                    {
                        var    mo   = (ManagementObject)o;
                        string text = mo.GetText(TextFormat.Mof);
                        WriteTextFile.WriteErrorLog("Computer Manufacturer Name: " + mo["Manufacturer"]);
                        oHw_DetailInfoDTO.HwManufacturer = mo["Manufacturer"].ToString();
                        Console.WriteLine(oHw_DetailInfoDTO.HwManufacturer);

                        if (mo["Manufacturer"].ToString().ToUpper().Contains("VMWARE"))
                        {
                            oHw_DetailInfoDTO.IsVirtual        = true;
                            oHw_DetailInfoDTO.VmInstanceName   = mo["Manufacturer"].ToString();
                            oHw_DetailInfoDTO.VmInstanceStatus = mo["Manufacturer"].ToString();
                        }
                        else
                        {
                            oHw_DetailInfoDTO.IsServerRole = false;
                            oHw_DetailInfoDTO.IsVirtual    = false;
                        }


                        WriteTextFile.WriteErrorLog("Caption: " + mo["Caption"]);
                        oHw_DetailInfoDTO.HwCaption = mo["Caption"].ToString();

                        WriteTextFile.WriteErrorLog("Model: " + mo["Model"]);
                        oHw_DetailInfoDTO.HwModelNo = mo["Model"].ToString();

                        WriteTextFile.WriteErrorLog("Name: " + mo["Name"]);

                        WriteTextFile.WriteErrorLog("System Type: " + mo["SystemType"]);
                        oHw_DetailInfoDTO.HwSystemType = mo["SystemType"].ToString();

                        WriteTextFile.WriteErrorLog("System Type: " + mo["SystemType"]);

                        try
                        {
                            WriteTextFile.WriteErrorLog("Part Number (SystemSKUNumber): " + mo["SystemSKUNumber"]);
                            oHw_DetailInfoDTO.HwPartNo = mo["SystemSKUNumber"].ToString();
                        }
                        catch (Exception ex)
                        {
                            oHw_DetailInfoDTO.HwPartNo = ex.Message;
                            Console.WriteLine("PartNo(SystemSKUNumber) not found due to:" + ex.Message + ex.StackTrace);
                        }

                        WriteTextFile.WriteErrorLog("Number Of Processors: " + mo["NumberOfProcessors"]);
                        oHw_DetailInfoDTO.NoOfProcessors = int.Parse(mo["NumberOfProcessors"].ToString());

                        WriteTextFile.WriteErrorLog("Total Physical Memory: " + Utils.formatSize(Int64.Parse(mo["totalphysicalmemory"].ToString()), false));
                        WriteTextFile.WriteErrorLog("Part Of Domain: " + mo["PartOfDomain"]);

                        WriteTextFile.WriteErrorLog("DNSHostName: " + mo["DNSHostName"]);
                        oHw_DetailInfoDTO.DNSHostName = mo["DNSHostName"].ToString();

                        WriteTextFile.WriteErrorLog("Domain: " + mo["Domain"]);
                        oHw_DetailInfoDTO.DomainName = mo["Domain"].ToString();

                        WriteTextFile.WriteErrorLog("User Name: " + mo["UserName"]);
                        oHw_DetailInfoDTO.UserName = mo["UserName"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("====================Computer System info Exception=====================");
                        Console.WriteLine(ex.Message + ex.StackTrace);
                        Console.WriteLine("====================Computer System info Exception=====================");
                    }
                }
                WriteTextFile.WriteErrorLog("====================Computer System Ended=====================");
                #endregion

                #region System Base Board Information
                WriteTextFile.WriteErrorLog("====================System Base Board Started=====================");
                oq              = new ObjectQuery("SELECT * FROM Win32_Baseboard");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();
                foreach (var o in queryCollection)
                {
                    var    mo   = (ManagementObject)o;
                    string text = mo.GetText(TextFormat.Mof);
                    // WriteTextFile.WriteErrorLog(text);

                    WriteTextFile.WriteErrorLog("Caption: " + mo["Caption"]);
                    oHw_DetailInfoDTO.BiosName = mo["Caption"].ToString();

                    WriteTextFile.WriteErrorLog("SerialNumber: " + mo["SerialNumber"]);
                    oHw_DetailInfoDTO.HwSerialNo = mo["SerialNumber"].ToString();

                    WriteTextFile.WriteErrorLog("Description: " + mo["Description"]);
                    oHw_DetailInfoDTO.HwDescription = mo["Description"].ToString();

                    WriteTextFile.WriteErrorLog("Product: " + mo["Product"]);
                    WriteTextFile.WriteErrorLog("PoweredOn: " + mo["PoweredOn"]);
                    WriteTextFile.WriteErrorLog("Replaceable: " + mo["Replaceable"]);
                    try
                    {
                        WriteTextFile.WriteErrorLog("Version: " + mo["Version"]);
                        oHw_DetailInfoDTO.HwVersion = mo["Version"].ToString();
                    }
                    catch (Exception)
                    {
                    }

                    WriteTextFile.WriteErrorLog("Replaceable: " + mo["Replaceable"]);
                    WriteTextFile.WriteErrorLog("Status: " + mo["Status"]);
                    oHw_DetailInfoDTO.HwStatus = mo["Status"].ToString();



                    Console.WriteLine("Caption: " + mo["Caption"]);
                    Console.WriteLine("SerialNumber: " + mo["SerialNumber"]);
                    Console.WriteLine("Description: " + mo["Description"]);
                    Console.WriteLine("Product: " + mo["Product"]);
                    Console.WriteLine("PoweredOn: " + mo["PoweredOn"]);
                    Console.WriteLine("Replaceable: " + mo["Replaceable"]);
                    Console.WriteLine("Version: " + mo["Version"]);
                    Console.WriteLine("Replaceable: " + mo["Replaceable"]);
                    Console.WriteLine("Status: " + mo["Status"]);
                }
                WriteTextFile.WriteErrorLog("====================System Base Board Ended=====================");
                #endregion

                #region System Bios Information
                WriteTextFile.WriteErrorLog("====================System Bios Started=====================");
                oq              = new ObjectQuery("SELECT * FROM Win32_bios");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();
                foreach (var o in queryCollection)
                {
                    var    mo   = (ManagementObject)o;
                    string text = mo.GetText(TextFormat.Mof);
                    WriteTextFile.WriteErrorLog("BIOS: " + mo["Caption"]);
                    oHw_DetailInfoDTO.BiosName = mo["Caption"].ToString();

                    WriteTextFile.WriteErrorLog("Manufacturer: " + mo["Manufacturer"]);
                    WriteTextFile.WriteErrorLog("Bios Serial Number: " + mo["serialnumber"]);
                    oHw_DetailInfoDTO.BiosSerialNo = mo["serialnumber"].ToString();

                    WriteTextFile.WriteErrorLog("BIOS Version: " + mo["version"]);
                    oHw_DetailInfoDTO.BiosVersion = mo["version"].ToString();

                    WriteTextFile.WriteErrorLog("Release Date: " + mo["ReleaseDate"]);

                    try
                    {
                        WriteTextFile.WriteErrorLog("List Of Languages: " + (string[])mo["ListOfLanguages"]);
                        var langList = ((string[])mo["ListOfLanguages"]);
                        oHw_DetailInfoDTO.ListOfAvailableLanguages = string.Join(",", langList);
                    }
                    catch (Exception ex)
                    {
                        WriteTextFile.WriteErrorLog("Error 'Win32_bios': " + ex.Message + ex.StackTrace);
                        Console.WriteLine(ex.Message);
                    }
                }
                WriteTextFile.WriteErrorLog("====================System Bios Ended=====================");
                #endregion System Bios Information

                #region System Processor Information
                WriteTextFile.WriteErrorLog("====================System Processor Started=====================");
                oq              = new ObjectQuery("SELECT * FROM Win32_processor");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();
                foreach (var o in queryCollection)
                {
                    var    mo   = (ManagementObject)o;
                    string text = mo.GetText(TextFormat.Mof);
                    WriteTextFile.WriteErrorLog("Manufacturer: " + mo["Manufacturer"]);

                    WriteTextFile.WriteErrorLog("Processor Id: " + mo["ProcessorId"]);
                    WriteTextFile.WriteErrorLog("Processor Name: " + mo["Name"]);
                    WriteTextFile.WriteErrorLog("Computer Processor: " + mo["Caption"]);
                    oHw_DetailInfoDTO.Processor = mo["Caption"].ToString();

                    WriteTextFile.WriteErrorLog("Number Of Logical Processors: " + mo["NumberOfLogicalProcessors"]);
                    oHw_DetailInfoDTO.NoOfLogicalProcessors = int.Parse(mo["NumberOfLogicalProcessors"].ToString());

                    WriteTextFile.WriteErrorLog("Number Of Cores: " + mo["NumberOfCores"]);
                    WriteTextFile.WriteErrorLog("CPU Speed: " + Utils.formatSpeed(Int64.Parse(mo["MaxClockSpeed"].ToString())));
                    WriteTextFile.WriteErrorLog("L2 Cache Size: " + Utils.formatSize(Int64.Parse(mo["L2CacheSize"].ToString()), false));
                    WriteTextFile.WriteErrorLog("L3 Cache Size: " + Utils.formatSize(Int64.Parse(mo["L3CacheSize"].ToString()), false));
                }
                WriteTextFile.WriteErrorLog("====================System Processor Ended=====================");
                #endregion System Processor Information

                #region System Time Zone Information
                WriteTextFile.WriteErrorLog("====================System Time Zone Started=====================");
                oq              = new ObjectQuery("SELECT * FROM Win32_timezone");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();
                foreach (var o in queryCollection)
                {
                    var    mo   = (ManagementObject)o;
                    string text = mo.GetText(TextFormat.Mof);
                    WriteTextFile.WriteErrorLog("Time Zone: " + mo["Caption"]);
                    oHw_DetailInfoDTO.CurrentTimeZone = mo["Caption"].ToString();
                }
                WriteTextFile.WriteErrorLog("====================System Time Zone Ended=====================");
                #endregion System Time Zone Information

                #region Memory Information
                //Get memory configuration
                oq              = new ObjectQuery("SELECT * FROM Win32_LogicalMemoryConfiguration");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();

                WriteTextFile.WriteErrorLog("====================Logical Memory Configuration=====================");



                WriteTextFile.WriteErrorLog("====================Physical Ram Configuration Start=====================");
                /// <summary>
                /// Retrieving Physical Ram Memory.
                /// </summary>
                /// <returns></returns>
                oq              = new ObjectQuery("SELECT Capacity FROM Win32_PhysicalMemory");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();
                long MemSize = 0;
                long mCap    = 0;
                // In case more than one Memory sticks are installed
                foreach (ManagementObject obj in queryCollection)
                {
                    mCap     = Convert.ToInt64(obj["Capacity"]);
                    MemSize += mCap;
                    WriteTextFile.WriteErrorLog("Mem Size: " + MemSize);
                }
                MemSize = (MemSize / 1024) / 1024;
                string memSize = MemSize.ToString() + "MB";
                WriteTextFile.WriteErrorLog("Total Size: " + memSize);
                oHw_DetailInfoDTO.PhysicalMemory = memSize.ToString();


                WriteTextFile.WriteErrorLog("====================Physical Ram Configuration End=====================");

                #endregion Memory Information

                #region Network Connection Information



                WriteTextFile.WriteErrorLog("====================Network Connection Started=====================");
                oq              = new ObjectQuery("SELECT * FROM Win32_NetworkConnection");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();
                foreach (var o in queryCollection)
                {
                    var    mo   = (ManagementObject)o;
                    string text = mo.GetText(TextFormat.Mof);
                    WriteTextFile.WriteErrorLog("Name: " + mo["Name"]);
                }
                WriteTextFile.WriteErrorLog("====================Network Connection Ended=====================");
                #endregion Network Connection Information

                #region Win32 Network Adapter Configuration
                WriteTextFile.WriteErrorLog("====================Win32_NetworkAdapterConfiguration System Started=====================");
                try
                {
                    ManagementClass            mc  = new ManagementClass("Win32_NetworkAdapterConfiguration");
                    ManagementObjectCollection moc = mc.GetInstances();
                    string MACAddress = String.Empty;

                    //// Installed Software's List
                    var LstHw_IpMacAddressDTO    = new List <Hw_IpMacAddressDTO>();
                    var oHw_IpMacAddressResponse = new Hw_DetailInfoResponse();
                    var oHw_IpMacAddressRequest  = new Hw_IpMacAddressRequest();
                    Hw_IpMacAddressDTO oHw_IpMacAddressDTO;
                    try
                    {
                        foreach (ManagementObject mo in moc)
                        {
                            oHw_IpMacAddressDTO = new Hw_IpMacAddressDTO();
                            oHw_IpMacAddressDTO.HwMasterInfoId = oHw_DetailInfoDTO.HwMasterInfoId;


                            string text = mo.GetText(TextFormat.Mof);
                            Console.WriteLine(text);
                            oHw_IpMacAddressDTO.IPEnabled = "false";
                            if (MACAddress == String.Empty)
                            {
                                if ((bool)mo["IPEnabled"] == true)
                                {
                                    MACAddress = mo["MacAddress"].ToString();
                                }
                            }
                            // string ipAddress;
                            try
                            {
                                if ((bool)mo["IPEnabled"] == true)
                                {
                                    string[] addresses = (string[])mo["IPAddress"];
                                    Console.WriteLine(addresses[0]);
                                    oHw_IpMacAddressDTO.IpAddress = addresses[0];
                                    oHw_IpMacAddressDTO.IPEnabled = ((bool)mo["IPEnabled"]).ToString();

                                    Console.WriteLine(mo["IPAddress"]);
                                }
                                oHw_IpMacAddressDTO.Caption    = mo["Description"].ToString();
                                oHw_IpMacAddressDTO.MacAddress = mo["MacAddress"].ToString();
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Exception Message in 'Network Cards Info': " + ex.Message + ex.StackTrace);
                            }
                            mo.Dispose();
                            if (!string.IsNullOrEmpty(oHw_IpMacAddressDTO.MacAddress))
                            {
                                LstHw_IpMacAddressDTO.Add(oHw_IpMacAddressDTO);
                            }
                        }
                        if (LstHw_IpMacAddressDTO.Count > 0)
                        {
                            oHw_DetailInfoDTO.LstHw_IpMacAddressDTO = LstHw_IpMacAddressDTO;
                        }
                    }
                    catch (Exception)
                    {
                        if (LstHw_IpMacAddressDTO.Count > 0)
                        {
                            oHw_DetailInfoDTO.LstHw_IpMacAddressDTO = LstHw_IpMacAddressDTO;
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteTextFile.WriteErrorLog("====================Win32_NetworkAdapterConfiguration System Exception: " + ex.Message + "=====================" + ex.StackTrace);
                }
                WriteTextFile.WriteErrorLog("====================Win32_NetworkAdapterConfiguration System Ended=====================");
                #endregion Win32 Network Adapter Configuration

                #region Network Card Information

                WriteTextFile.WriteErrorLog("====================Network Cards Info Started=====================");
                oq              = new ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();
                string MACAdd = String.Empty;
                foreach (var o in queryCollection)
                {
                    var    mo   = (ManagementObject)o;
                    string text = mo.GetText(TextFormat.Mof);
                    if (MACAdd == String.Empty)
                    {
                        string[] ipFull;
                        string   ipAddress;
                        try
                        {
                            ipFull    = mo["IPAddress"].ToString().Split(',');
                            ipAddress = ipFull[0].ToString();
                            Console.WriteLine(mo["IPAddress"].ToString());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Exception Message in 'Network Cards Info': " + ex.Message + ex.StackTrace);
                        }
                    }
                }
                WriteTextFile.WriteErrorLog("====================Network Cards Info Ended=====================");

                #endregion Network Card Information

                #region Video Controller Information

                WriteTextFile.WriteErrorLog("====================Video Controller Started=====================");
                oq              = new ObjectQuery("SELECT * FROM Win32_VideoController");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();
                foreach (var o in queryCollection)
                {
                    try
                    {
                        var    mo   = (ManagementObject)o;
                        string text = mo.GetText(TextFormat.Mof);
                        WriteTextFile.WriteErrorLog("Name: " + mo["Name"]);
                        WriteTextFile.WriteErrorLog("Processor: " + mo["VideoProcessor"]);
                        WriteTextFile.WriteErrorLog("Mode: " + mo["VideoModeDescription"]);
                        oHw_DetailInfoDTO.BiosDisplayConfiguration = mo["VideoModeDescription"].ToString();

                        if (mo["AdapterRAM"] == null)
                        {
                            WriteTextFile.WriteErrorLog("Video Ram: " + mo["AdapterRAM"]);
                        }
                        else
                        {
                            WriteTextFile.WriteErrorLog("Video Ram: " + Utils.formatSize(Int64.Parse(mo["AdapterRAM"].ToString()), false));
                        }
                        WriteTextFile.WriteErrorLog("PNP Device ID: " + mo["PNPDeviceID"]);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine("Exception Message in 'Video Controller Cards Info': " + ex.Message + ex.StackTrace);
                    }
                }
                WriteTextFile.WriteErrorLog("====================Video Controller Ended=====================");
                #endregion Video Controller Information

                #region Netwrok IIS Web Information

                try
                {
                    // SELECT* FROM IIsWebInfo
                    WriteTextFile.WriteErrorLog("====================Network IIsWebInfo Started=====================");
                    oq              = new ObjectQuery("SELECT * FROM IIsWebInfo");
                    query           = new ManagementObjectSearcher(ms, oq);
                    queryCollection = query.Get();
                    foreach (var o in queryCollection)
                    {
                        var    mo   = (ManagementObject)o;
                        string text = mo.GetText(TextFormat.Mof);
                        WriteTextFile.WriteErrorLog(text);
                    }
                    WriteTextFile.WriteErrorLog("====================Network IIsWebInfo Ended=====================");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                try
                {
                    WriteTextFile.WriteErrorLog("====================Network IIsWebService Started=====================");
                    oq              = new ObjectQuery("SELECT * FROM IIsWebService");
                    query           = new ManagementObjectSearcher(ms, oq);
                    queryCollection = query.Get();
                    foreach (var o in queryCollection)
                    {
                        var    mo   = (ManagementObject)o;
                        string text = mo.GetText(TextFormat.Mof);
                        WriteTextFile.WriteErrorLog(text);
                    }
                    WriteTextFile.WriteErrorLog("====================Network IIsWebService Ended=====================");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                #endregion Netwrok IIS Web Information

                #region Network IIS Smtp Service
                try
                {
                    WriteTextFile.WriteErrorLog("====================Network IIsSmtpService Started=====================");
                    oq              = new ObjectQuery("SELECT * FROM IIsSmtpService");
                    query           = new ManagementObjectSearcher(ms, oq);
                    queryCollection = query.Get();
                    foreach (var o in queryCollection)
                    {
                        var    mo   = (ManagementObject)o;
                        string text = mo.GetText(TextFormat.Mof);
                        WriteTextFile.WriteErrorLog(text);
                    }
                    WriteTextFile.WriteErrorLog("====================Network IIsSmtpService Ended=====================");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                #endregion Network IIS Smtp Service

                #region Network IIS Pop3 Service
                try
                { //  SELECT* FROM IIsPop3Service
                    WriteTextFile.WriteErrorLog("====================Network IIsPop3Service Started=====================");
                    oq              = new ObjectQuery("SELECT * FROM IIsPop3Service");
                    query           = new ManagementObjectSearcher(ms, oq);
                    queryCollection = query.Get();
                    foreach (var o in queryCollection)
                    {
                        var    mo   = (ManagementObject)o;
                        string text = mo.GetText(TextFormat.Mof);
                        WriteTextFile.WriteErrorLog(text);
                    }
                    WriteTextFile.WriteErrorLog("====================Network IIsPop3Service Ended=====================");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                #endregion Network IIS Pop3 Service

                #region Installed Software and services List

                //// Services List
                //// Installed Software's List
                var LstHw_Sw_ServicesDTO    = new List <Hw_Sw_ServicesDTO>();
                var oHw_Sw_ServicesResponse = new Hw_Sw_ServicesResponse();
                var oHw_Sw_ServicesRequest  = new Hw_Sw_ServicesRequest();

                WriteTextFile.WriteErrorLog("====================Services List Started=====================");
                string[] lvData = new string[12];
                try
                {
                    oq              = new ObjectQuery("SELECT * FROM Win32_Service");
                    query           = new ManagementObjectSearcher(ms, oq);
                    queryCollection = query.Get();
                    foreach (var o in queryCollection)
                    {
                        try
                        {
                            var mo = (ManagementObject)o;
                            //create child node for operating system

                            var oHw_Sw_ServicesDTO = new Hw_Sw_ServicesDTO();
                            oHw_Sw_ServicesDTO.HwMasterInfoId = oHw_DetailInfoDTO.HwMasterInfoId;

                            lvData[0] = mo["Name"].ToString();
                            oHw_Sw_ServicesDTO.Caption = mo["Name"].ToString();
                            //lvData[1] = mo["Caption"].ToString();
                            lvData[2] = mo["DisplayName"].ToString();
                            oHw_Sw_ServicesDTO.DisplayName = mo["DisplayName"].ToString();

                            lvData[3] = mo["Description"].ToString();
                            oHw_Sw_ServicesDTO.Description = mo["Description"].ToString();

                            //lvData[4] = mo["PathName"].ToString();
                            lvData[5] = mo["ServiceType"].ToString();
                            oHw_Sw_ServicesDTO.ServiceType = mo["ServiceType"].ToString();

                            lvData[6] = mo["StartMode"].ToString();
                            oHw_Sw_ServicesDTO.StartMode = mo["StartMode"].ToString();

                            if (mo["Started"].Equals(true))
                            {
                                lvData[7] = "Started";
                            }
                            else
                            {
                                lvData[7] = "Stop";
                            }
                            oHw_Sw_ServicesDTO.Started = mo["Started"].Equals(true);

                            lvData[8] = mo["StartName"].ToString();
                            oHw_Sw_ServicesDTO.StartName = mo["StartName"].ToString();

                            lvData[9] = mo["State"].ToString();
                            oHw_Sw_ServicesDTO.State = mo["State"].ToString();

                            lvData[10] = mo["Status"].ToString();
                            oHw_Sw_ServicesDTO.Status = mo["Status"].ToString();

                            WriteTextFile.WriteErrorLog(string.Join("','", lvData));

                            LstHw_Sw_ServicesDTO.Add(oHw_Sw_ServicesDTO);
                        }
                        catch (Exception ex)
                        {
                            WriteTextFile.WriteErrorLog(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    oHw_DetailInfoDTO.LstHw_Sw_ServicesDTO = LstHw_Sw_ServicesDTO;

                    // ignored
                }
                oHw_DetailInfoDTO.LstHw_Sw_ServicesDTO = LstHw_Sw_ServicesDTO;
                WriteTextFile.WriteErrorLog("====================Services List Ended=====================");



                //// Installed Software's List
                var LstHw_Sw_InstalledDTO    = new List <Hw_Sw_InstalledDTO>();
                var oHw_Sw_InstalledResponse = new Hw_Sw_InstalledResponse();
                var oHw_Sw_InstalledRequest  = new Hw_Sw_InstalledRequest();

                WriteTextFile.WriteErrorLog("====================Installed Softwares List Started=====================");
                int count = 0;

                WriteTextFile.WriteErrorLog(MachineName + " Installed Softwares List From Win32_Product as:-");
                oq              = new ObjectQuery("SELECT * FROM Win32_Product");
                query           = new ManagementObjectSearcher(ms, oq);
                queryCollection = query.Get();
                foreach (var o in queryCollection)
                {
                    try
                    {
                        var mo = (ManagementObject)o;
                        count++;
                        WriteTextFile.WriteErrorLog("Software No: " + count + "  |  " + mo["Name"] + " | " + mo["InstallDate"].ToString() + " | " + mo["Vendor"].ToString() + " | " + mo["Version"].ToString());

                        Hw_Sw_InstalledDTO oHw_Sw_InstalledDTO = new Hw_Sw_InstalledDTO();
                        oHw_Sw_InstalledDTO.HwMasterInfoId = oHw_DetailInfoDTO.HwMasterInfoId;

                        oHw_Sw_InstalledDTO.SwName = mo["Name"].ToString();

                        //  Console.WriteLine(mo["InstallDate"].ToString());

                        string dateString = mo["InstallDate"].ToString(); // Modified from MSDN
                        try
                        {
                            oHw_Sw_InstalledDTO.InstalledDate = DateTime.ParseExact(dateString, "yyyyMMdd", null);

                            Console.WriteLine(oHw_Sw_InstalledDTO.InstalledDate);
                        }
                        catch (Exception)
                        {
                        }

                        oHw_Sw_InstalledDTO.CopyRight     = mo["Vendor"].ToString();
                        oHw_Sw_InstalledDTO.SwDescription = mo["Vendor"].ToString();
                        oHw_Sw_InstalledDTO.SwVersion     = mo["Version"].ToString();

                        LstHw_Sw_InstalledDTO.Add(oHw_Sw_InstalledDTO);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        WriteTextFile.WriteErrorLog("Exception Message From Installesd Softwares List: " + ex.Message);
                        WriteTextFile.WriteErrorLog("====================Installed Softwares List End=====================");
                    }
                }
                oHw_DetailInfoDTO.LstHw_Sw_InstalledDTO = LstHw_Sw_InstalledDTO;



                ///////////////////////////////// Softwares list Compression

                count = 0;
                try
                {
                    WriteTextFile.WriteErrorLog(MachineName + " Installed Softwares List From Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall as:-");

                    string softwareRegLoc = @"Software\Microsoft\Windows\CurrentVersion\Uninstall";

                    ManagementClass      registry = new ManagementClass(ms, new ManagementPath("StdRegProv"), null);
                    ManagementBaseObject inParams = registry.GetMethodParameters("EnumKey");
                    inParams["hDefKey"]     = 0x80000002; //HKEY_LOCAL_MACHINE
                    inParams["sSubKeyName"] = softwareRegLoc;

                    // Read Registry Key Names
                    ManagementBaseObject outParams    = registry.InvokeMethod("EnumKey", inParams, null);
                    string[]             programGuids = outParams["sNames"] as string[];

                    foreach (string subKeyName in programGuids)
                    {
                        inParams                = registry.GetMethodParameters("GetStringValue");
                        inParams["hDefKey"]     = 0x80000002;//HKEY_LOCAL_MACHINE
                        inParams["sSubKeyName"] = softwareRegLoc + @"\" + subKeyName;
                        inParams["sValueName"]  = "DisplayName";
                        // Read Registry Value
                        outParams = registry.InvokeMethod("GetStringValue", inParams, null);

                        if (outParams.Properties["sValue"].Value != null)
                        {
                            string softwareName = outParams.Properties["sValue"].Value.ToString();
                            programs.Add(softwareName);
                        }
                    }
                    //// share folder path
                    programs.Sort();
                    foreach (string softname in programs)
                    {
                        count++;
                        WriteTextFile.WriteErrorLog("Software No: " + count + "  |  " + softname);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    WriteTextFile.WriteErrorLog("Exception Message From Installesd Softwares List: " + ex.Message);
                    WriteTextFile.WriteErrorLog("====================Installed Softwares List End=====================");
                }
                WriteTextFile.WriteErrorLog("====================Installed Softwares List Ended=====================");

                return(oHw_DetailInfoDTO);
            }
            catch (Exception ex)
            {
                WriteTextFile.WriteErrorLog("Hardware Detailed Information Outer ERROR");
                WriteTextFile.WriteErrorLog("==========================================");
                WriteTextFile.WriteErrorLog(ex);

                return(oHw_DetailInfoDTO);
            }
            #endregion Installed Software and services List
        }