UGPC Utility to Listing Window

This is an edit of the example from Convert Part Units Submitted by NXJournaling.
Because I am not experienced, I ran in to some issues, but solved.
You can respond and clean up this code so it is better.

Option Strict Off
' NX 10
' Date: 4/23/2018
' Subject: UGPC Utility to Listing Window
Imports System
Imports System.Diagnostics
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module startup

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
Public theUISession As UI = UI.GetUI
Public workPart As Part = theSession.Parts.Work
Public partPath As String = workPart.FullPath
Public partName As String = System.IO.Path.GetFileName(partPath)
Public copyPart As String = System.IO.Path.Combine(System.IO.Path.GetTempPath, partName)
Public response As Integer

Sub Main()

Dim rm As RemoteUtilities = RemoteUtilities.GetRemoteUtilities()

Dim baseDir As String = Environment.GetEnvironmentVariable("UGII_BASE_DIR")
' lw.WriteLine("UGII_BASE_DIR = " & baseDir)
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
'Utility to run
'Dim UtilityUGPC As String = baseDir & "\" & "ugpc.exe"
Dim UtilityUGPC As String = baseDir & "\NXBIN\" & "ugpc.exe"
Dim unitArg As String = "-s"
unitArg = " " & unitArg & " "

IsPrtMod()

' ----------- Use the Remote Utility ------------
Dim utilitySuccess As Boolean = False
Try

Dim utilityProcess As New Process

Dim myStartInfo As New ProcessStartInfo
myStartInfo.UseShellExecute = False
myStartInfo.CreateNoWindow = True
' The command
myStartInfo.FileName = """" & UtilityUGPC & """" & unitArg & """" & partPath & """"
myStartInfo.RedirectStandardOutput = True
myStartInfo.RedirectStandardError = True

'test
lw.WriteLine("Running: " &myStartInfo.FileName)
utilityProcess.StartInfo = myStartInfo
utilityProcess.Start()

Dim std_out As IO.StreamReader = utilityProcess.StandardOutput()
Dim std_err As IO.StreamReader = utilityProcess.StandardError()

Dim stdOutput As String = std_out.ReadToEnd
Dim stdLines() As String = stdOutput.Split(ControlChars.CrLf)

For Each Line As String In stdLines
If Line.ToUpper.Contains("SUCCESS") Then
utilitySuccess = True
End If
' To Listing Window
If Line IsNot Nothing Then
Line = Line.Replace(vbCr, "").Replace(vbLf, "") ' removing return character
lw.WriteLine(Line)
Else
End If
Next

Dim stdError As String = std_err.ReadToEnd
If Not String.IsNullOrEmpty(stdError) Then
lw.WriteLine("")
lw.WriteLine("stdErr:")
For Each Line As String In stdError
lw.WriteLine(Line)
Next
End If

std_out.Close()
std_err.Close()
utilityProcess.Close()

Catch ex As Exception

lw.WriteLine("Error with ug_convert_part.exe")
lw.WriteLine(ex.GetType.ToString & " : " & ex.Message)

End Try

End Sub

'----------------------------------- Function ----------------------------------------
Public Function IsPrtMod()

Dim messages(4) As String
messages(0) = "The part, " & partName & " shows that it is modified and"
messages(1) = "is not saved locally for this function:"
messages(2) = " "
messages(3) = " Would you like to save the current work part?"
messages(4) = " "

If ufs.Part.IsModified(workPart.Tag) Then
response = theUISession.NXMessageBox.Show("Save current changes?", theUISession.NXMessageBox.DialogType.Question, messages)

If response = 1 Then
'save
Dim partSaveStatus1 As PartSaveStatus
partSaveStatus1 = workPart.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False)
partSaveStatus1.Dispose()
' workPart.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.UseResponses, Nothing)
' workPart = Nothing

Else

End If

Else

End If

End Function

'-------------------------------------------------------------------------------------

'----------------------------------- Function ----------------------------------------
Public Function GetUnloadOption(ByVal dummy As String) As Integer

Return Session.LibraryUnloadOption.Immediately

End Function
'-------------------------------------------------------------------------------------

End Module