VB.Net Tutorial/Development/Process

Материал из VB Эксперт
Перейти к: навигация, поиск

Display properties of current Process

Imports System.Diagnostics
Module Module1
    Sub Main()
        Dim objProcess As New Process()
        objProcess = Process.GetCurrentProcess()
        With objProcess
            Console.WriteLine("Base Priority {0}", .BasePriority)
            Console.WriteLine("Handle count {0}", .HandleCount)
            Console.WriteLine("Process ID (PID) {0}", .Id)
            Console.WriteLine("Machine Name {0}", .MachineName)
            Console.WriteLine("Main Module {0}", .MainModule)
            Console.WriteLine("Main Window Title {0}", .MainWindowTitle)
            Console.WriteLine("Max Working Set {0}", .MaxWorkingSet)
            Console.WriteLine("Min Working Set {0}", .MinWorkingSet)
            Console.WriteLine("Modules {0}", .Modules)
            Console.WriteLine("Nonpage System Memory Size {0}",.NonpagedSystemMemorySize)
            Console.WriteLine("Paged Memory Size {0}", .PagedMemorySize)
            Console.WriteLine("Paged System Memory Size {0}",.PagedSystemMemorySize)
            Console.WriteLine("Peak Paged Memory Size {0}",.PeakPagedMemorySize)
            Console.WriteLine("Peak Virtual Memory Size {0}",.PeakVirtualMemorySize)
            Console.WriteLine("Peak Working Set {0}", .PeakWorkingSet)
            Console.WriteLine("Priority Boost Enabled {0}", .PriorityBoostEnabled)
            Console.WriteLine("Priority Class {0}", .PriorityClass)
            Console.WriteLine("Private Memory Size {0}",.PrivateMemorySize)
            Console.WriteLine("Priviledged Processsor Time {0}",.PrivilegedProcessorTime)
            Console.WriteLine("Name {0}", .ProcessName)
            Console.WriteLine("Processor Affinity {0}", .ProcessorAffinity)
            Console.WriteLine("Start Time {0}", .StartTime)
            Console.WriteLine("Total Processor Time {0}", .TotalProcessorTime)
            Console.WriteLine("User Processor Time {0}", .UserProcessorTime)
            Console.WriteLine("Virtual Memory Size {0}", .VirtualMemorySize)
            Console.WriteLine("Working Set {0}", .WorkingSet)
        End With
    End Sub
End Module
Base Priority 8
Handle count 87
Process ID (PID) 3424
Machine Name .
Main Module System.Diagnostics.ProcessModule (main.exe)
Main Window Title
Max Working Set 1413120
Min Working Set 204800
Modules System.Diagnostics.ProcessModuleCollection
Nonpage System Memory Size 4508
Paged Memory Size 9330688
Paged System Memory Size 105068
Peak Paged Memory Size 9330688
Peak Virtual Memory Size 92123136
Peak Working Set 5308416
Priority Boost Enabled True
Priority Class Normal
Private Memory Size 9330688
Priviledged Processsor Time 00:00:00.0156250
Name main
Processor Affinity 1
Start Time 11/05/2007 9:33:28 PM
Total Processor Time 00:00:00.0781250
User Processor Time 00:00:00.0625000
Virtual Memory Size 92057600
Working Set 5308416

Get current Process

Imports System.Diagnostics
Module Module1
    Sub Main()
        Dim objProcess As New Process()
        objProcess = Process.GetCurrentProcess()
        With objProcess
            Console.WriteLine("Base Priority {0}", .BasePriority)
            Console.WriteLine("Handle count {0}", .HandleCount)
            Console.WriteLine("Process ID (PID) {0}", .Id)
            Console.WriteLine("Machine Name {0}", .MachineName)
            Console.WriteLine("Main Module {0}", .MainModule)
            Console.WriteLine("Main Window Title {0}", .MainWindowTitle)
            Console.WriteLine("Max Working Set {0}", .MaxWorkingSet)
            Console.WriteLine("Min Working Set {0}", .MinWorkingSet)
            Console.WriteLine("Modules {0}", .Modules)
            Console.WriteLine("Nonpage System Memory Size {0}",.NonpagedSystemMemorySize)
            Console.WriteLine("Paged Memory Size {0}", .PagedMemorySize)
            Console.WriteLine("Paged System Memory Size {0}",.PagedSystemMemorySize)
            Console.WriteLine("Peak Paged Memory Size {0}",.PeakPagedMemorySize)
            Console.WriteLine("Peak Virtual Memory Size {0}",.PeakVirtualMemorySize)
            Console.WriteLine("Peak Working Set {0}", .PeakWorkingSet)
            Console.WriteLine("Priority Boost Enabled {0}", .PriorityBoostEnabled)
            Console.WriteLine("Priority Class {0}", .PriorityClass)
            Console.WriteLine("Private Memory Size {0}",.PrivateMemorySize)
            Console.WriteLine("Priviledged Processsor Time {0}",.PrivilegedProcessorTime)
            Console.WriteLine("Name {0}", .ProcessName)
            Console.WriteLine("Processor Affinity {0}", .ProcessorAffinity)
            Console.WriteLine("Start Time {0}", .StartTime)
            Console.WriteLine("Total Processor Time {0}", .TotalProcessorTime)
            Console.WriteLine("User Processor Time {0}", .UserProcessorTime)
            Console.WriteLine("Virtual Memory Size {0}", .VirtualMemorySize)
            Console.WriteLine("Working Set {0}", .WorkingSet)
        End With
    End Sub
End Module
Base Priority 8
Handle count 87
Process ID (PID) 2988
Machine Name .
Main Module System.Diagnostics.ProcessModule (main.exe)
Main Window Title
Max Working Set 1413120
Min Working Set 204800
Modules System.Diagnostics.ProcessModuleCollection
Nonpage System Memory Size 4508
Paged Memory Size 9330688
Paged System Memory Size 105068
Peak Paged Memory Size 9330688
Peak Virtual Memory Size 92123136
Peak Working Set 5308416
Priority Boost Enabled True
Priority Class Normal
Private Memory Size 9330688
Priviledged Processsor Time 00:00:00.0312500
Name main
Processor Affinity 1
Start Time 11/05/2007 9:33:27 PM
Total Processor Time 00:00:00.0781250
User Processor Time 00:00:00.0468750
Virtual Memory Size 92057600
Working Set 5308416

Get Process by ID

Imports System.Diagnostics
Public Class Tester
    Public Shared Sub Main
        Dim pid As Integer = 12345
        Dim p As Process = Process.GetProcessById(pid)
        If p Is Nothing Then Return
        Try
            Console.WriteLine(p.Id.ToString())
            Console.WriteLine(p.ProcessName)
            Console.WriteLine(p.StartTime.ToLongTimeString())
            Console.WriteLine(p.PriorityClass.ToString())
            Console.WriteLine(p.VirtualMemorySize64.ToString())
            Console.WriteLine(p.WorkingSet64.ToString())
            If p.MainModule IsNot Nothing Then
                Console.WriteLine(p.MainModule.FileName)
                Console.WriteLine(p.MainModule.FileVersionInfo.FileDescription)
                Console.WriteLine(p.MainModule.FileVersionInfo.FileVersion)
            End If
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        Finally
            p.Close()
        End Try    
    End Sub
End Class
Unhandled Exception: System.ArgumentException: Process with an Id of 12345 is not running.
   at System.Diagnostics.Process.GetProcessById(Int32 processId, String machineName)
   at System.Diagnostics.Process.GetProcessById(Int32 processId)
   at Tester.Main()

Get thread count in current process

Imports System.Diagnostics
Module Module1
    Sub Main()
        Console.WriteLine("Thread Count: {0}", Process.GetCurrentProcess().Threads.Count)
    End Sub
End Module
Thread Count: 3

Kill current process

Imports System.Diagnostics
Module Module1
    Sub Main()
"       Process.GetCurrentProcess.Kill()
    End Sub
End Module

List all process in a ListView

Imports System.Diagnostics
Imports System.Windows.Forms
public class ProcessManager
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Private Sub ListProcesses()
        Dim ps() As Process
        Try
            ps = Process.GetProcesses()
            lvProcesses.BeginUpdate()
            lvProcesses.Clear()
            lvProcesses.Columns.Add("Name", 100, HorizontalAlignment.Left)
            lvProcesses.Columns.Add("ID", 60, HorizontalAlignment.Left)
            lvProcesses.Columns.Add("Priority", 60, HorizontalAlignment.Right)
            lvProcesses.Columns.Add("Memory", 100, HorizontalAlignment.Right)
            Dim p As Process
            For Each p In ps
                Dim lvi As ListViewItem = New ListViewItem()
                lvi.Text = p.ProcessName
                lvi.SubItems.Add(p.Id.ToString())
                lvi.SubItems.Add(p.BasePriority.ToString())
                lvi.SubItems.Add(p.WorkingSet64.ToString())
                lvProcesses.Items.Add(lvi)
            Next p
            lvProcesses.EndUpdate()
        Catch e As Exception
            MessageBox.Show(e.Message)
        End Try
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListProcesses()
    End Sub
    Private Sub btnKillProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKillProcess.Click
        If MessageBox.Show(Me, "Stop Process" + lvProcesses.SelectedItems(0).Text, "Stop", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) = DialogResult.Cancel Then
            Return
        End If
        Dim pid As Integer = Int32.Parse(lvProcesses.SelectedItems(0).SubItems(1).Text)
        Dim p As Process = Process.GetProcessById(pid)
        If p Is Nothing Then Return
        If Not p.CloseMainWindow() Then p.Kill()
        p.WaitForExit()
        p.Close()
        ListProcesses()
    End Sub
    Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        ListProcesses()
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub
    Private components As System.ruponentModel.IContainer
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.btnRefresh = New System.Windows.Forms.Button
        Me.label1 = New System.Windows.Forms.Label
        Me.btnKillProcess = New System.Windows.Forms.Button
        Me.btnNewProcess = New System.Windows.Forms.Button
        Me.lvProcesses = New System.Windows.Forms.ListView
        Me.btnProcessProp = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "btnRefresh
        "
        Me.btnRefresh.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnRefresh.Location = New System.Drawing.Point(557, 11)
        Me.btnRefresh.Margin = New System.Windows.Forms.Padding(4)
        Me.btnRefresh.Name = "btnRefresh"
        Me.btnRefresh.Size = New System.Drawing.Size(116, 35)
        Me.btnRefresh.TabIndex = 11
        Me.btnRefresh.Text = "Refresh(&R)"
        Me.btnRefresh.UseVisualStyleBackColor = True
        "
        "label1
        "
        Me.label1.AutoSize = True
        Me.label1.Location = New System.Drawing.Point(13, 24)
        Me.label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
        Me.label1.Name = "label1"
        Me.label1.Size = New System.Drawing.Size(112, 15)
        Me.label1.TabIndex = 10
        Me.label1.Text = "Processes"
        "
        "btnKillProcess
        "
        Me.btnKillProcess.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnKillProcess.Location = New System.Drawing.Point(509, 347)
        Me.btnKillProcess.Margin = New System.Windows.Forms.Padding(4)
        Me.btnKillProcess.Name = "btnKillProcess"
        Me.btnKillProcess.Size = New System.Drawing.Size(164, 29)
        Me.btnKillProcess.TabIndex = 9
        Me.btnKillProcess.Text = "Stop(&K)"
        Me.btnKillProcess.UseVisualStyleBackColor = True
        "
        "btnNewProcess
        "
        Me.btnNewProcess.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnNewProcess.Location = New System.Drawing.Point(362, 347)
        Me.btnNewProcess.Margin = New System.Windows.Forms.Padding(4)
        Me.btnNewProcess.Name = "btnNewProcess"
        Me.btnNewProcess.Size = New System.Drawing.Size(139, 29)
        Me.btnNewProcess.TabIndex = 8
        Me.btnNewProcess.Text = "New(&N)"
        Me.btnNewProcess.UseVisualStyleBackColor = True
        "
        "lvProcesses
        "
        Me.lvProcesses.Location = New System.Drawing.Point(13, 54)
        Me.lvProcesses.Margin = New System.Windows.Forms.Padding(4)
        Me.lvProcesses.MultiSelect = False
        Me.lvProcesses.Name = "lvProcesses"
        Me.lvProcesses.Size = New System.Drawing.Size(659, 285)
        Me.lvProcesses.TabIndex = 7
        Me.lvProcesses.UseCompatibleStateImageBehavior = False
        Me.lvProcesses.View = System.Windows.Forms.View.Details
        "
        "btnProcessProp
        "
        Me.btnProcessProp.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnProcessProp.Location = New System.Drawing.Point(32, 347)
        Me.btnProcessProp.Margin = New System.Windows.Forms.Padding(4)
        Me.btnProcessProp.Name = "btnProcessProp"
        Me.btnProcessProp.Size = New System.Drawing.Size(153, 29)
        Me.btnProcessProp.TabIndex = 6
        Me.btnProcessProp.Text = "Properties(&P)"
        Me.btnProcessProp.UseVisualStyleBackColor = True
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(679, 395)
        Me.Controls.Add(Me.btnRefresh)
        Me.Controls.Add(Me.label1)
        Me.Controls.Add(Me.btnKillProcess)
        Me.Controls.Add(Me.btnNewProcess)
        Me.Controls.Add(Me.lvProcesses)
        Me.Controls.Add(Me.btnProcessProp)
        Me.ResumeLayout(False)
        Me.PerformLayout()
    End Sub
    Private WithEvents btnRefresh As System.Windows.Forms.Button
    Private WithEvents label1 As System.Windows.Forms.Label
    Private WithEvents btnKillProcess As System.Windows.Forms.Button
    Private WithEvents btnNewProcess As System.Windows.Forms.Button
    Private WithEvents lvProcesses As System.Windows.Forms.ListView
    Private WithEvents btnProcessProp As System.Windows.Forms.Button
End Class

Open Default editor for text file

Imports System.Diagnostics
public class Test
   public Shared Sub Main
        Dim new_process As New Process
        new_process.StartInfo.FileName = "test.txt"
        new_process.StartInfo.Verb = "Open"
        new_process.Start()
   End Sub
End class

Print properties of Process

Imports System.Diagnostics
Public Class Tester
    Public Shared Sub Main
        Dim pid As Integer = 12345
        Dim p As Process = Process.GetProcessById(pid)
        If p Is Nothing Then Return
        Try
            Console.WriteLine(p.Id.ToString())
            Console.WriteLine(p.ProcessName)
            Console.WriteLine(p.StartTime.ToLongTimeString())
            Console.WriteLine(p.PriorityClass.ToString())
            Console.WriteLine(p.VirtualMemorySize64.ToString())
            Console.WriteLine(p.WorkingSet64.ToString())
            If p.MainModule IsNot Nothing Then
                Console.WriteLine(p.MainModule.FileName)
                Console.WriteLine(p.MainModule.FileVersionInfo.FileDescription)
                Console.WriteLine(p.MainModule.FileVersionInfo.FileVersion)
            End If
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        Finally
            p.Close()
        End Try    
    End Sub
End Class
Unhandled Exception: System.ArgumentException: Process with an Id of 12345 is not running.
   at System.Diagnostics.Process.GetProcessById(Int32 processId, String machineName)
   at System.Diagnostics.Process.GetProcessById(Int32 processId)
   at Tester.Main()

