private static void AddComputerSystem(Computer computer, ROOT.CIMV2.Win32.ComputerSystem wmiComputerSystem)
        {
            // Set computer name
            computer.Name = wmiComputerSystem.Name;

            computer.System.LoggedOnUser = wmiComputerSystem.UserName;
            computer.System.Manufacturer = wmiComputerSystem.Manufacturer;
            computer.System.Model = wmiComputerSystem.Model;
            computer.System.Domain = wmiComputerSystem.Domain;
            computer.System.TotalMemory = wmiComputerSystem.TotalPhysicalMemory;
        }
        private static void AddLogicalDisk(Computer computer, ROOT.CIMV2.Win32.LogicalDisk wmiLogicalDisk)
        {
            LogicalDisk logicalDisk = new LogicalDisk();

            logicalDisk.Description = wmiLogicalDisk.Description;
            logicalDisk.Name = wmiLogicalDisk.Name;
            logicalDisk.ShareName = wmiLogicalDisk.ProviderName;
            logicalDisk.Type = wmiLogicalDisk.DriveType.ToString();
            logicalDisk.FileSystem = wmiLogicalDisk.FileSystem;
            logicalDisk.FreeSpace = wmiLogicalDisk.FreeSpace;
            logicalDisk.Size = wmiLogicalDisk.Size;

            computer.LogicalDisks.Add(logicalDisk);
        }
        /// <summary>
        /// Adds a Computer object to the specified TreeView.
        /// </summary>
        /// <param name="treeView">TreeView to add Computer to</param>
        /// <param name="computer">Computer added as a node to the TreeView</param>
        public static void AddComputerToView(TreeView treeView, Computer computer)
        {
            TreeNode computerNode = new TreeNode(computer.Name);

            AddOperatingSystemNode(computerNode, computer.OperatingSystem);
            AddPrintersNode(computerNode, computer.Printers);
            AddProcessesNode(computerNode, computer.Processes);
            AddSharesNode(computerNode, computer.Shares);
            AddLogicalDisksNode(computerNode, computer.LogicalDisks);
            AddComputerSystemNode(computerNode, computer.System);
            AddProcessorsNode(computerNode, computer.Processors);
            AddNetworkAdaptersNode(computerNode, computer.NetworkAdapters);

            // Add computer node and its related nodes to this tree view control
            treeView.BeginUpdate();
            treeView.Nodes.Add(computerNode);
            treeView.EndUpdate();
        }
Example #4
0
        /// <summary>
        /// Stores a computer object to the database.
        /// </summary>
        /// <param name="computerCollection"></param>
        public void PersistComputer(Computer computer)
        {
            //Get the ID of the computer if it already exists
            int ComputerID = GetComputerIDByName(computer.Name);

            if (ComputerID == 0)
                //Add new computer to DB and obtain its new ID
                ComputerID = PersistComputerName(computer.Name);

            //Update computer in DB
            PersistShares(computer, ComputerID);
            PersistPrinters(computer, ComputerID);
            PersistOperatingSystem(computer, ComputerID);
            PersistLogicalDisks(computer, ComputerID);
            PersistSystem(computer, ComputerID);
            PersistProcesses(computer, ComputerID);
            PersistProcessors(computer, ComputerID);
            PersistNetworkAdapters(computer, ComputerID);
        }
