如何在启动“DOS”时避免Windows(XP)安全警告。命令行在C#中? [英] How to avoid the Windows (XP) Security Warning when launching a "DOS" command line within C#?

查看:279
本文介绍了如何在启动“DOS”时避免Windows(XP)安全警告。命令行在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与这个初始问题有关。 。

现在,我已经选择了提取工具,我通过一个给定的命令行参数目录和子目录中提取压缩的.zip文件。 p>

Now, that I have chosen the extracting tool, I'm iterating through a given in command line parameter directory and subdirectories to extract the compressed .zip files.

private static void ExtractAll(DirectoryInfo _workingFolder) {
    if(_workingFolder == null) {
        Console.WriteLine("Répertoire inexistant.");
        return;
    }

    foreach (DirectoryInfo subFolder in _workingFolder.GetDirectories("*", SearchOption.AllDirectories)) 
        foreach(FileInfo zippedFile in subFolder.GetFiles("*.zip", SearchOption.AllDirectories)) {
            if(zippedFile.Exists) {
                ProcessStartInfo task = new ProcessStartInfo(@".\Tools\7za.exe", string.Format("x {0}", zippedFile.FullName));
                Process.Start(task);
            }
    }
}

但每次我开始一个7za进程,Windows安全警告提示。我想避免这种恼人的行为,所以这里是我的问题:

But everytime I start a 7za process, the Windows Security Warning prompts. I would like to avoid such annoying behaviour, so here's my question:

如何避免Windows(XP)安全警告启动DOS命令行

推荐答案

这是最好的猜测(没有时间去尝试)也许可以尝试使用CreateNoWindow?

This is a guess at best(don't have the time to try), but maybe try using CreateNoWindow?

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.createnowindow.aspx

这里是使用建议的解决方案后的代码:

Here's the code after using the proposed solution:

private static void ExtractAll(DirectoryInfo _workingFolder) {
    if(_workingFolder == null) {
        Console.WriteLine("Répertoire inexistant.");
        return;
    }

    foreach (DirectoryInfo subFolder in _workingFolder.GetDirectories("*", SearchOption.AllDirectories)) 
        foreach(FileInfo zippedFile in subFolder.GetFiles("*.zip", SearchOption.AllDirectories)) {
            if(zippedFile.Exists) {
                Console.WriteLine(string.Format("Extraction du fichier : {0}", zippedFile.FullName));
                Process task = new Process();
                task.StartInfo.UseShellExecute = false;
                task.StartInfo.FileName = @".\Tools\7za.exe";
                task.StartInfo.Arguments = string.Format("x {0}", zippedFile.FullName);
                task.StartInfo.CreateNoWindow = true;
                task.Start();
                Console.WriteLine(string.Format("Extraction de {0} terminée", zippedFile.FullName));
                //ProcessStartInfo task = new ProcessStartInfo(@".\Tools\7za.exe", string.Format("x {0}", zippedFile.FullName));
                //Process.Start(task);
            }
    }
}

这篇关于如何在启动“DOS”时避免Windows(XP)安全警告。命令行在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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