Running external zip utility  - command line error

Posted on 2006-04-12
Last Modified: 2010-05-18
I’ve been attempting to launch a zip utility from C#.NET code.  Unfortunately, the 7-Zip utility that I’m using doesn’t like the command line string that I’m passing in.  Without getting into the switch syntax for this utility, I can tell you that the command line in the code below works when the utility is launched from the command prompt, so no problem there.

Here’s the sample code:

using System.Diagnostics;

private void btnZipMe_Click(object sender, System.EventArgs e)
    string strCmdLine = @"7z a -tzip c:\backups\ \a\*.doc";        
    ProcessStartInfo psi = new ProcessStartInfo();

    psi.FileName = @"C:\Program Files\7-Zip\7zG.exe";
    psi.Arguments = strCmdLine;
    Process p = Process.Start(psi);

When the last line of code above executes, the external utility pops up a message box stating “Incorrect command line” . Additionally, just as a test, I also set up everything under my C: drive to avoid escape characters even though the literal symbol should handle that – same error. Any ideas?

Question by:tmccallister
    LVL 1

    Expert Comment

    watch out for the \ escaping \. I mean use \\ instead of \

    LVL 85

    Accepted Solution

    Shot in the dark...

    Try setting the Working directory and starting it this way:

            Process p = new Process();
            p.StartInfo.FileName = @"C:\Program Files\7-Zip\7zG.exe";
            p.StartInfo.Arguments = @"7z a -tzip c:\backups\ \a\*.doc";
            p.StartInfo.WorkingDirectory = @"C:\Program Files\7-Zip\";
    LVL 11

    Expert Comment

    And another run at it...

      private void btnZipMe_Click(object sender, System.EventArgs e)
        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = @"C:\Program Files\7-Zip\7z.exe";
        psi.Arguments = @"a -tzip ""c:\backups\"" ""c:\FULL_PATH\a\*.doc""";
        Process p = Process.Start(psi);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now