Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

Need to develop Agentless software to retrieve software/hardware data from Windows Servers

Can anyone point me in the right direction to read up or learn about how to develop an Agentless Inventory software application to retrieve software/hardware data from Windows Servers? So, rather than develop a Windows Service that has to run on each of the Windows Servers and deploy it, it appears that there is a better way to do it using Agentless software.
I will be developing this using Visual Studio 2008 Professional and specifically, using the C# language. It doesn't matter if I learn to do it in ASP.NET or using Windows Forms. Any help would be most appreciated.
Thank you Experts!
Wallace
0
wally_davis
Asked:
wally_davis
  • 4
  • 2
2 Solutions
 
wally_davisAuthor Commented:
Thanks Kaufmed. Yes, I've used WMI numerous times in VBScript and I was wondering if that was the Class they might have been referring to. I like that last link you gave me using the ManagementObjectSearcher and ManagementObject class examples.
When using a For Each loop, I end up piping in one server name at a time. I imagine I could create a thread of some sort that would allow me to pipe in multiple servers so that the data collection and output is much quicker. Do you know of a class or an example that would allow me to do that?
0
 
käµfm³d 👽Commented:
Here's a quick Forms example I put together which uses ThreadPool to fork off the tasks. There is limited error checking, so you'd need to expand upon it. It should at least get you started  = )

You'll, of course, need to make sure the WMI service is enabled on each target machine and that you use an account that has the appropriate privileges.
using System;
using System.Management;
using System.Net.NetworkInformation;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApplication10
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Queries the server identified by <paramref name="serverNameOrIpAddress"/>.
        /// </summary>
        /// <param name="serverNameOrIpAddress">The server name or ip address.</param>
        private void QueryServer(object serverNameOrIpAddress)
        {
            ConnectionOptions options = new ConnectionOptions();

            options.EnablePrivileges = true;
            options.Username = UserInfo.UserName;    // UserInfo is my class and not mandatory for your usage
            options.Password = UserInfo.Password;    // UserInfo is my class and not mandatory for your usage
            options.Authority = "ntlmdomain:Laptop"; // Change "Laptop" to your DOMAIN. I was targeting one non-domain machine.

            string connectionString = string.Format(@"\\{0}\root\cimv2", serverNameOrIpAddress.ToString());
            ManagementScope scope = new ManagementScope(connectionString, options);

            try
            {
                scope.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not connect!");
                return;
            }

            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection objects = searcher.Get();

            foreach (ManagementObject obj in objects)
            {
                string resultString = string.Concat(serverNameOrIpAddress, ": ", obj["Caption"].ToString());
                DisplayResult(resultString);
            }
        }

        /// <summary>
        /// Displays the result.
        /// </summary>
        /// <param name="result">The result.</param>
        private void DisplayResult(string result)
        {
            if (this.resultsList.InvokeRequired)
            {
                this.resultsList.Invoke((Action<string>)DisplayResult, result);
            }
            else
            {
                this.resultsList.Items.Add(result);
            }
        }

        /// <summary>
        /// Handles the Click event of the startQueryButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void startQueryButton_Click(object sender, EventArgs e)
        {
            this.resultsList.Items.Clear();

            foreach (object item in this.targetList.Items)
            {
                ThreadPool.QueueUserWorkItem(QueryServer, item);
            }
        }

        /// <summary>
        /// Handles the Click event of the addTargetButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void addTargetButton_Click(object sender, EventArgs e)
        {
            // Add an entry to the "target" list if it actually is "alive"
            if (this.targetBox.Text.Trim().Length > 0 && !this.targetList.Items.Contains(this.targetBox.Text))
            {
                Ping pinger = new Ping();

                try
                {
                    PingReply reply = pinger.Send(this.targetBox.Text);

                    if (reply.Status == IPStatus.Success)
                    {
                        this.targetList.Items.Add(this.targetBox.Text);
                        this.targetBox.Clear();
                    }
                }
                catch (PingException ex)
                {
                    MessageBox.Show(ex.InnerException.Message);
                    return;
                }
            }
        }

        /// <summary>
        /// Handles the Click event of the clearButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void clearButton_Click(object sender, EventArgs e)
        {
            this.targetList.Items.Clear();
            this.resultsList.Items.Clear();
            this.targetBox.Clear();
        }
    }
}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
käµfm³d 👽Commented:
Here's a screenshot of the results of using the code above. In reality, "Laptop" and "192.168.1.101" are the same machine, but it should give you an idea of what to expect.
Untitled.png
0
 
käµfm³d 👽Commented:
P.S.

You *may* not need the ConnectionOptions parameter. I was querying a Win 7 box, and it seems like it was required (even though I have the same account on both machines).
0
 
wally_davisAuthor Commented:
Great exampls of using the WMI Class Kaufmed. Thanks!
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now