Opening Files Through Their Default Application...
Hi, I have a program with of files that I want to be able to access. Most of these are executable files so I have no problems in accessing them with the Simple shell filename command. However, I've just learned that this doesn't work with the zip files in the list. How could I make my application open a zip file with the computers default application? So it I had winzip on my computer for example, clicking on the zip in my application would bring up winzip with the file as a parameter. Thanks for any help. Regards,
Rich.
Re: Opening Files Through Their Default Application...
Use ShellExecute API. This API will open the file in the associated application.
VB Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
Private Sub Form_Load()
ShellExecute Me.hwnd, vbNullString, "C:\Test.doc", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
Re: Opening Files Through Their Default Application...
but a zip file will be opened in explorer rather than by the default UnZipping app.
Re: Opening Files Through Their Default Application...
Quote:
Originally Posted by bushmobile
but a zip file will be opened in explorer rather than by the default UnZipping app.
I am afraid no.
It will open the associated WinZip (or some other zipping utility) application.
Re: Opening Files Through Their Default Application...
If the user has a zipping utility set up as the default association then maybe.
but in XP the built in Extraction Wizard is not the default option - opening in explorer is.
Re: Opening Files Through Their Default Application...
Quote:
Originally Posted by bushmobile
If the user has a zipping utility set up as the default association then maybe.
Correct :thumb:
Quote:
Originally Posted by bushmobile
but in XP the built in Extraction Wizard is not the default option - opening in explorer is.
I have Winzip installed so I tried it with that. Didn't try it without Winzip on XP.
Re: Opening Files Through Their Default Application...
you could always check if computer is running XP and if they are then use the built-in extractor, and on other systems use shellexecute.
Re: Opening Files Through Their Default Application...
Thanks a lot guys, this code is excellent and is just what I was looking for! :wave:
Re: Opening Files Through Their Default Application...
Is there a way to do this with a .reg file, but have it automatically ammend the files content's to the registry, without a promt asking if the user want's to (e.g. an instalation)(just a simpler way of adding registry files)? And please don't tell me of some other way to acomplish this, I have many other ways already, I was just wondering if this was another way that could easily be made to work.
Re: Opening Files Through Their Default Application...
I don't believe so, unless you send an enter key to get rid of the prompt yourself. It's a security risk of sorts to allow you to add .reg files (which could be maliciously edited) to the registry without the permission of the user. When it's hard coded in, it's usually safer, or as safe as it could be, as long as the program was built with good intentions!