We help IT Professionals succeed at work.

Need some Help

PeterSchenk
PeterSchenk asked
on

HI,
I need the code below to look at the remote system and determine if it’s a windows 7 or not.  The way its written it can only determine if the machine its running on is Windows 7 or no.

        private void button4_Click(object sender, EventArgs e)
        {
            if (Environment.OSVersion.Platform == PlatformID.Win32NT
                && Environment.OSVersion.Version.Major == 6
                && Environment.OSVersion.Version.Minor != 0)
                    {
                        data(stfamtv0001); //Sets Thin Client Variable
                        if (string.IsNullOrEmpty(hostname_value))
                        {
                            MessageBox.Show("Hostname was not set!");
                        }
                        else
                        {
                            System.Diagnostics.Process ps = System.Diagnostics.Process.Start("pskill", hostname_value);
                            ps.WaitForExit();

                            data(stfamtv0002);
                            if (string.IsNullOrEmpty(hostname_value))
                            {
                                MessageBox.Show("Hostname was not set!");
                            }
                            else
                            {
                                ps = System.Diagnostics.Process.Start("psexec", hostname_value); ;
                                ps.WaitForExit();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("This is a Linux System");        
                // run code for Linux Debian system
                    }    
        }
Comment
Watch Question

You can use this to get what version of Windows is running, I am not sure how to get Linux info though.

This sets the String OSv to the OS name, you could then check that variable with known names and run your PSExec...
            string OSv;

            ConnectionOptions connection = new ConnectionOptions();

            ManagementScope scope = new ManagementScope("\\\\" + computerName + "\\root\\CIMV2", connection);
            scope.Connect();

            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");

            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

            foreach (ManagementObject queryObj in searcher.Get())
            {
                OSv = queryObj["Caption"];
            }

Open in new window

Author

Commented:
OK how can we intergratet that into my code?
You could put your OS check here:

           
             foreach (ManagementObject queryObj in searcher.Get())
            {
                string OSv = Convert.ToString(queryObj["Caption"]);
                if (OSv.Contains("Windows"))
                    System.Console.Out.WriteLine("Windows version: {0}", OSv);
            }

Open in new window


I have it check the string for the word "Windows" for this example.

Author

Commented:
Example is great but I need a working solution intergrated into the orginal code above.

Author

Commented:
no Complete

Explore More ContentExplore courses, solutions, and other research materials related to this topic.