Example #5
0
        public void PersistSystem(Computer computer, int computerID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            connection.Open();

            cmd.CommandText = "DeleteSystemByID";
            cmd.Parameters.Add("@ComputerID", computerID);
            cmd.ExecuteNonQuery();

            //Store System in DB
            cmd.CommandText = "AddSystem";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@ComputerID", computerID);
            cmd.Parameters.Add("@Domain", computer.System.Domain + "");
            cmd.Parameters.Add("@LoggedOnUser", computer.System.LoggedOnUser + "");
            cmd.Parameters.Add("@Manufacturer", computer.System.Manufacturer + "");
            cmd.Parameters.Add("@Model", computer.System.Model + "");
            cmd.Parameters.Add("@TotalMemory", (long)computer.System.TotalMemory);

            cmd.ExecuteNonQuery();

            connection.Close();
        }
        private static void AddNetworkAdapter(Computer computer, ROOT.CIMV2.Win32.NetworkAdapterConfiguration wmiNetworkAdapter)
        {
            NetworkAdapter networkAdapter = new NetworkAdapter();
            networkAdapter.Model = wmiNetworkAdapter.Description;
            networkAdapter.DnsDomain = wmiNetworkAdapter.DNSDomain;
            networkAdapter.DnsHostName = wmiNetworkAdapter.DNSHostName;
            networkAdapter.MacAddress = wmiNetworkAdapter.MACAddress;
            networkAdapter.DhcpEnabled = wmiNetworkAdapter.DHCPEnabled;
            networkAdapter.DhcpLeaseExpirationDate = wmiNetworkAdapter.DHCPLeaseExpires;
            networkAdapter.DhcpLeaseObtainedDate = wmiNetworkAdapter.DHCPLeaseObtained;
            networkAdapter.DhcpServer = wmiNetworkAdapter.DHCPServer;
            networkAdapter.DatabasePath = wmiNetworkAdapter.DatabasePath;
            networkAdapter.WinsLMHostLookupEnabled = wmiNetworkAdapter.WINSEnableLMHostsLookup;
            networkAdapter.WinsHostLookupFile = wmiNetworkAdapter.WINSHostLookupFile;
            networkAdapter.WinsPrimaryServer = wmiNetworkAdapter.WINSPrimaryServer;
            networkAdapter.WinsSecondaryServer = wmiNetworkAdapter.WINSSecondaryServer;
            networkAdapter.Model = wmiNetworkAdapter.Description;

            networkAdapter.IPEnabled = wmiNetworkAdapter.IPEnabled;
            networkAdapter.IPAddresses = wmiNetworkAdapter.IPAddress;
            networkAdapter.DnsServers = wmiNetworkAdapter.DNSServerSearchOrder;
            networkAdapter.Gateways = wmiNetworkAdapter.DefaultIPGateway;
            networkAdapter.IPSubnets = wmiNetworkAdapter.IPSubnet;

            computer.NetworkAdapters.Add(networkAdapter);
        }
Example #7
0
        public void PersistProcessors(Computer computer, int computerID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            connection.Open();

            cmd.CommandText = "DeleteProcessorsByID";
            cmd.Parameters.Add("@ComputerID", computerID);
            cmd.ExecuteNonQuery();

            //Store each processor in DB
            foreach (ComputerSystem.Processor processor in computer.Processors)
            {
                cmd.CommandText = "AddProcessor";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@ComputerID", computerID);
                cmd.Parameters.Add("@Name", processor.Name + "");
                cmd.Parameters.Add("@L2CacheSize", (long)processor.L2CacheSize);
                cmd.Parameters.Add("@Speed", (long)processor.Speed);
                cmd.Parameters.Add("@UpgradeMethod", processor.UpgradeMethod + "");
                cmd.Parameters.Add("@Version", processor.Version + "");

                cmd.ExecuteNonQuery();
            }

            connection.Close();
        }
Example #8
0
        public void PersistShares(Computer computer, int computerID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            connection.Open();

            cmd.CommandText = "DeleteSharesByID";
            cmd.Parameters.Add("@ComputerID", computerID);
            cmd.ExecuteNonQuery();

            //Store each share in DB
            foreach (ComputerSystem.Share share in computer.Shares)
            {

                cmd.CommandText = "AddShare";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@ComputerID", computerID);
                cmd.Parameters.Add("@Description", share.Description + "");
                cmd.Parameters.Add("@Name", share.Name + "");
                cmd.Parameters.Add("@Path", share.Path + "");
                cmd.Parameters.Add("@Type", share.Type + "");
                cmd.Parameters.Add("@Status", share.Status + "");

                cmd.ExecuteNonQuery();
            }

            connection.Close();
        }
