All pastes #44068 Raw Edit

Miscellany

public text v1 · immutable
#44068 ·published 2006-03-01 06:46 UTC
rendered paste body
Imports System
Imports Microsoft
Imports System.Diagnostics

Module Module1
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Sub Main()
        '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)

            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")

        Sleep(2000)
        Process.Start(path)

        Sleep(5000)
        AppActivate("euox")
        Sendkeys.SendWait("{F9}")
    End Sub
End Module