Learn how to a build a cloud-first strategyRegister Now

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

Put this together....

Hi,
Im trying to take do a PSKILL in button click one before doing a PSEXEC action in button click two.  I need to combine these two in that order under one click event and need some help to do it.  The PSKILL needs to run first then the PSEXEC.

namespace WindowsFormsApplication7
{
    public partial class Form1 : Form  
    {
       // private string stfamtv0001 = "-i 1 -d -u Administrator -p Administrator \\\\{0} vlc.exe --video-on-top --volume 512 rtsp://stfamtv0007/streama";
        private string stfamtv0002 = "-i 1 -d -u Administrator -p Administrator \\\\{0} vlc.exe --video-on-top --volume 512 rtsp://stfamtv0007/streama";
        private string stfamtv0003; // New variable
        private string hostname_value;
        string stfamtv0001 = "-t \\\\{0} -u Administrator -p Administrator vlc";

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            data(stfamtv0001); //Sets Thin Client Variable
         //   vlcKill(killvlc);
            if (string.IsNullOrEmpty(hostname_value))
            {
                MessageBox.Show("Hostname was not set!");
            }
           
            else
            {
                vlcKill(hostname_value);
            }
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            data(stfamtv0002);


            if (string.IsNullOrEmpty(hostname_value))
            {
                MessageBox.Show("Hostname was not set!");
            }
            else
            {
                PCdata(hostname_value);
            }
        }
        private void vlcKill(string PCstreamPath)
        {
            System.Diagnostics.Process ps;
            ps = new System.Diagnostics.Process();
            ps.EnableRaisingEvents = false;
            ps.StartInfo.UseShellExecute = false;
            System.Diagnostics.Process.Start("pskill", PCstreamPath);
            ps.Close();
        }

        private void PCdata(string PCstreamPath)
        {
            System.Diagnostics.Process ps;
            ps = new System.Diagnostics.Process();
            ps.EnableRaisingEvents = false;
            ps.StartInfo.UseShellExecute = false;
            System.Diagnostics.Process.Start("psexec", PCstreamPath);
            ps.Close();
        }

        private void data(string streamPath)
        {
          //  System.Collections.IDictionary envVars = Environment.GetEnvironmentVariables();

            System.Collections.IDictionary envVars = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User);

            foreach (System.Collections.DictionaryEntry envVar in envVars)
            {
                if (envVar.Key.ToString() == "ThinConnectedFrom")
                {
                    hostname_value = string.Format(streamPath, envVar.Value.ToString());
                }
            }
        }


    }

}
0
PeterSchenk
Asked:
PeterSchenk
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Does this work?
private void button3_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();
                }                
            }
        }

Open in new window

0
 
PeterSchenkAuthor Commented:
Your simple the best : )
0

Featured Post

Technology Partners: 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!

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