Example #9
0
        public void PersistPrinters(Computer computer, int computerID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            connection.Open();

            cmd.CommandText = "DeletePrintersByID";
            cmd.Parameters.Add("@ComputerID", computerID);
            cmd.ExecuteNonQuery();

            //Store each printer in DB
            foreach (ComputerSystem.Printer printer in computer.Printers)
            {

                cmd.CommandText = "AddPrinter";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@ComputerID", computerID);
                cmd.Parameters.Add("@Name", printer.Name + "");
                cmd.Parameters.Add("@ServerName", printer.ServerName + "");
                cmd.Parameters.Add("@ShareName", printer.ShareName + "");
                cmd.Parameters.Add("@State", printer.State + "");
                cmd.Parameters.Add("@Status", printer.Status + "");
                cmd.Parameters.Add("@HorizontalResolution", (long)printer.HorizontalResolution);
                cmd.Parameters.Add("@VerticalResolution", (long)printer.VerticalResolution);
                cmd.Parameters.Add("@DataType", printer.DataType + "");

                cmd.ExecuteNonQuery();
            }

            connection.Close();
        }
Example #10
0
        public void PersistProcesses(Computer computer, int computerID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            connection.Open();

            cmd.CommandText = "DeleteProcessesByID";
            cmd.Parameters.Add("@ComputerID", computerID);
            cmd.ExecuteNonQuery();

            //Store each process in DB
            foreach (ComputerSystem.Process process in computer.Processes)
            {
                cmd.CommandText = "AddProcess";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@ComputerID", computerID);
                cmd.Parameters.Add("@Name", process.Name + "");
                cmd.Parameters.Add("@Path", process.Path + "");

                cmd.ExecuteNonQuery();
            }

            connection.Close();
        }
        private static void AddPrinter(Computer computer, ROOT.CIMV2.Win32.Printer wmiPrinter)
        {
            Printer printer = new Printer();
            printer.Name = wmiPrinter.Name;
            printer.ShareName = wmiPrinter.ShareName;
            printer.ServerName = wmiPrinter.ServerName;
            printer.State = wmiPrinter.PrinterState.ToString();
            printer.Status = wmiPrinter.PrinterStatus.ToString();
            printer.DataType = wmiPrinter.PrintJobDataType;
            printer.HorizontalResolution = wmiPrinter.HorizontalResolution;
            printer.VerticalResolution = wmiPrinter.VerticalResolution;

            computer.Printers.Add(printer);
        }
Example #12
0
        public void PersistOperatingSystem(Computer computer, int computerID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            connection.Open();

            cmd.CommandText = "DeleteOperatingSystemByID";
            cmd.Parameters.Add("@ComputerID", computerID);
            cmd.ExecuteNonQuery();

            //Store Operating System in DB
            cmd.CommandText = "AddOperatingSystem";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@ComputerID", computerID);
            cmd.Parameters.Add("@Name", computer.OperatingSystem.Name + "");
            cmd.Parameters.Add("@FreePhysicalMemory", (long)computer.OperatingSystem.FreePhysicalMemory);
            cmd.Parameters.Add("@FreeVirtualMemory", (long)computer.OperatingSystem.FreeVirtualMemory);
            cmd.Parameters.Add("@InstallDate", computer.OperatingSystem.InstallDate);
            cmd.Parameters.Add("@LastBootUpTime", computer.OperatingSystem.LastBootUpTime);
            cmd.Parameters.Add("@LocalDateTime", computer.OperatingSystem.LocalDateTime);
            cmd.Parameters.Add("@SerialNumber", computer.OperatingSystem.SerialNumber + "");
            cmd.Parameters.Add("@ServicePack", computer.OperatingSystem.ServicePack + "");
            cmd.Parameters.Add("@Version", computer.OperatingSystem.Version + "");
            cmd.Parameters.Add("@WindowsDirectory", computer.OperatingSystem.WindowsDirectory + "");

            cmd.ExecuteNonQuery();

            connection.Close();
        }
