Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
AnswerRe: Very Simple Question Pin
Jochen Arndt23-Mar-17 4:25
professionalJochen Arndt23-Mar-17 4:25 
AnswerRe: Very Simple Question Pin
Richard MacCutchan23-Mar-17 4:29
mveRichard MacCutchan23-Mar-17 4:29 
AnswerRe: Very Simple Question Pin
Pete O'Hanlon23-Mar-17 4:30
mvePete O'Hanlon23-Mar-17 4:30 
AnswerRe: Very Simple Question Pin
Gerry Schmitz23-Mar-17 17:38
mveGerry Schmitz23-Mar-17 17:38 
AnswerRe: Very Simple Question Pin
V.23-Mar-17 20:19
professionalV.23-Mar-17 20:19 
GeneralRe: Very Simple Question Pin
Richard MacCutchan23-Mar-17 22:43
mveRichard MacCutchan23-Mar-17 22:43 
AnswerRe: Very Simple Question Pin
OriginalGriff23-Mar-17 23:36
mveOriginalGriff23-Mar-17 23:36 
Questionmessagebox problem when process completed Pin
Akshit.b23-Mar-17 0:17
Akshit.b23-Mar-17 0:17 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Reflection;
using System.Threading;
using System.Configuration;
using System.Net;
using System.Net.NetworkInformation;


namespace RemoteBlocker
{
    public partial class Form2 : Form
    {
        BackgroundWorker bgw = new BackgroundWorker();

        int mode = 0;

        public Form2()
        {
            InitializeComponent();
        }

        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            int total = 100;

            for (int i = 0; i <= total; i++)
            {
                System.Threading.Thread.Sleep(50);
                int percents = (i * 100) / total;
                bgw.ReportProgress(percents, i);
            }
        }

