How to hide command prompt during Self-Extract

Aug 20, 2009 at 8:55 PM

Hello,

I have created a self extracting executable using the following code:

 

                // Create a new zip file instance
                using (ZipFile zip = new ZipFile())
                {
                    // Set the password, encryption type, and comment
                    zip.Password = password;
                    zip.Encryption = EncryptionAlgorithm.WinZipAes256;
                    zip.Comment = "This program contains a zipped archive of your Patient Health Information.  The sensitive nature of this data requires the security and encryption provided within.  To extract the data, you will be required to provide the password originally used to secure it.  Please contact your physician's office if you have problems accessing your data.";
                    // If a byte array was sent in then add it
                    if (fileByteArray != null)                    
                        zip.AddEntry(fileName, "", fileByteArray);                    
                    // Else if a path to a file was sent in then add it
                    else if (fileNameWithPath != string.Empty)                    
                        zip.AddFile(fileNameWithPath, "");
                    // Else if we have an array of file names
                    else if (fileNameWithPathArray != null)
                    {
                        // Loop through each of the files in the array
                        foreach (string currentFileName in fileNameWithPathArray)
                        {
                            // Add the file to the zip archive
                            zip.AddFile(currentFileName, "");
                        }
                    }
                    // Create the self extracting zip
                    zip.SaveSelfExtractor(textBoxFolder.Text + "\\" + "Patient Data Self Extractor.exe", SelfExtractorFlavor.WinFormsApplication);
                    // Close the dialog
                    this.Close();
                }

                // Create a new zip file instance

                using (ZipFile zip = new ZipFile())

                {

                    // Set the password, encryption type, and comment

                    zip.Password = password;

                    zip.Encryption = EncryptionAlgorithm.WinZipAes256;

                    // If a byte array was sent in then add it

                    if (fileByteArray != null)                    

                        zip.AddEntry(fileName, "", fileByteArray);                    

                    // Create the self extracting zip

                    zip.SaveSelfExtractor(textBoxFolder.Text + "\\" + "Self Extractor.exe", SelfExtractorFlavor.WinFormsApplication);

                    // Close the dialog

                    this.Close();

                }

 

When I run the executable that is created I end up seeing a command prompt behind the form.  I was under the impression that setting the SelfExtractorFlavor to WinFormsApplication was what controls the hiding and showing of the command prompt.

Maybe there is a bug in the application or I may not be doing something quite right.

Anyone have any ideas?

 

Thanks

Fred

Coordinator
Aug 20, 2009 at 9:34 PM
Edited Aug 20, 2009 at 9:35 PM

How are you running the executable that is created?  Are you doing this from code?  in a WinForms app?  Can you show me the code? 

Coordinator
Aug 20, 2009 at 9:45 PM
Edited Aug 20, 2009 at 9:52 PM

If you use the System.Diagnostics.Process class, and specify in the StartInfo, WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden, you won't get a window in the background. Example:

private void button_Click(object sender, EventArgs e)
{
    p = new System.Diagnostics.Process
    {
        StartInfo = new System.Diagnostics.ProcessStartInfo
        {
            WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
            FileName = @"c:\dinoch\dev\dotnet\zip\test\CreateSfx2-console-archive.exe",
            Arguments = "-o"
        }
    };
    p.Start();
    //p.WaitForExit(); // optional
}

This has nothing to do with DotNetZip. It's a feature of System.Diagnostics.Process.

Setting the SelfExtractorFlavor to WinFormsApplication, and running the resulting exe, will cause a Windows GUI to be displayed.  It's not a command prompt.  It's a small windows application with a few buttons on it.   Example:

If you use WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden with a SFX that is a WinFormsApplication, and launch it the same way, no window will be displayed, and no files will be extracted.  The self-extracting GUI app will just run, invisibly, waiting for a button click that never comes.

Aug 20, 2009 at 10:12 PM
Cheeso wrote:

How are you running the executable that is created?  Are you doing this from code?  in a WinForms app?  Can you show me the code? 

Hey Cheeso,

Using the code in my original question I end up creating an executable.  We plan on the end user simply double clicking on this .exe file in order to run the self extractor like the one you've shown.  When the user double clicks on the file I see the self-extractor but behind it I see the command window that I mentioned.

Thanks for your quick responses.

Fred

Coordinator
Aug 20, 2009 at 10:24 PM

ok, I see what you mean.

Coordinator
Aug 20, 2009 at 10:37 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Aug 21, 2009 at 4:45 PM

This is fixed in v1.8.4.21.  available now.

Aug 22, 2009 at 10:43 PM

Thanks for the quick attention to this.  Very appreciated.

 

Fred