Results 1 to 7 of 7

Thread: Executing Another File

  1. #1

    Thread Starter
    New Member The Developer's Avatar
    Join Date
    Sep 2002
    Location
    London, England, UK
    Posts
    11

    Executing Another File

    Hi,

    How do I have windows open a certain file using its default program in VB.NET?

    In VB6, ShellExecute was used, but I am not too sure on how to do this in VB.NET...

    I am sure someone can help...

    Thanks
    The Developer

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    ms-help://MS.VSCC/MS.MSDNVS/vblr7/html/vafctShell.htm

  3. #3

    Thread Starter
    New Member The Developer's Avatar
    Join Date
    Sep 2002
    Location
    London, England, UK
    Posts
    11
    Erm...no wonder your called "Slow_Learner", I am looking for a way to execute ANY file not just an executable.

    The ShellExecute is not like the Shell() function in VB6 and VB.NET. ShellExecute is an API that I used back in VB6 days for opening ANY file.

    I am trying to do the same in VB.NET....

    Thanks anyway...
    The Developer

  4. #4
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Originally posted by The Developer
    Erm...no wonder your called "Slow_Learner", I am looking for a way to execute ANY file not just an executable.

    The ShellExecute is not like the Shell() function in VB6 and VB.NET. ShellExecute is an API that I used back in VB6 days for opening ANY file.

    I am trying to do the same in VB.NET....

    Thanks anyway...
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemDiagnosticsProcessClassStartTopic3.htm

    Remarks
    (...)
    Starting a process by specifying its file name is similar to typing the information in the Run dialog box of the Windows Start menu. Therefore, the file name does not need to represent an executable file. It can be of any file type for which the extension has been associated with an application installed on the system. For example the file name can have a .txt extenstion if you have associated text files with an editor, such as Notepad, or it can have a .doc if you have associated .doc files with a word processing tool, such as Microsoft Word. Similarly, in the same way that the Run dialog box can accept an executable file name with or without the .exe extension, the .exe extension is optional in the fileName parameter. For example, you can set the fileName parameter to either "Notepad.exe" or "Notepad".


    Don't be too rough on me for misreading your post and I won't be rough on you for not looking at your documentation

  5. #5
    Member BinaryAnge's Avatar
    Join Date
    Jun 2002
    Location
    Columbus,Ohio
    Posts
    51

    THE RIGHT WAY TO DO IT

    Private Sub MyProcess(ByVal FileToRun As String)
    Dim Proc As New Process()
    With Proc.StartInfo
    .FileName = FileToRun
    .ErrorDialog = True
    .ErrorDialogParentHandle = Me.Handle
    .UseShellExecute = True
    End With
    Try
    Proc.Start()
    Catch Ex As Exception
    End Try
    End Sub

    you only need to catch the exception, you dont need to handle it because it will be handled for you with the errordialog
    The Programmers Credo -
    Protect dumb-ass from himself.

  6. #6
    Member BinaryAnge's Avatar
    Join Date
    Jun 2002
    Location
    Columbus,Ohio
    Posts
    51
    this also give you the open with dialog for unknow file types
    The Programmers Credo -
    Protect dumb-ass from himself.

  7. #7

    Thread Starter
    New Member The Developer's Avatar
    Join Date
    Sep 2002
    Location
    London, England, UK
    Posts
    11
    Cheers!
    The Developer

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