Feb 6, 2010 #1 TOMBUGGY Programmer Oct 4, 2000 36 US How do I terminate a program that I started with the Shell Statement? Thanks.
Feb 6, 2010 1 #2 vb5prgrmr Programmer Jul 5, 2002 3,617 US [tt] [blue]Option Explicit Private Const[/blue] PROCESS_TERMINATE = &H1 [blue]Private Declare Function[/blue] OpenProcess [blue]Lib[/blue] "kernel32.dll" ([blue]ByVal[/blue] dwDesiredAccess [blue]As Long[/blue], [blue]ByVal[/blue] bInheritHandle [blue]As Long[/blue], [blue]ByVal[/blue] dwProcessId [blue]As Long[/blue]) [blue]As Long Private Declare Function[/blue] CloseHandle [blue]Lib[/blue] "kernel32" ([blue]ByVal[/blue] hObject [blue]As Long[/blue]) [blue]As Long Private Declare Function[/blue] TerminateProcess [blue]Lib[/blue] "kernel32" ([blue]ByVal[/blue] hProcess [blue]As Long[/blue], [blue]ByVal[/blue] uExitCode [blue]As Long[/blue]) [blue]As Long Dim[/blue] PID [blue]As Long Private Sub[/blue] ShellNotePad() PID = Shell("notepad.exe", vbNormalFocus) [blue]End Sub Private Sub[/blue] KillNotepad() [blue]Dim[/blue] HandleToProcess [blue]As Long[/blue] HandleToProcess = OpenProcess(PROCESS_TERMINATE, 0, PID) [blueIf[/blue] HandleToProcess [blue]Then[/blue] TerminateProcess HandleToProcess, 1& CloseHandle HandleToProcess [blue]End If End Sub[/blue] [/tt] Good Luck Upvote 0 Downvote
[tt] [blue]Option Explicit Private Const[/blue] PROCESS_TERMINATE = &H1 [blue]Private Declare Function[/blue] OpenProcess [blue]Lib[/blue] "kernel32.dll" ([blue]ByVal[/blue] dwDesiredAccess [blue]As Long[/blue], [blue]ByVal[/blue] bInheritHandle [blue]As Long[/blue], [blue]ByVal[/blue] dwProcessId [blue]As Long[/blue]) [blue]As Long Private Declare Function[/blue] CloseHandle [blue]Lib[/blue] "kernel32" ([blue]ByVal[/blue] hObject [blue]As Long[/blue]) [blue]As Long Private Declare Function[/blue] TerminateProcess [blue]Lib[/blue] "kernel32" ([blue]ByVal[/blue] hProcess [blue]As Long[/blue], [blue]ByVal[/blue] uExitCode [blue]As Long[/blue]) [blue]As Long Dim[/blue] PID [blue]As Long Private Sub[/blue] ShellNotePad() PID = Shell("notepad.exe", vbNormalFocus) [blue]End Sub Private Sub[/blue] KillNotepad() [blue]Dim[/blue] HandleToProcess [blue]As Long[/blue] HandleToProcess = OpenProcess(PROCESS_TERMINATE, 0, PID) [blueIf[/blue] HandleToProcess [blue]Then[/blue] TerminateProcess HandleToProcess, 1& CloseHandle HandleToProcess [blue]End If End Sub[/blue] [/tt] Good Luck
Feb 8, 2010 #3 strongm MIS May 24, 2001 20,147 GB I've provided an alternative to this in your original thread: thread222-1589849 Upvote 0 Downvote