Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Terminate a Shelled To Program 1

Status
Not open for further replies.

TOMBUGGY

Programmer
Oct 4, 2000
36
US
How do I terminate a program that I started with the Shell Statement? Thanks.
 
[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

 
I've provided an alternative to this in your original thread: thread222-1589849
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top