1

Im creating the file msinfo :

ProcessRun.Processing(contentDirectory, "msinfo32.exe" , "/nfo " + "\"" + contentDirectory + "\\msinfo.nfo" + "\"",false,"");

This is the class that create and usig the process to create the file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;

namespace Diagnostic_Tool_Blue_Screen
{
    class ProcessRun
    {


        public void ProcessesRun()
        {

        }

        public static void Processing(string WorkingDirectory, string FileName, string Arguments, bool StandardOutput, string OutputFileName)
        {
            Process proc = new Process();
            proc.EnableRaisingEvents = true;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardOutput = StandardOutput;
            proc.StartInfo.FileName = FileName;
            proc.StartInfo.CreateNoWindow = true;
            proc.StartInfo.WorkingDirectory = WorkingDirectory;
            proc.StartInfo.Arguments = Arguments;
            proc.Start();
            if (StandardOutput == true)
            {
                string output = proc.StandardOutput.ReadToEnd();
                DumpOutput(WorkingDirectory + "\\" + OutputFileName, output);
            }
            proc.WaitForExit();
            proc.Close();
        }

        private static void DumpOutput(string filename, string output)
        {
            StreamWriter w = new StreamWriter(filename);
            w.Write(output);
            w.Close();
        }
    }
}

Once the process start and running the msinfo32.exe there is a small window showing the process of the msinfo32.exe in the middle of the screen.

Its not the cmd window ! Its part of the msinfo32.exe Is there any way to hide this window while its Processing ?

enter image description here

Edited an image showing on the left my program and next to it on the right the small window of the msinfo32.exe that i want to hide.

4

3 回答 3

0

您可以使用本机功能ShowWindow。您需要查看 pinvoke 以了解如何使用它,否则我很乐意为您提供代码片段。

于 2013-08-01T15:23:12.297 回答
0

你能补充一下:

 proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
于 2013-08-01T15:23:47.643 回答
0

您可以通过引用user32.dll来隐藏窗口。

虽然窗口会出现很短的时间,但可以防止用户意外触摸取消按钮。

using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

namespace Diagnostic_Tool_Blue_Screen
{
    public class GetSystemInfo
    {
        [DllImport("user32.dll")]
        private static extern int FindWindow(string className, string windowText);

        [DllImport("user32.dll")]
        private static extern int ShowWindow(int hwnd, int command);

        public void GetInfo(string path)
        {
            using (Process exeObj = new Process())
            {
                exeObj.StartInfo.FileName = "msinfo32.exe";
                exeObj.StartInfo.Arguments = string.Format("{0}{1}{2}", "/nfo ", path, @"\mysysinfo.nfo");

                exeObj.StartInfo.UseShellExecute = false;
                exeObj.StartInfo.RedirectStandardInput = true;
                exeObj.StartInfo.RedirectStandardOutput = true;
                exeObj.EnableRaisingEvents = true;
                exeObj.Start();
                exeObj.BeginOutputReadLine();
                exeObj.Close();
            }

            Thread.Sleep(1000);
            const int SW_HIDE = 0;

            int hwnd = FindWindow(null, "System Information");

            if (hwnd != 0)
            {
                var num = ShowWindow(hwnd, SW_HIDE);
            }
        }
    }
}
于 2018-08-22T04:18:06.730 回答