Monday, July 28, 2008

Run an application from a VB.NET program

Ahhhhh, today I'm a bit bored so I thought to my self why not post a small module for VB.NET that will run an application from within a Visual Basic program.

Ok, you may say "bigggggg deeeallll!!", but hey I'm bored. So here it is:

'======================================

Module modRunMe
Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process
Public Sub RunMe(ByVal fileName As String)
Try
myProcess.StartInfo.FileName = fileName
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
myProcess.Start()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try
End Sub
End Module

'======================================

You can call it like this:

RunMe("c:\temp\TheTestPdfFile.PDF"). And it will run the PDF file or any file that you want (just as long as there is a program associated with it).

If you find it useful let me know, and you never know I might upload more code. AHAHHAHAHAHAH (sound of crackling thunder on the background)

No comments: