S
S
sHARek2019-02-20 12:58:54
C++ / C#
sHARek, 2019-02-20 12:58:54

How to "Create a Solution"?

Good afternoon.
Picking homemade:

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.IO;
using System.Diagnostics;

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

        private void button1_Click(object sender, EventArgs e)
        {
            //string  = textBox2.Text;
            //label2.Text = Text;
            string Pc = textBox2.Text;
            ProcessStartInfo psiOpt = new ProcessStartInfo("cmd.exe", "/c ping 192.168.1." + Pc) {
                StandardOutputEncoding = Encoding.GetEncoding(866)// устанавливаем кодировку выводимого
            };
            // скрываем окно запущенного процесса
            psiOpt.WindowStyle = ProcessWindowStyle.Hidden;
            psiOpt.RedirectStandardOutput = true;
            psiOpt.UseShellExecute = false;
            psiOpt.CreateNoWindow = true; //не показывать cmd
            // запускаем процесс
            Process procCommand = Process.Start(psiOpt);
            // получаем ответ запущенного процесса
            StreamReader srIncoming = procCommand.StandardOutput;
            // закрываем процесс
            procCommand.WaitForExit();
            // выводим результат
            textBox3.Text = srIncoming.ReadToEnd();
        }
    }
}

If you run from Visual Studio via F5 and when you click the button everything works
5c6d1f1ebf366166906562.png
If you do "Build solution" and from the folder C:\Users\pupkin\source\repos\WindowsFormsApp1\WindowsFormsApp1\bin\Debug copy my WindowsFormsApp1.exe to the desktop or another PC, then when you click on the button, nothing happens, but the form opens again ... and so on ..
5c6d24b5d43f1259655193.png
How to win? What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pavlov, 2019-02-20
@sHARek

And if you copy the entire folder C:\Users\pupkin\source\repos\WindowsFormsApp1\WindowsFormsApp1\bin\Debug and run the executable from there?
When creating a finished program, it is better to choose the Release build configuration, and then the entire C:\Users\pupkin\source\repos\WindowsFormsApp1\WindowsFormsApp1\bin\Release folder will become the distribution kit of the program, especially all dlls. You can try to remove the "extra" files from the folder, but .exe and .dll are all usually needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question