How do I open files without specifying the program

How can I open a file from vb without knowing which program you have to start. I want it automatically to use the registered program. f.e filename.doc => word / filename.pdf => Adobe Acrobat.

You can do this via start -> RUN.
So I Think It must be possible via VB also
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
You can use this code here:

Public Sub OpenWithShellExecute(                                         ByVal pstrOperation As String, _
                                         ByVal pstrFichierAOuvrir As String)

'pstrOperation can be "Print" or "Open"
Dim lngResult As Long
Dim strDir As String

    lngResult = ShellExecute(me.Hwnd, pstrOperation, pstrFichierAOuvrir, vbNullString, "", IIf(pstrOperation = "Print", SW_HIDE, SW_SHOW))

    'If the function fails, the return value is an error value that is less than or equal to 32.
    If lngResult >= 33 Then Exit Sub
    Select Case lngResult
            MsgBox "Le document est introuvable (" & pstrFichierAOuvrir & ").", vbExclamation + vbOKOnly
        Case SE_ERR_NOASSOC
            MsgBox "Ce type de document n'est pas ASSOCIÉ à une application Windows." & vbCrLf & vbCrLf & "Appuyer sur le bouton OK et vous pourrez l'associer.", vbExclamation + vbOKOnly
            strDir = Space$(260)
            lngResult = GetSystemDirectory(strDir, Len(strDir))
            strDir = Left$(strDir, lngResult)
            Call ShellExecute(me.Hwnd, vbNullString, "RUNDLL32.EXE", "shell32.dll,OpenAs_RunDLL " & pstrFichierAOuvrir, strDir, vbNormalFocus)
        Case Else
            MsgBox "Un problème empêche d'ouvrir ce document( " & pstrFichierAOuvrir & "). (Code: " & lngResult & ")", vbCritical + vbOKOnly
    End Select
End Sub
Try this:

FileName = "" 'The file to open
Shell "start.exe " + FileName

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you're doing to use the shell "start" command, do it this way:

FileName = "" 'The file to open
shell "start.exe " & FileName, vbHide

That way you don't get that annoying DOS box that pops up to run start.exe.  Also keep in mind that not all systems have start.exe on them.  

Personally I would do it this way:

Private Const SW_SHOWNORMAL = 1
Private Declare Function GetDesktopWindow Lib "user32" () As Long
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

Private Sub Command1_Click()
   Dim Scr_hDC As Long
   Dim DocName As String
   On Error Resume Next
   DocName = ""
   Scr_hDC = GetDesktopWindow
   LaunchDocument = ShellExecute(Scr_hDC, "Open", DocName, "", "C:\", SW_SHOWNORMAL)
End Sub

If you use this, please reject the current answer and accept this comment as the answer...

Hope this helps!

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

By the way, in both my examples you can replace the URL references with filenames... for example:

   DocName="My Word Doc.doc"

"HOWTO: Use ShellExecute to Launch Associated File"
FrancisIdeAuthor Commented:
I didn't use the simple way. Start.exe but used the API function.

Thanks for the help you all

Did you use the API example as defined in my comment?  If so, you awarded the points to the wrong person...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.