Start a process : Process « Development « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Development » Process 
7.24.10.Start a process
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.EventArgsHandles MyBase.Load
        cbxStyle.SelectedIndex = 2
    End Sub

    Private Sub txtFileName_Leave(ByVal sender As System.Object, ByVal e As System.EventArgsHandles txtFileName.Leave
        ListVerb(txtFileName.Text)
    End Sub

    Private Sub btnExplorer_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles 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.EventArgsHandles 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 <> -Then si.Verb = cbxVerb.Text
        si.WorkingDirectory = txtWorkDir.Text
        If cbxStyle.SelectedIndex = Then
            si.WindowStyle = ProcessWindowStyle.Maximized
        ElseIf cbxStyle.SelectedIndex = 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.CompilerServices.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.ComponentModel.IContainer

    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.cbxStyle = New System.Windows.Forms.ComboBox
        Me.cbxVerb = New System.Windows.Forms.ComboBox
        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.ComboBoxStyle.DropDownList
        Me.cbxStyle.FormattingEnabled = True
        Me.cbxStyle.Items.AddRange(New Object() {"Maximized""Minimized""Regular"})
        Me.cbxStyle.Location = New System.Drawing.Point(109134)
        Me.cbxStyle.Margin = New System.Windows.Forms.Padding(4)
        Me.cbxStyle.Name = "cbxStyle"
        Me.cbxStyle.Size = New System.Drawing.Size(48723)
        Me.cbxStyle.TabIndex = 29
        '
        'cbxVerb
        '
        Me.cbxVerb.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cbxVerb.FormattingEnabled = True
        Me.cbxVerb.Location = New System.Drawing.Point(109105)
        Me.cbxVerb.Margin = New System.Windows.Forms.Padding(4)
        Me.cbxVerb.Name = "cbxVerb"
        Me.cbxVerb.Size = New System.Drawing.Size(48723)
        Me.cbxVerb.TabIndex = 28
        '
        'txtWorkDir
        '
        Me.txtWorkDir.Location = New System.Drawing.Point(109166)
        Me.txtWorkDir.Margin = New System.Windows.Forms.Padding(4)
        Me.txtWorkDir.Name = "txtWorkDir"
        Me.txtWorkDir.Size = New System.Drawing.Size(48725)
        Me.txtWorkDir.TabIndex = 27
        '
        'txtParam
        '
        Me.txtParam.Location = New System.Drawing.Point(10971)
        Me.txtParam.Margin = New System.Windows.Forms.Padding(4)
        Me.txtParam.Name = "txtParam"
        Me.txtParam.Size = New System.Drawing.Size(48725)
        Me.txtParam.TabIndex = 26
        '
        'btnCancel
        '
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Location = New System.Drawing.Point(358266)
        Me.btnCancel.Margin = New System.Windows.Forms.Padding(4)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(10029)
        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(174266)
        Me.btnOK.Margin = New System.Windows.Forms.Padding(4)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(10029)
        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(16239)
        Me.chkErrDlg.Margin = New System.Windows.Forms.Padding(4)
        Me.chkErrDlg.Name = "chkErrDlg"
        Me.chkErrDlg.Size = New System.Drawing.Size(13419)
        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(16211)
        Me.chkUseShell.Margin = New System.Windows.Forms.Padding(4)
        Me.chkUseShell.Name = "chkUseShell"
        Me.chkUseShell.Size = New System.Drawing.Size(20919)
        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(13173)
        Me.label5.Margin = New System.Windows.Forms.Padding(4040)
        Me.label5.Name = "label5"
        Me.label5.Size = New System.Drawing.Size(8215)
        Me.label5.TabIndex = 21
        Me.label5.Text = "Dir:"
        '
        'label4
        '
        Me.label4.AutoSize = True
        Me.label4.Location = New System.Drawing.Point(13140)
        Me.label4.Margin = New System.Windows.Forms.Padding(4040)
        Me.label4.Name = "label4"
        Me.label4.Size = New System.Drawing.Size(8215)
        Me.label4.TabIndex = 20
        Me.label4.Text = "Window style"
        '
        'label3
        '
        Me.label3.AutoSize = True
        Me.label3.Location = New System.Drawing.Point(12110)
        Me.label3.Margin = New System.Windows.Forms.Padding(4040)
        Me.label3.Name = "label3"
        Me.label3.Size = New System.Drawing.Size(5215)
        Me.label3.TabIndex = 19
        Me.label3.Text = "Predicate"
        '
        'label2
        '
        Me.label2.AutoSize = True
        Me.label2.Location = New System.Drawing.Point(1276)
        Me.label2.Margin = New System.Windows.Forms.Padding(4040)
        Me.label2.Name = "label2"
        Me.label2.Size = New System.Drawing.Size(5215)
        Me.label2.TabIndex = 18
        Me.label2.Text = "Parameter"
        '
        'btnExplorer
        '
        Me.btnExplorer.Location = New System.Drawing.Point(50227)
        Me.btnExplorer.Margin = New System.Windows.Forms.Padding(4)
        Me.btnExplorer.Name = "btnExplorer"
        Me.btnExplorer.Size = New System.Drawing.Size(10029)
        Me.btnExplorer.TabIndex = 17
        Me.btnExplorer.Text = "Browser."
        Me.btnExplorer.UseVisualStyleBackColor = True
        '
        'txtFileName
        '
        Me.txtFileName.Location = New System.Drawing.Point(927)
        Me.txtFileName.Margin = New System.Windows.Forms.Padding(4)
        Me.txtFileName.Name = "txtFileName"
        Me.txtFileName.Size = New System.Drawing.Size(48425)
        Me.txtFileName.TabIndex = 16
        '
        'label1
        '
        Me.label1.AutoSize = True
        Me.label1.Location = New System.Drawing.Point(139)
        Me.label1.Margin = New System.Windows.Forms.Padding(4040)
        Me.label1.Name = "label1"
        Me.label1.Size = New System.Drawing.Size(30715)
        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(612306)
        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.ComboBox
    Private WithEvents cbxVerb As System.Windows.Forms.ComboBox
    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
7.24.Process
7.24.1.Start process by setting file name
7.24.2.Get current Process
7.24.3.Display properties of current Process
7.24.4.Start main module in current process
7.24.5.Kill current process
7.24.6.Get thread count in current process
7.24.7.Get Process by ID
7.24.8.Print properties of Process
7.24.9.Open Default editor for text file
7.24.10.Start a processStart a process
7.24.11.List all process in a ListViewList all process in a ListView
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.