Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 47,379 times

Contents

Related Categories

Advanced Files & Folders - Default Programs

Default Programs

It is quite simple to open a file using its default program (for example, if you double click a *.doc file in explorer, Word will automatically load. You do this using the ShellExecute function. This also allows you to open a browser with the specified URL, or an write a new email, to the specified email address:

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

'// open file (quotes are used so that the actual value that is passed is "C: est.doc"
Private Sub cmdOpen_Click()
    If ShellExecute(0, vbNullString, """"C: est.doc"""", vbNullString, vbNullString, vbNormalFocus) = 2 Then
End Sub

'// open url
Private Sub cmdOpen_Click()
    If ShellExecute(0, vbNullString, "http://www.vbweb.f9.co.uk/", vbNullString, vbNullString, vbNormalFocus) = 2 Then
End Sub

'// open email address
Private Sub cmdOpen_Click()
    If ShellExecute(0, vbNullString, "mailto:support@vbweb.f9.co.uk", vbNullString, vbNullString, vbNormalFocus) = 2 Then
End Sub

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [38] Advanced Files & Folders

    Posted by unitled on 28 Jul 2006

    Okay, I've used the 'List all files in a directory' code (with a few slight modifications) but whenever I reboot the computer, it stops finding the files that are there (other than that, it works fine...

  • Posted by HyperHacker on 26 Nov 2004

    I think you use the FOF_SILENT flag. Been a while since I did it though.

  • Posted by HyperHacker on 26 Nov 2004

    I think you use the FOF_SILENT flag. Been a while since I did it though.

  • How does one actually Undo?

    Posted by vor0nwe on 22 Sep 2004

    Hi,

    This code snippet works all right. What I’m looking for, however, is how to actually Undo a file operation? I can’t find any way to do that by code...

    Thanks for all tips!

    vor0nwe

  • Minor bugs

    Posted by RobCrombie on 08 Aug 2004

    Hi,
    Couple of small bugs -

    Change Dim sPath As String to strPath

    Change "" to "\" in two lines -
    sStartDir = Left$(sFile, InStrRev(sFile, ""))
    '// just get filename
    ...