We help IT Professionals succeed at work.

Help

PeterSchenk
PeterSchenk asked
on
HI,
I need some help combining the two click events below.  btWes7 is for a Windows 7 system and btDebian is for a Linux Debian system.  Once combined I will need to be able to determine that the host system is Windows 7 and run that part or Debian and run the other part.  


        private void btWes7_Click(object sender, EventArgs e)
        {
            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();
                }
            }

        }
       
       
       private void btDebianCNN_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
                        CNN();
                        Thread.Sleep(500);
                        data(stfamtv0002);
        }
Comment
Watch Question

Senior Developer
BRONZE EXPERT
Commented:
Try the code below:

private void RunWindows7()
    {
        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();
            }
        }

    }


    private void RunLinux()
    {
        CNN();
        Thread.Sleep(500);
        data(stfamtv0002);
    }

    private void btCombination_Click(object sender, EventArgs e)
    {
        if (getOSInfo() == "7")
        {
            RunWindows7();
        }
        else if (getOSInfo() == "LINUX")
        {
            RunLinux();
        }
    }

    private string getOSInfo()
    {
        OperatingSystem os = Environment.OSVersion;
        Version vs = os.Version;

        string operatingSystem = "";

        if (os.Platform == PlatformID.Win32Windows)
        {            
            operatingSystem = "PRE-WINDOWS";
        }
        else if (os.Platform == PlatformID.Win32NT)
        {
            switch (vs.Major)
            {
                case 3:
                    operatingSystem = "PRE-WINDOWS";
                    break;
                case 4:
                    operatingSystem = "PRE-WINDOWS";
                    break;
                case 5:
                    if (vs.Minor == 0)
                        operatingSystem = "PRE-WINDOWS";
                    else
                        operatingSystem = "XP";
                    break;
                case 6:
                    if (vs.Minor == 0)
                        operatingSystem = "Vista";
                    else
                        operatingSystem = "7";
                    break;
                default:
                    break;
            }
        }
        else
        {
            int p = (int)Environment.OSVersion.Platform;
            if (p == 4 || p == 6 || p == 128)
                operatingSystem = "LINUX";
        }

        return operatingSystem;
    }

try this

        private void button1_Click(object sender, EventArgs e)
        {
            dosomething(sender, e);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dosomething(sender, e);
        }


        private void dosomething(object sender, EventArgs e)
        {
            switch (((System.Windows.Forms.ButtonBase)(sender)).Text )
            {
                case "button1":
                    break;
                case "button2":
                    break;
            }
            
        }

Open in new window

Author

Commented:
Armchang,
Your code is reading the local operating system.... Need it to ready the target machine operating system.

Commented:
if (Environment.OSVersion.Platform == PlatformID.Win32NT
   && Environment.OSVersion.Version.Major == 6
   && Environment.OSVersion.Version.Minor != 0)
      {
          // run code for Windows 7
      }
else
      {
          // run code for Linux Debian system
      }      

Author

Commented:
All of this code is looking at what kind of machine the program is running on ..... this needs to look at the remote machine its connecting to and determine whether its a Linux or Widows 7 machine.

Author

Commented:
Solution does not meet criteria

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