Example #13
0
        public void PersistLogicalDisks(Computer computer, int computerID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            connection.Open();

            cmd.CommandText = "DeleteLogicalDisksByID";
            cmd.Parameters.Add("@ComputerID", computerID);
            cmd.ExecuteNonQuery();

            //Store each logical disk in DB
            foreach (ComputerSystem.LogicalDisk logicalDisk in computer.LogicalDisks)
            {
                cmd.CommandText = "AddLogicalDisk";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@ComputerID", computerID);
                cmd.Parameters.Add("@Name", logicalDisk.Name + "");
                cmd.Parameters.Add("@Description", logicalDisk.Description + "");
                cmd.Parameters.Add("@FileSystem", logicalDisk.FileSystem + "");
                cmd.Parameters.Add("@FreeSpace", (long)logicalDisk.FreeSpace);
                cmd.Parameters.Add("@ShareName", logicalDisk.ShareName + "");
                cmd.Parameters.Add("@Size", (long)logicalDisk.Size);
                cmd.Parameters.Add("@Status", logicalDisk.Status + "");
                cmd.Parameters.Add("@Type", logicalDisk.Type + "");

                cmd.ExecuteNonQuery();

            }

            connection.Close();
        }
        private static void AddProcess(Computer computer, ROOT.CIMV2.Win32.Process wmiProcess)
        {
            Process process = new Process();
            process.Name = wmiProcess.Name;
            process.Path = wmiProcess.ExecutablePath;

            computer.Processes.Add(process);
        }
        private static void AddProcessor(Computer computer, ROOT.CIMV2.Win32.Processor wmiProcessor)
        {
            Processor processor = new Processor();

            processor.Name = wmiProcessor.Name.Trim();
            processor.Speed = wmiProcessor.MaxClockSpeed;
            processor.L2CacheSize = wmiProcessor.L2CacheSize;
            processor.UpgradeMethod = wmiProcessor.UpgradeMethod.ToString();
            processor.Version = wmiProcessor.Version;

            computer.Processors.Add(processor);
        }
        private static Computer GetComputer(ManagementScope scope)
        {
            Computer Computer = new Computer();

            foreach (ROOT.CIMV2.Win32.OperatingSystem0 col in ROOT.CIMV2.Win32.OperatingSystem0.GetInstances(scope, ""))
            {
                AddOperatingSystem(Computer, col);
            }
            foreach (ROOT.CIMV2.Win32.ComputerSystem col in ROOT.CIMV2.Win32.ComputerSystem.GetInstances(scope, ""))
            {
                AddComputerSystem(Computer, col);
            }
            foreach (ROOT.CIMV2.Win32.Share col in ROOT.CIMV2.Win32.Share.GetInstances(scope, ""))
            {
                AddShare(Computer, col);
            }
            foreach (ROOT.CIMV2.Win32.Processor col in ROOT.CIMV2.Win32.Processor.GetInstances(scope, ""))
            {
                AddProcessor(Computer, col);
            }
            foreach (ROOT.CIMV2.Win32.LogicalDisk col in ROOT.CIMV2.Win32.LogicalDisk.GetInstances(scope, ""))
            {
                AddLogicalDisk(Computer, col);
            }
            foreach (ROOT.CIMV2.Win32.Process col in ROOT.CIMV2.Win32.Process.GetInstances(scope, ""))
            {
                AddProcess(Computer, col);
            }
            foreach (ROOT.CIMV2.Win32.Printer col in ROOT.CIMV2.Win32.Printer.GetInstances(scope, ""))
            {
                AddPrinter(Computer, col);
            }

            foreach (ROOT.CIMV2.Win32.NetworkAdapterConfiguration col in ROOT.CIMV2.Win32.NetworkAdapterConfiguration.GetInstances(scope, ""))
            {
                if (col.IPEnabled)
                {
                    AddNetworkAdapter(Computer, col);
                    //TreeNode CurrentNetworkAdapterConfigurationNode = new TreeNode( col.Description );
                    //AddNetworkAdapterConfiguration(CurrentNetworkAdapterConfigurationNode, col );
                    //NetworkAdapterConfigurationNode.Nodes.Add( CurrentNetworkAdapterConfigurationNode );
                }
            }

            return Computer;
        }
        private static void AddShare(Computer computer, ROOT.CIMV2.Win32.Share wmiShare)
        {
            Share share = new Share();
            share.Name = wmiShare.Name;
            share.Description = wmiShare.Description;
            share.Path = wmiShare.Path0;
            share.Type = wmiShare.Type.ToString();

            computer.Shares.Add(share);
        }
