All posts for the year 2009

VB.NET class for running process/application as background thread:

Public Class Shell
   Private Process1 As Process = New Process()
   Sub New()
   End Sub
   Public ReadOnly Property Active() As Boolean
         Return Process1.HasExited
      End Get
   End Property
   Public Sub Run(ByVal sProcessPath As String, ByVal sArguments As String)
      Process1.StartInfo.FileName = sProcessPath
      Process1.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
      Process1.StartInfo.CreateNoWindow = False
      Process1.StartInfo.UseShellExecute = True
      Process1.EnableRaisingEvents = True
      Process1.StartInfo.Arguments = sArguments
         'Start Process
      Catch ex As Exception
      End Try
   End Sub
   Private Sub Wait()
      If Not Process1.HasExited Then
      End If
   End Sub
End Class

Example for transparent printing txt file:

Dim sproc As New Shell
sproc.Run("notepad", " /p c:\test\example.txt" )

Example for transparent printing pdf  file with FoxitReader :

Dim pdfAppPath as String = String.Empty
Dim progamsfolder As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
If File.Exists(progamsfolder & "\Foxit\FoxitReader.exe") Then pdfAppPath = progamsfolder & "\Foxit\FoxitReader.exe"
Dim sproc As New Shell
sproc.Run(pdfAppPath, " /p c:\test\example.pdf")