We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How can I programmatically extract cabinet (CAB) files in Visual Basic .NET (not VB6)

gregorylambert
on
Medium Priority
1,515 Views
Last Modified: 2008-01-09
I am using VB.NET (VS 2005) and I am looking for either sample code or controls (commercial or free) that will provide programmatic access to extracting files from specified Cabinet (CAB) files.

I understand that there are samples for VB6 - however these samples do not upgrade to VB.NET (as far as I have tried) and I am looking for a strong .NET solution.

Comment
Watch Question

Alexandre SimõesSoftware Architect
CERTIFIED EXPERT
Commented:

If you open a commandprompt window write Makecab and press Return, you'll see that there's a DOS command that does just what you need.
You just have to call it and pass the arguments you want:

     System.Diagnostics.Process.Start("MAKECAB.EXE", "c:\\myFile.txt");

Take a look at the MAKEBAB...

Alex :p

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Actually to extract files from a Cabinet file, you need the EXTRACT command:

EXPAND -D cab1.cab -F:file.txt

Also, this is a VB.NET question.

Bob
Alexandre SimõesSoftware Architect
CERTIFIED EXPERT

Commented:

Ups... sorry mate... at 02:08AM I may start confusing! :)

Alex :p

Author

Commented:
Hi,

Thanks for taking the time to answer my question. This solution "works" but it is the one that I am trying to avoid. I am trying to get a fully .NET solution developed and I am trying to avoid "shelling out" to external executables.

Hopefully, I made that clear in the question "header/title" - don't want to waste anybodys time.

I am going to raise the points for this solution -I am pretty keen to get a .NET CAB control or sample code.

cheers,

g

Author

Commented:
Hi,

With reference to the shell out to EXTRACT command, here is the sample code that I "don't" want to use (my preference is a .NET control):

Here is the sample code for shelling out to the MS windows 2000 reskit CAB expanding EXTRACT tool

        Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process()
        myProcess.StartInfo.FileName = "C:\Program Files\Resource Kit\extract.exe /c c:\temp\extract\orca.cab *.*"
        myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
        myProcess.Start()

This sample allows the VB app to still have some control over the process (i.e. it waits for the extraction to finish before moving on to the next thing) and even hides the window so user thinks that everything is "cool" - no dodgy black pop-up windows.

cheers,

g
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
You need to specify the filename separate from the arguments:

  myProcess.StartInfo.FileName = "C:\Program Files\Resource Kit\extract.exe"
  myProcess.StartInfo.Arguments = " /c c:\temp\extract\orca.cab *.*"
  myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden

Bob  

Author

Commented:
Bob,

Thanks for the comments on the command line arguments. I eventually figured that one out this morning.

However, this is the solution I don't want.

:)

Any ideas on a .NET solution? I have now raised the pot to 500 points - Whooho!

I would greatly appreciate any help on pursuing the .NET solution.

cheers,

g
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
I don't know of any .NET solution for 2.0.

Bob
Alexandre SimõesSoftware Architect
CERTIFIED EXPERT
Commented:
Hi...
Why don'y you want this solution?

The only possible reason I can think is because the computer eventually may not have that EXPAND.EXE file...
To prevent a possible error you can copy the exe to the app exe folder and access it as:

        Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process()
        myProcess.StartInfo.FileName = System.Windows.Forms.Application.StartupPath + "\\extract.exe /c c:\temp\extract\orca.cab *.*"
        myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
        myProcess.Start()


As my opinion for that .net solution you want...
I don't know any, and if it exists it's for sure just a wrapper around that Expand.exe file.

Alex :p
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.