Results 1 to 10 of 10

Thread: Opening Files Through Their Default Application...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    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.

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Opening Files Through Their Default Application...

    Use ShellExecute API. This API will open the file in the associated application.
    VB Code:
    1. Option Explicit
    2. 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
    3. Const SW_SHOWNORMAL = 1
    4. Private Sub Form_Load()
    5.     ShellExecute Me.hwnd, vbNullString, "C:\Test.doc", vbNullString, "C:\", SW_SHOWNORMAL
    6. End Sub
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Opening Files Through Their Default Application...

    but a zip file will be opened in explorer rather than by the default UnZipping app.

  4. #4
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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.

  6. #6
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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

    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.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    10

    Re: Opening Files Through Their Default Application...

    Thanks a lot guys, this code is excellent and is just what I was looking for!

  9. #9
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking 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.
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  10. #10
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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!
    Like Archer? Check out some Sterling Archer quotes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width