Question

This question is related to this initial question asked a little while ago.

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);
            }
    }
}

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:

How to avoid the Windows (XP) Security Warning when launching a "DOS" command line within C#?

Was it helpful?

Solution

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);
            }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top