Example #18
0
        public void PersistNetworkAdapters(Computer computer, int computerID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            connection.Open();

            cmd.CommandText = "DeleteNetworkAdaptersByID";
            cmd.Parameters.Add("@ComputerID", computerID);
            cmd.ExecuteNonQuery();

            //Store each processor in DB
            foreach (ComputerSystem.NetworkAdapter networkAdapter in computer.NetworkAdapters)
            {
                cmd.CommandText = "AddNetworkAdapter";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@ComputerID", computerID);
                cmd.Parameters.Add("@DatabasePath", networkAdapter.DatabasePath + "");
                cmd.Parameters.Add("@DhcpEnabled", networkAdapter.DhcpEnabled);
                cmd.Parameters.Add("@DhcpLeaseExpirationDate", networkAdapter.DhcpLeaseExpirationDate);
                cmd.Parameters.Add("@DhcpLeaseObtainedDate", networkAdapter.DhcpLeaseObtainedDate);
                cmd.Parameters.Add("@DhcpServer", networkAdapter.DhcpServer + "");
                cmd.Parameters.Add("@DnsDomain", networkAdapter.DnsDomain + "");
                cmd.Parameters.Add("@DnsHostName", networkAdapter.DnsHostName + "");
                cmd.Parameters.Add("@DnsServers", String.Join(", ", networkAdapter.DnsServers) + "");
                cmd.Parameters.Add("@Gateways", String.Join(", ", networkAdapter.Gateways) + "");
                cmd.Parameters.Add("@IPAddresses", String.Join(", ", networkAdapter.IPAddresses) + "");
                cmd.Parameters.Add("@IPEnabled", networkAdapter.IPEnabled);
                cmd.Parameters.Add("@IPSubnets", String.Join(", ", networkAdapter.IPSubnets) + "");
                cmd.Parameters.Add("@MacAddress", networkAdapter.MacAddress + "");
                cmd.Parameters.Add("@Model", networkAdapter.Model + "");
                cmd.Parameters.Add("@WinsHostLookupFile", networkAdapter.WinsHostLookupFile + "");
                cmd.Parameters.Add("@WinsLMHostLookupEnabled", networkAdapter.WinsLMHostLookupEnabled);
                cmd.Parameters.Add("@WinsPrimaryServer", networkAdapter.WinsPrimaryServer + "");
                cmd.Parameters.Add("@WinsSecondaryServer", networkAdapter.WinsSecondaryServer + "");

                cmd.ExecuteNonQuery();
            }

            connection.Close();
        }
 private static void AddOperatingSystem(Computer computer, ROOT.CIMV2.Win32.OperatingSystem0 wmiOS)
 {
     computer.OperatingSystem.FreePhysicalMemory = wmiOS.FreePhysicalMemory;
     computer.OperatingSystem.FreeVirtualMemory = wmiOS.FreeVirtualMemory;
     computer.OperatingSystem.InstallDate = wmiOS.InstallDate;
     computer.OperatingSystem.LastBootUpTime = wmiOS.LastBootUpTime;
     computer.OperatingSystem.LocalDateTime = wmiOS.LocalDateTime;
     computer.OperatingSystem.Name = wmiOS.Caption;
     computer.OperatingSystem.SerialNumber = wmiOS.SerialNumber;
     computer.OperatingSystem.ServicePack = wmiOS.CSDVersion;
     computer.OperatingSystem.Version = wmiOS.Version;
     computer.OperatingSystem.WindowsDirectory = wmiOS.WindowsDirectory;
 }