views:

83

answers:

2

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#?

A: 

Did you download the file? There should be a checkbox where you can disable the warning. This has nothing to do with .net.

Femaref
I know there's a CheckBox within the prompted dialog. My question is about how to avoid to get this dialog, so that the user does not have to check or uncheck it. And as long as I write the code in .NET, this has something to do with it, since there might be a way in .NET to accomplish what I want to. Plus, this has nothing to do with downloading, since I provide the the 7za.exe command line compression tool with my application.
Will Marcouiller
I think what @Femaref is saying, is if you downloaded 7za.exe with a browser, rather than say extracting it from a zip file, or installing it from an installer, then you will get a warning because the file was tagged as a potential threat when it was downloaded.The tag is in the NTFS meta-data somewhere, though I'm not sure of the details. You can avoid the problem on your machine by using the check-box and on other machines by distributing it in some other manner.
ScottS
@ScottS: Nice explanation. Thanks to have made it clear. I remember of such security "issues" while downloading and unzipping files, etc. You're right about that. And if it is what our friend @Femaref meant, than I thank him for remembering me.
Will Marcouiller
yes, this is what I meant.
Femaref
+1  A: 

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);
            }
    }
}
dirtmike
Another way around this is by signing your exe if you can figure out how to do thatlink - http://www.csharp411.com/net-assembly-faq-part-3-strong-names-and-signing/
dirtmike