All pastes #44071 Raw Edit

Something

public text v1 · immutable
#44071 ·published 2006-03-01 06:57 UTC
rendered paste body
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        Timer1.Interval = 10000
        ' Enable timer.
        Timer1.Enabled = True
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        'System.Threading.Thread.Sleep(5000)

        Dim Sendkeys As Windows.Forms.SendKeys
        Dim path As String = "E:\Program Files\EA Games\Ultima Online sphere\client.exe"
        Dim arg As String = "client"
        Dim proc As Process

        ' Dim test() As Process = System.Diagnostics.Process.Responding(arg)

        Dim procs() As Process = Process.GetProcessesByName(arg)
        If procs.Length = 1 Then
            Console.WriteLine("found")
            proc = procs(0)
        ElseIf procs.Length > 1 Then
            Console.WriteLine _
                ("Process name is ambiguous. Unable to proceed.")
            End
        ElseIf procs.Length = 0 Then
            Console.WriteLine("Process not found. Unable to proceed")
            Process.Start(path)

            System.Threading.Thread.Sleep(5000)
            AppActivate("euox")
            Sendkeys.SendWait("{F9}")
            End
        End If

        ' kill the process
        Dim res As Boolean

        ' attempt to kill the process by closing its main window
        res = proc.CloseMainWindow()

        If res = False Then
            ' no UI or the window is disabled
            proc.Kill()

        End If

        ' wait for the process to end
        If proc.WaitForExit(5000) Then
            Console.WriteLine("Process {0} has been killed", proc.ProcessName)
        Else
            Console.WriteLine("Unable to kill process {0}", proc.ProcessName)
        End If
        Console.WriteLine("complete")

        System.Threading.Thread.Sleep(5000)
        Process.Start(path)

        System.Threading.Thread.Sleep(5000)
        AppActivate("euox")
        Sendkeys.SendWait("{F9}")

    End Sub
End Class