Get IWin32Window for the main window of Visual Studio

This is a way to wrap the main window of Visual Studio in a klass that implements the IWin32Window interface.

Public Class MainWinWrapper
    Implements System.Windows.Forms.IWin32Window
    Overridable ReadOnly Property Handle() As System.IntPtr _
            Implements System.Windows.Forms.IWin32Window.Handle
        Get
            Dim iptr As New System.IntPtr(DTE.MainWindow.HWnd)
            Return iptr
        End Get
    End Property
End Class

This is useful for example when Visual Studio should be used as the owner of a MessageBox.

Dim res As DialogResult
res = MessageBox.Show(New MainWinWrapper(), "Hello!")

The code was found here.

Start process and redirect output

Function GetProcessText(ByVal process As String, ByVal param As String, _
        ByVal workingDir As String) As String
    Dim p As System.Diagnostics.Process = New System.Diagnostics.Process

    ' this is the name of the process we want to execute 
    p.StartInfo.FileName = process
    If Not (workingDir = "") Then
        p.StartInfo.WorkingDirectory = workingDir
    End If
    p.StartInfo.Arguments = param

    ' need to set this to false to redirect output
    p.StartInfo.UseShellExecute = False
    p.StartInfo.RedirectStandardOutput = True

    ' start the process 
    p.Start()

    ' read all the output
    ' here we could just read line by line and display it
    ' in an output window 
    Dim output As String = p.StandardOutput.ReadToEnd
    ' wait for the process to terminate 
    p.WaitForExit()
    Return output
End Function

Code from http://www.developerfusion.co.uk/show/4662/.