        private void bgw_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
        }

        private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //do the code when bgv completes its work
            progressBar1.Visible = false;

            if (mode == 1)
            {
                MessageBox.Show("Enable Successfully.");
            }
            else if (mode == 2)
            {
                MessageBox.Show("Disable Successfully.");
            }           
        }

        private void btnDisable_Click(object sender, EventArgs e)
        {
            try
            {
                Ping pingServer1 = new Ping();
                PingReply pingresultFrmServer1 = pingServer1.Send("172.16.102.4");
                if (pingresultFrmServer1.Status.ToString() == "Success")
                {
                    try
                    {
                        Process proc = null;

                        string batDir = System.Configuration.ConfigurationManager.AppSettings["block1"];
                        string executebatDir = System.Configuration.ConfigurationManager.AppSettings["executeblock"];

                        FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(batDir);
                        ftpRequest.Credentials = new NetworkCredential("subhankar", "subhankar");
                        ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                        FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();

                        StreamReader streamReader = new StreamReader(response.GetResponseStream());
                        List<string> directories = new List<string>();

                        string line = streamReader.ReadLine();
                        while (!string.IsNullOrEmpty(line))
                        {
                            directories.Add(line);
                            line = streamReader.ReadLine();
                        }
                        streamReader.Close();

                        using (WebClient ftpClient = new WebClient())
                        {
                            ftpClient.Credentials = new System.Net.NetworkCredential("subhankar", "subhankar");

                            for (int i = 0; i <= directories.Count - 1; i++)
                            {
                                if (directories[i].Contains("."))
                                {
                                    string path = batDir + directories[i].ToString();
                                    string trnsfrpth = executebatDir + directories[i].ToString();
                                    ftpClient.DownloadFile(path, trnsfrpth);
                                }
                            }

                            proc = new Process();

                            string trnsfrexepth = executebatDir;
                            proc.StartInfo.WorkingDirectory = trnsfrexepth;

                            proc.StartInfo.FileName = "Hostblock.bat";
                            proc.StartInfo.CreateNoWindow = false;
                            proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                            proc.StartInfo.Verb = "runas";
                            proc.Start();
                            proc.WaitForExit();

                            // Delete From temp folder

                            DirectoryInfo dir = new DirectoryInfo(trnsfrexepth);

                            foreach (FileInfo files in dir.GetFiles("*.bat"))
                            {
                                files.Delete();
                            }

                            foreach (DirectoryInfo dirs in dir.GetDirectories())
                            {
                                //dirs.Delete(true);
                            }

                            progressBar1.Visible = true;

                            bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
                            bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
                            bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
                            bgw.WorkerReportsProgress = true;
                            bgw.RunWorkerAsync();

                            mode = 1;                            
                        }
                    }
                    catch (Exception exc)
                    {

                    }
                    finally
                    {

                    }
                }
                else
                {
                    Ping pingServer2 = new Ping();
                    PingReply pingresultFrmServer2 = pingServer2.Send("172.16.102.4");
                    if (pingresultFrmServer2.Status.ToString() == "Success")
                    {
                        try
                        {
                            Process proc = null;

                            string batDir = System.Configuration.ConfigurationManager.AppSettings["block2"];
                            string executebatDir = System.Configuration.ConfigurationManager.AppSettings["executeblock"];

                            FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(batDir);
                            ftpRequest.Credentials = new NetworkCredential("subhankar", "subhankar");
                            ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                            FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();

                            StreamReader streamReader = new StreamReader(response.GetResponseStream());
                            List<string> directories = new List<string>();

                            string line = streamReader.ReadLine();
                            while (!string.IsNullOrEmpty(line))
                            {
                                directories.Add(line);
                                line = streamReader.ReadLine();
                            }
                            streamReader.Close();

                            using (WebClient ftpClient = new WebClient())
                            {
                                ftpClient.Credentials = new System.Net.NetworkCredential("subhankar", "subhankar");

                                for (int i = 0; i <= directories.Count - 1; i++)
                                {
                                    if (directories[i].Contains("."))
                                    {
                                        string path = batDir + directories[i].ToString();
                                        string trnsfrpth = executebatDir + directories[i].ToString();
                                        ftpClient.DownloadFile(path, trnsfrpth);
                                    }
                                }

                                proc = new Process();

                                string trnsfrexepth = executebatDir;
                                proc.StartInfo.WorkingDirectory = trnsfrexepth;

                                proc.StartInfo.FileName = "Hostblock.bat";
                                proc.StartInfo.CreateNoWindow = false;
                                proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                                proc.StartInfo.Verb = "runas";
                                proc.Start();
                                proc.WaitForExit();

                                // Delete From temp folder

                                DirectoryInfo dir = new DirectoryInfo(trnsfrexepth);

                                foreach (FileInfo files in dir.GetFiles("*.bat"))
                                {
                                    files.Delete();
                                }

                                foreach (DirectoryInfo dirs in dir.GetDirectories())
                                {
                                    //dirs.Delete(true);
                                }

                                progressBar1.Visible = true;

                                //bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
                                //bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
                                //bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
                                //bgw.WorkerReportsProgress = true;
                                bgw.RunWorkerAsync();

                                mode = 1;
                            }
                        }
                        catch (Exception exc)
                        {

                        }
                        finally
                        {

                        }
                    }
                    else
                    {
                        Ping pingServer3 = new Ping();
                        PingReply pingresultFrmServer3 = pingServer3.Send("172.16.102.4");
                        if (pingresultFrmServer3.Status.ToString() == "Success")
                        {
                            try
                            {
                                Process proc = null;

                                string batDir = System.Configuration.ConfigurationManager.AppSettings["block3"];
                                string executebatDir = System.Configuration.ConfigurationManager.AppSettings["executeblock"];

                                FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(batDir);
                                ftpRequest.Credentials = new NetworkCredential("subhankar", "subhankar");
                                ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                                FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();

                                StreamReader streamReader = new StreamReader(response.GetResponseStream());
                                List<string> directories = new List<string>();

                                string line = streamReader.ReadLine();
                                while (!string.IsNullOrEmpty(line))
                                {
                                    directories.Add(line);
                                    line = streamReader.ReadLine();
                                }
                                streamReader.Close();

                                using (WebClient ftpClient = new WebClient())
                                {
                                    ftpClient.Credentials = new System.Net.NetworkCredential("subhankar", "subhankar");

                                    for (int i = 0; i <= directories.Count - 1; i++)
                                    {
                                        if (directories[i].Contains("."))
                                        {
                                            string path = batDir + directories[i].ToString();
                                            string trnsfrpth = executebatDir + directories[i].ToString();
                                            ftpClient.DownloadFile(path, trnsfrpth);
                                        }
                                    }

                                    proc = new Process();

                                    string trnsfrexepth = executebatDir;
                                    proc.StartInfo.WorkingDirectory = trnsfrexepth;

                                    proc.StartInfo.FileName = "Hostblock.bat";
                                    proc.StartInfo.CreateNoWindow = false;
                                    proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                                    proc.StartInfo.Verb = "runas";
                                    proc.Start();
                                    proc.WaitForExit();

                                    // Delete From temp folder

                                    DirectoryInfo dir = new DirectoryInfo(trnsfrexepth);

                                    foreach (FileInfo files in dir.GetFiles("*.bat"))
                                    {
                                        files.Delete();
                                    }

                                    foreach (DirectoryInfo dirs in dir.GetDirectories())
                                    {
                                        //dirs.Delete(true);
                                    }

                                    progressBar1.Visible = true;

                                    //bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
                                    //bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
                                    //bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
                                    //bgw.WorkerReportsProgress = true;
                                    bgw.RunWorkerAsync();

                                    mode = 1;
                                }
                            }
                            catch (Exception exc)
                            {

                            }
                            finally
                            {

                            }

                        }
                    }





                    //////////////////////////////////////////////////////////////////////////

                    //Process proc = null;

                    //string batDir = System.Configuration.ConfigurationManager.AppSettings["block1"];
                    //string executebatDir = System.Configuration.ConfigurationManager.AppSettings["executeblock"];

                    //FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(batDir);
                    //ftpRequest.Credentials = new NetworkCredential("subhankar", "subhankar");
                    //ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                    //FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();

                    //StreamReader streamReader = new StreamReader(response.GetResponseStream());
                    //List<string> directories = new List<string>();

                    //string line = streamReader.ReadLine();
                    //while (!string.IsNullOrEmpty(line))
                    //{
                    //    directories.Add(line);
                    //    line = streamReader.ReadLine();
                    //}
                    //streamReader.Close();

                    //using (WebClient ftpClient = new WebClient())
                    //{
                    //    ftpClient.Credentials = new System.Net.NetworkCredential("subhankar", "subhankar");

                    //    for (int i = 0; i <= directories.Count - 1; i++)
                    //    {
                    //        if (directories[i].Contains("."))
                    //        {
                    //            string path = batDir + directories[i].ToString();
                    //            string trnsfrpth = executebatDir + directories[i].ToString();
                    //            ftpClient.DownloadFile(path, trnsfrpth);
                    //        }
                    //    }

                    //    proc = new Process();

                    //    string trnsfrexepth = executebatDir;
                    //    proc.StartInfo.WorkingDirectory = trnsfrexepth;

                    //    proc.StartInfo.FileName = "Hostblock.bat";
                    //    proc.StartInfo.CreateNoWindow = false;
                    //    proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                    //    proc.StartInfo.Verb = "runas";
                    //    proc.Start();
                    //    proc.WaitForExit();

                    //    // Delete From temp folder

                    //    DirectoryInfo dir = new DirectoryInfo(trnsfrexepth);

                    //    foreach (FileInfo files in dir.GetFiles("*.bat"))
                    //    {
                    //        files.Delete();
                    //    }

                    //    foreach (DirectoryInfo dirs in dir.GetDirectories())
                    //    {
                    //        //dirs.Delete(true);
                    //    }

                    //    progressBar1.Visible = true;

                    //    bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
                    //    bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
                    //    bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
                    //    bgw.WorkerReportsProgress = true;
                    //    bgw.RunWorkerAsync();

                    //    mode = 1;
                    //}
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        }

        private void btnEnable_Click(object sender, EventArgs e)
        {
            try
            {
                Ping pingServer1 = new Ping();
                PingReply pingresultFrmServer1 = pingServer1.Send("172.16.102.4");
                if (pingresultFrmServer1.Status.ToString() == "Success")
                {
                    try 
                    {
                        Process proc = null;

                        string batDir = System.Configuration.ConfigurationManager.AppSettings["unblock1"];
                        string executebatDir = System.Configuration.ConfigurationManager.AppSettings["executeunblock"];

                        FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(batDir);
                        ftpRequest.Credentials = new NetworkCredential("subhankar", "subhankar");
                        ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                        FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
                        StreamReader streamReader = new StreamReader(response.GetResponseStream());
                        List<string> directories = new List<string>();

                        string line = streamReader.ReadLine();
                        while (!string.IsNullOrEmpty(line))
                        {
                            directories.Add(line);
                            line = streamReader.ReadLine();
                        }
                        streamReader.Close();

                        using (WebClient ftpClient = new WebClient())
                        {
                            ftpClient.Credentials = new System.Net.NetworkCredential("subhankar", "subhankar");

                            for (int i = 0; i <= directories.Count - 1; i++)
                            {
                                if (directories[i].Contains("."))
                                {
                                    string path = batDir + directories[i].ToString();
                                    string trnsfrpth = executebatDir + directories[i].ToString();
                                    ftpClient.DownloadFile(path, trnsfrpth);
                                }
                            }

                            proc = new Process();

                            string trnsfrexepth = executebatDir;
                            proc.StartInfo.WorkingDirectory = trnsfrexepth;

                            proc.StartInfo.FileName = "Undohostblock.bat";
                            proc.StartInfo.CreateNoWindow = false;
                            proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                            proc.StartInfo.Verb = "runas";
                            proc.Start();
                            proc.WaitForExit();

                            // Delete From temp folder

                            DirectoryInfo dir = new DirectoryInfo(trnsfrexepth);

                            foreach (FileInfo files in dir.GetFiles("*.bat"))
                            {
                                files.Delete();
                            }

                            foreach (DirectoryInfo dirs in dir.GetDirectories())
                            {
                                //dirs.Delete(true);
                            }

                            progressBar1.Visible = true;

                            bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
                            bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
                            bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
                            bgw.WorkerReportsProgress = true;
                            bgw.RunWorkerAsync();
                            
                            mode = 2;
                        } 
                    }
                    catch(Exception exc)
                    {
                        
                    }
                    finally
                    {

                    }
                }
                else 
                {
                    Ping pingServer2 = new Ping();
                    PingReply pingresultFrmServer2 = pingServer2.Send("172.16.102.4");
                    if (pingresultFrmServer2.Status.ToString() == "Success")
                    {
                        try
                        {
                            Process proc = null;

                            string batDir = System.Configuration.ConfigurationManager.AppSettings["unblock2"];
                            string executebatDir = System.Configuration.ConfigurationManager.AppSettings["executeunblock"];

                            FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(batDir);
                            ftpRequest.Credentials = new NetworkCredential("subhankar", "subhankar");
                            ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                            FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
                            StreamReader streamReader = new StreamReader(response.GetResponseStream());
                            List<string> directories = new List<string>();

                            string line = streamReader.ReadLine();
                            while (!string.IsNullOrEmpty(line))
                            {
                                directories.Add(line);
                                line = streamReader.ReadLine();
                            }
                            streamReader.Close();

                            using (WebClient ftpClient = new WebClient())
                            {
                                ftpClient.Credentials = new System.Net.NetworkCredential("subhankar", "subhankar");

                                for (int i = 0; i <= directories.Count - 1; i++)
                                {
                                    if (directories[i].Contains("."))
                                    {
                                        string path = batDir + directories[i].ToString();
                                        string trnsfrpth = executebatDir + directories[i].ToString();
                                        ftpClient.DownloadFile(path, trnsfrpth);
                                    }
                                }

                                proc = new Process();

                                string trnsfrexepth = executebatDir;
                                proc.StartInfo.WorkingDirectory = trnsfrexepth;

                                proc.StartInfo.FileName = "Undohostblock.bat";
                                proc.StartInfo.CreateNoWindow = false;
                                proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                                proc.StartInfo.Verb = "runas";
                                proc.Start();
                                proc.WaitForExit();

                                // Delete From temp folder

                                DirectoryInfo dir = new DirectoryInfo(trnsfrexepth);

                                foreach (FileInfo files in dir.GetFiles("*.bat"))
                                {
                                    files.Delete();
                                }

                                foreach (DirectoryInfo dirs in dir.GetDirectories())
                                {
                                    //dirs.Delete(true);
                                }

                                progressBar1.Visible = true;

                                //bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
                                //bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
                                //bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
                                //bgw.WorkerReportsProgress = true;
                                bgw.RunWorkerAsync();

                                mode = 2;
                            } 
                        }
                        catch (Exception exc)
                        {

                        }
                        finally
                        {

                        }
                    }
                    else
                    {
                        Ping pingServer3 = new Ping();
                        PingReply pingresultFrmServer3 = pingServer3.Send("172.16.102.4");
                        if (pingresultFrmServer3.Status.ToString() == "Success")
                        {
                            try
                            {
                                Process proc = null;

                                string batDir = System.Configuration.ConfigurationManager.AppSettings["unblock3"];
                                string executebatDir = System.Configuration.ConfigurationManager.AppSettings["executeunblock"];

                                FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(batDir);
                                ftpRequest.Credentials = new NetworkCredential("subhankar", "subhankar");
                                ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                                FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
                                StreamReader streamReader = new StreamReader(response.GetResponseStream());
                                List<string> directories = new List<string>();

                                string line = streamReader.ReadLine();
                                while (!string.IsNullOrEmpty(line))
                                {
                                    directories.Add(line);
                                    line = streamReader.ReadLine();
                                }
                                streamReader.Close();

                                using (WebClient ftpClient = new WebClient())
                                {
                                    ftpClient.Credentials = new System.Net.NetworkCredential("subhankar", "subhankar");

                                    for (int i = 0; i <= directories.Count - 1; i++)
                                    {
                                        if (directories[i].Contains("."))
                                        {
                                            string path = batDir + directories[i].ToString();
                                            string trnsfrpth = executebatDir + directories[i].ToString();
                                            ftpClient.DownloadFile(path, trnsfrpth);
                                        }
                                    }

                                    proc = new Process();

                                    string trnsfrexepth = executebatDir;
                                    proc.StartInfo.WorkingDirectory = trnsfrexepth;

                                    proc.StartInfo.FileName = "Undohostblock.bat";
                                    proc.StartInfo.CreateNoWindow = false;
                                    proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                                    proc.StartInfo.Verb = "runas";
                                    proc.Start();
                                    proc.WaitForExit();

                                    // Delete From temp folder

                                    DirectoryInfo dir = new DirectoryInfo(trnsfrexepth);

                                    foreach (FileInfo files in dir.GetFiles("*.bat"))
                                    {
                                        files.Delete();
                                    }

                                    foreach (DirectoryInfo dirs in dir.GetDirectories())
                                    {
                                        //dirs.Delete(true);
                                    }

                                    progressBar1.Visible = true;

                                    //bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
                                    //bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
                                    //bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
                                    //bgw.WorkerReportsProgress = true;
                                    bgw.RunWorkerAsync();

                                    mode = 2;
                                }
                            }
                            catch (Exception exc)
                            {

                            }
                            finally
                            {

                            }
                        }
                        else
                        {

                        }
                    }
                }

                //////////////////////////////////////////////////////

                //Process proc = null;

                //string batDir = System.Configuration.ConfigurationManager.AppSettings["unblock1"];
                //string executebatDir = System.Configuration.ConfigurationManager.AppSettings["executeunblock"];

                //FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(batDir);
                //ftpRequest.Credentials = new NetworkCredential("subhankar", "subhankar");
                //ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                //FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
                //StreamReader streamReader = new StreamReader(response.GetResponseStream());
                //List<string> directories = new List<string>();

                //string line = streamReader.ReadLine();
                //while (!string.IsNullOrEmpty(line))
                //{
                //    directories.Add(line);
                //    line = streamReader.ReadLine();
                //}
                //streamReader.Close();

                //using (WebClient ftpClient = new WebClient())
                //{
                //    ftpClient.Credentials = new System.Net.NetworkCredential("subhankar", "subhankar");

                //    for (int i = 0; i <= directories.Count - 1; i++)
                //    {
                //        if (directories[i].Contains("."))
                //        {
                //            string path = batDir + directories[i].ToString();
                //            string trnsfrpth = executebatDir + directories[i].ToString();
                //            ftpClient.DownloadFile(path, trnsfrpth);
                //        }
                //    }

                //    proc = new Process();

                //    string trnsfrexepth = executebatDir;
                //    proc.StartInfo.WorkingDirectory = trnsfrexepth;

                //    proc.StartInfo.FileName = "Undohostblock.bat";
                //    proc.StartInfo.CreateNoWindow = false;
                //    proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                //    proc.StartInfo.Verb = "runas";
                //    proc.Start();
                //    proc.WaitForExit();

                //    // Delete From temp folder

                //    DirectoryInfo dir = new DirectoryInfo(trnsfrexepth);

                //    foreach (FileInfo files in dir.GetFiles("*.bat"))
                //    {
                //        files.Delete();
                //    }

                //    foreach (DirectoryInfo dirs in dir.GetDirectories())
                //    {
                //        //dirs.Delete(true);
                //    }                                    

                //    progressBar1.Visible = true;

                //    bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
                //    bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
                //    bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
                //    bgw.WorkerReportsProgress = true;
                //    bgw.RunWorkerAsync();

                //    mode = 2;
                //}                
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            this.Hide();
            f.Close();
        }

        private void btnAdmin_Click(object sender, EventArgs e)
        {
            Form3 f = new Form3();
            this.Hide();
            f.Show();
        }       
    }
}



after clicking enable button when clicking disable button then message box comes 2 times.it is increasing recursively.
AnswerRe: messagebox problem when process completed Pin
Richard MacCutchan23-Mar-17 2:08
mveRichard MacCutchan23-Mar-17 2:08 
AnswerRe: messagebox problem when process completed Pin
Dave Kreskowiak23-Mar-17 2:43
mveDave Kreskowiak23-Mar-17 2:43 
AnswerRe: messagebox problem when process completed Pin
Gerry Schmitz23-Mar-17 17:41
mveGerry Schmitz23-Mar-17 17:41 
AnswerRe: messagebox problem when process completed Pin
Luc Pattyn24-Mar-17 4:27
sitebuilderLuc Pattyn24-Mar-17 4:27 
GeneralRe: messagebox problem when process completed Pin
Akshit.b26-Mar-17 20:22
Akshit.b26-Mar-17 20:22 
QuestionHow to write a generic code to make async call to Rest Service Pin
ArunHanu22-Mar-17 0:31
ArunHanu22-Mar-17 0:31 
AnswerRe: How to write a generic code to make async call to Rest Service Pin
Nathan Minier22-Mar-17 1:13
professionalNathan Minier22-Mar-17 1:13 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
ArunHanu22-Mar-17 1:43
ArunHanu22-Mar-17 1:43 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Pete O'Hanlon22-Mar-17 2:03
mvePete O'Hanlon22-Mar-17 2:03 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Nathan Minier22-Mar-17 2:08
professionalNathan Minier22-Mar-17 2:08 
SuggestionRe: How to write a generic code to make async call to Rest Service Pin
Richard Deeming22-Mar-17 2:23
mveRichard Deeming22-Mar-17 2:23 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
ArunHanu22-Mar-17 3:06
ArunHanu22-Mar-17 3:06 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Nathan Minier22-Mar-17 3:53
professionalNathan Minier22-Mar-17 3:53 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Richard Deeming22-Mar-17 4:20
mveRichard Deeming22-Mar-17 4:20 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Nathan Minier22-Mar-17 4:59
professionalNathan Minier22-Mar-17 4:59 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Richard Deeming22-Mar-17 5:26
mveRichard Deeming22-Mar-17 5:26 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Nathan Minier22-Mar-17 6:06
professionalNathan Minier22-Mar-17 6:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.