Start a process

Imports System.Diagnostics
Imports System.Windows.Forms
public class ProcessStartForm
   public Shared Sub Main
        Application.Run(New FormStartInfo)
   End Sub
End class
Public Class FormStartInfo
    Private Sub ListVerb(ByVal filename As String)
        cbxVerb.Items.Clear()
        Dim sinfo As ProcessStartInfo = New ProcessStartInfo(filename)
        cbxVerb.Items.AddRange(sinfo.Verbs)
    End Sub

    Private Sub FormStartInfo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cbxStyle.SelectedIndex = 2
    End Sub
    Private Sub txtFileName_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFileName.Leave
        ListVerb(txtFileName.Text)
    End Sub
    Private Sub btnExplorer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExplorer.Click
        Dim dlg As OpenFileDialog = New OpenFileDialog()
        dlg.CheckFileExists = True
        dlg.Filter = "(*.exe)|*.exe|(*.*)|*.*"
        If dlg.ShowDialog = System.Windows.Forms.DialogResult.OK Then
            txtFileName.Text = dlg.FileName
            ListVerb(dlg.FileName)
        End If
    End Sub
    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim si As ProcessStartInfo = New ProcessStartInfo()
        si.FileName = txtFileName.Text
        si.Arguments = txtParam.Text
        si.ErrorDialog = chkErrDlg.Checked
        si.UseShellExecute = chkUseShell.Checked
        If cbxVerb.SelectedIndex <> -1 Then si.Verb = cbxVerb.Text
        si.WorkingDirectory = txtWorkDir.Text
        If cbxStyle.SelectedIndex = 0 Then
            si.WindowStyle = ProcessWindowStyle.Maximized
        ElseIf cbxStyle.SelectedIndex = 1 Then
            si.WindowStyle = ProcessWindowStyle.Minimized
        Else
            si.WindowStyle = ProcessWindowStyle.Normal
        End If
        Try
            Process.Start(si)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class FormStartInfo
    Inherits System.Windows.Forms.Form
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub
    Private components As System.ruponentModel.IContainer
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.cbxStyle = New System.Windows.Forms.ruboBox
        Me.cbxVerb = New System.Windows.Forms.ruboBox
        Me.txtWorkDir = New System.Windows.Forms.TextBox
        Me.txtParam = New System.Windows.Forms.TextBox
        Me.btnCancel = New System.Windows.Forms.Button
        Me.btnOK = New System.Windows.Forms.Button
        Me.chkErrDlg = New System.Windows.Forms.CheckBox
        Me.chkUseShell = New System.Windows.Forms.CheckBox
        Me.label5 = New System.Windows.Forms.Label
        Me.label4 = New System.Windows.Forms.Label
        Me.label3 = New System.Windows.Forms.Label
        Me.label2 = New System.Windows.Forms.Label
        Me.btnExplorer = New System.Windows.Forms.Button
        Me.txtFileName = New System.Windows.Forms.TextBox
        Me.label1 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        "
        "cbxStyle
        "
        Me.cbxStyle.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList
        Me.cbxStyle.FormattingEnabled = True
        Me.cbxStyle.Items.AddRange(New Object() {"Maximized", "Minimized", "Regular"})
        Me.cbxStyle.Location = New System.Drawing.Point(109, 134)
        Me.cbxStyle.Margin = New System.Windows.Forms.Padding(4)
        Me.cbxStyle.Name = "cbxStyle"
        Me.cbxStyle.Size = New System.Drawing.Size(487, 23)
        Me.cbxStyle.TabIndex = 29
        "
        "cbxVerb
        "
        Me.cbxVerb.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList
        Me.cbxVerb.FormattingEnabled = True
        Me.cbxVerb.Location = New System.Drawing.Point(109, 105)
        Me.cbxVerb.Margin = New System.Windows.Forms.Padding(4)
        Me.cbxVerb.Name = "cbxVerb"
        Me.cbxVerb.Size = New System.Drawing.Size(487, 23)
        Me.cbxVerb.TabIndex = 28
        "
        "txtWorkDir
        "
        Me.txtWorkDir.Location = New System.Drawing.Point(109, 166)
        Me.txtWorkDir.Margin = New System.Windows.Forms.Padding(4)
        Me.txtWorkDir.Name = "txtWorkDir"
        Me.txtWorkDir.Size = New System.Drawing.Size(487, 25)
        Me.txtWorkDir.TabIndex = 27
        "
        "txtParam
        "
        Me.txtParam.Location = New System.Drawing.Point(109, 71)
        Me.txtParam.Margin = New System.Windows.Forms.Padding(4)
        Me.txtParam.Name = "txtParam"
        Me.txtParam.Size = New System.Drawing.Size(487, 25)
        Me.txtParam.TabIndex = 26
        "
        "btnCancel
        "
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Location = New System.Drawing.Point(358, 266)
        Me.btnCancel.Margin = New System.Windows.Forms.Padding(4)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(100, 29)
        Me.btnCancel.TabIndex = 25
        Me.btnCancel.Text = "Cancel(&C)"
        Me.btnCancel.UseVisualStyleBackColor = True
        "
        "btnOK
        "
        Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.btnOK.Location = New System.Drawing.Point(174, 266)
        Me.btnOK.Margin = New System.Windows.Forms.Padding(4)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(100, 29)
        Me.btnOK.TabIndex = 24
        Me.btnOK.Text = "OK(&O)"
        Me.btnOK.UseVisualStyleBackColor = True
        "
        "chkErrDlg
        "
        Me.chkErrDlg.AutoSize = True
        Me.chkErrDlg.Location = New System.Drawing.Point(16, 239)
        Me.chkErrDlg.Margin = New System.Windows.Forms.Padding(4)
        Me.chkErrDlg.Name = "chkErrDlg"
        Me.chkErrDlg.Size = New System.Drawing.Size(134, 19)
        Me.chkErrDlg.TabIndex = 23
        Me.chkErrDlg.Text = "Error Dialog"
        Me.chkErrDlg.UseVisualStyleBackColor = True
        "
        "chkUseShell
        "
        Me.chkUseShell.AutoSize = True
        Me.chkUseShell.Location = New System.Drawing.Point(16, 211)
        Me.chkUseShell.Margin = New System.Windows.Forms.Padding(4)
        Me.chkUseShell.Name = "chkUseShell"
        Me.chkUseShell.Size = New System.Drawing.Size(209, 19)
        Me.chkUseShell.TabIndex = 22
        Me.chkUseShell.Text = "Start Process"
        Me.chkUseShell.UseVisualStyleBackColor = True
        "
        "label5
        "
        Me.label5.AutoSize = True
        Me.label5.Location = New System.Drawing.Point(13, 173)
        Me.label5.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
        Me.label5.Name = "label5"
        Me.label5.Size = New System.Drawing.Size(82, 15)
        Me.label5.TabIndex = 21
        Me.label5.Text = "Dir:"
        "
        "label4
        "
        Me.label4.AutoSize = True
        Me.label4.Location = New System.Drawing.Point(13, 140)
        Me.label4.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
        Me.label4.Name = "label4"
        Me.label4.Size = New System.Drawing.Size(82, 15)
        Me.label4.TabIndex = 20
        Me.label4.Text = "Window style"
        "
        "label3
        "
        Me.label3.AutoSize = True
        Me.label3.Location = New System.Drawing.Point(12, 110)
        Me.label3.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
        Me.label3.Name = "label3"
        Me.label3.Size = New System.Drawing.Size(52, 15)
        Me.label3.TabIndex = 19
        Me.label3.Text = "Predicate"
        "
        "label2
        "
        Me.label2.AutoSize = True
        Me.label2.Location = New System.Drawing.Point(12, 76)
        Me.label2.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
        Me.label2.Name = "label2"
        Me.label2.Size = New System.Drawing.Size(52, 15)
        Me.label2.TabIndex = 18
        Me.label2.Text = "Parameter"
        "
        "btnExplorer
        "
        Me.btnExplorer.Location = New System.Drawing.Point(502, 27)
        Me.btnExplorer.Margin = New System.Windows.Forms.Padding(4)
        Me.btnExplorer.Name = "btnExplorer"
        Me.btnExplorer.Size = New System.Drawing.Size(100, 29)
        Me.btnExplorer.TabIndex = 17
        Me.btnExplorer.Text = "Browser."
        Me.btnExplorer.UseVisualStyleBackColor = True
        "
        "txtFileName
        "
        Me.txtFileName.Location = New System.Drawing.Point(9, 27)
        Me.txtFileName.Margin = New System.Windows.Forms.Padding(4)
        Me.txtFileName.Name = "txtFileName"
        Me.txtFileName.Size = New System.Drawing.Size(484, 25)
        Me.txtFileName.TabIndex = 16
        "
        "label1
        "
        Me.label1.AutoSize = True
        Me.label1.Location = New System.Drawing.Point(13, 9)
        Me.label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
        Me.label1.Name = "label1"
        Me.label1.Size = New System.Drawing.Size(307, 15)
        Me.label1.TabIndex = 15
        Me.label1.Text = "Executable file name"
        "
        "FormStartInfo
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(612, 306)
        Me.Controls.Add(Me.cbxStyle)
        Me.Controls.Add(Me.cbxVerb)
        Me.Controls.Add(Me.txtWorkDir)
        Me.Controls.Add(Me.txtParam)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.chkErrDlg)
        Me.Controls.Add(Me.chkUseShell)
        Me.Controls.Add(Me.label5)
        Me.Controls.Add(Me.label4)
        Me.Controls.Add(Me.label3)
        Me.Controls.Add(Me.label2)
        Me.Controls.Add(Me.btnExplorer)
        Me.Controls.Add(Me.txtFileName)
        Me.Controls.Add(Me.label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.ResumeLayout(False)
        Me.PerformLayout()
    End Sub
    Private WithEvents cbxStyle As System.Windows.Forms.ruboBox
    Private WithEvents cbxVerb As System.Windows.Forms.ruboBox
    Private WithEvents txtWorkDir As System.Windows.Forms.TextBox
    Private WithEvents txtParam As System.Windows.Forms.TextBox
    Private WithEvents btnCancel As System.Windows.Forms.Button
    Private WithEvents btnOK As System.Windows.Forms.Button
    Private WithEvents chkErrDlg As System.Windows.Forms.CheckBox
    Private WithEvents chkUseShell As System.Windows.Forms.CheckBox
    Private WithEvents label5 As System.Windows.Forms.Label
    Private WithEvents label4 As System.Windows.Forms.Label
    Private WithEvents label3 As System.Windows.Forms.Label
    Private WithEvents label2 As System.Windows.Forms.Label
    Private WithEvents btnExplorer As System.Windows.Forms.Button
    Private WithEvents txtFileName As System.Windows.Forms.TextBox
    Private WithEvents label1 As System.Windows.Forms.Label
End Class

Start main module in current process

Imports System.Diagnostics
Module Module1
    Sub Main()
"        Process.Start(Process.GetCurrentProcess().MainModule.FileName)
    End Sub
End Module

Start process by setting file name

Public Class Tester
    Public Shared Sub Main
    
        Dim proc As System.Diagnostics.Process
        proc = New System.Diagnostics.Process()
        proc.StartInfo.FileName = "c:\\text.txt"
        proc.Start()
    End Sub
End Class
Unhandled Exception: System.ruponentModel.Win32Exception: The system cannot find the file specified
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Tester.Main()