C#execute system命令无法正常工作 [英] C# execute system command doesn't work correctly

查看:55
本文介绍了C#execute system命令无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友。

i有一个Windows窗体,想要在程序启动时,Explorer.exe禁用,当用户点击特定按钮时,explorer.exe启动并正确显示任务栏和启动菜单。

这是我的问题:当我的程序开始工作时,explorer.exe正确禁用并且没有问题。但是当我点击button1时,只显示我的文档窗口,任务栏和开始菜单都是不可见的。请注意,当我通过cmd启动explorer.exe时没有任何问题,任务栏和开始菜单变得可见,但是当我用c#执行相同的命令时,只显示我的文档窗口。

这里是我的代码:

hello friends.
i have a windows form and want to when a program start, Explorer.exe disable and when user click on specific button, explorer.exe starts and show taskbar and start menu correctly.
here is my problem: when my program starts working, explorer.exe disable correctly and there is no problem.but when i click button1, just "My Document" window appear and taskbar and start menu are invisible. note that when i start explorer.exe by cmd there is not any problem and taskbar and start menu become visible, but when i execute same command by c#, just my document window appear.
here is my code:

  public Form1()
        {
            InitializeComponent();
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new    System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C Taskkill /IM explorer.exe /F";//command for kill explorer.exe process
            process.StartInfo = startInfo;
            process.Start();

        }

private void button1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/C explorer.exe /F";//command for start explorer.exe
            process.StartInfo = startInfo;
            process.Start();

        }





请有人帮助我。

提前感谢。



please someone help me.
thanks in advance.

推荐答案

首先,Explorer.exe是你不要用的过程之一。



命令行启动它是explorer.exe,而不是CMD / C explorer.exe / F。



/ F开关在资源管理器中无效。它或任何其他无效开关将强制资源管理器打开为当前用户打开MyDocuments的单个窗口。它不会使用完整的桌面启动整个Explorer进程。



当您尝试重新启动时,无法保证整个Explorer进程(带桌面)将正确启动它。无法修复任何此类情况,因为您必须重新启动Windows才能使其再次正常工作。
First, Explorer.exe is one of those process that you DO NOT SCREW WITH.

The command line to launch it is "explorer.exe", not "CMD /C explorer.exe /F".

The /F switch is not valid in Explorer. It, or any other invalid switch, will force Explorer to open a single window opened to MyDocuments for the current user. It will not start the entire Explorer process with a complete desktop.

There is no guarantee that the entire Explorer process (with desktop) will launch correctly when you try to restart it. There is no way to fix any such situation as you have to restart Windows to get it to work correctly again.


这篇关于C#execute system命令无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