Taskkill akan 'membunuh' semua aplikasi. Maksudnya, jika anda membuka 4
window explorer, maka keempat window explorer akan 'dibunuh' semuanya.
Tapi kalo ingin 'membunuh' aplikasi secara spesifik, dapat digunakan
OpenProcess <-> TerminateProcess.
Ini contohnya, aku ambil dari MSDN. MSDN merupakan sumber resource yang
menakjubkan. Mungkin sebelum anggota milis bertanya, bisa mencoba hal2
baru dari MSDN. Mungkin lho ....
Step-by-Step Example
1. Start a new project in Visual Basic. Form1 is created by
default.
2. Add the following code to the General Declarations section of
Form1:
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Declare Function CreateProcess Lib "kernel32" Alias _
"CreateProcessA" (ByVal lpApplicationName As String, ByVal _
lpCommandLine As String, lpProcessAttributes As Any, _
lpThreadAttributes As Any, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal _
lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal _
dwAccess As Long, ByVal fInherit As Integer, ByVal hObject _
As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal _
hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Const SYNCHRONIZE = 1048576
Const NORMAL_PRIORITY_CLASS = &H20&
3. Add the following code to the Form1_Click event:
Dim pInfo As PROCESS_INFORMATION
Dim sInfo As STARTUPINFO Dim sNull As String
Dim success
Dim ret
sInfo.cb = Len(sInfo)
success = CreateProcess(sNull, "Calc.exe", ByVal 0&, ByVal 0&, _
1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull,
sInfo, pInfo)
' ProcessID& = Shell("Calc.exe", vbNormalFocus)
' ProcessHandle& = OpenProcess(SYNCHRONIZE, True, ProcessID&)
MsgBox "Calculator has been launched!"
ret = TerminateProcess(pInfo.hProcess, 0&)
ret = CloseHandle(pInfo.hThread)
ret = CloseHandle(pInfo.hProcess)
' ret = TerminateProcess(ProcessHandle&, 0&)
' ret = CloseHandle(ProcessHandle&)
' ret = CloseHandle(ProcessHandle&)
MsgBox "Calculator has terminated!"
4. Press the F5 key to run the program. Click Form1. The Windows
Calculator program launches, and a message tells you so. When you click
the OK button on the MsgBox, the Calculator program terminates, and
another message tells you so.
To see how this method works using the Shell and OpenProcess method,
change the commented code into executed code, change the rest of the
code into comments except for the two MsgBox statements.
________________________________
From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of Arief Wibowo
Sent: Wednesday, March 28, 2007 5:48 PM
To: [email protected]
Subject: [Programmer-VB] Re: Ada yang tau ga codingnya tentang "End
processes di Windows Task Manager"
=== BEGIN ARIEFWT'S POSTING ===
Di %system32% ada tool namanya taskkill.exe.
Gabungin aja fungsi Shell dengan taskkill tsb...
Contoh:
'=== BEGIN CODE - COPY FROM HERE ===
Shell("C:\WINDOWS\system32\taskkill.exe /F /IM ""explorer.exe""")
'powered by Arief Softwares Lab ([EMAIL PROTECTED]
<mailto:ariefwt%2Baslab%40gmail.com> )
'=== END CODE - COPY UNTIL HERE ===
Dalam contoh di atas, saya "mencoba" mematikan proses explorer.exe.
=== END ARIEFWT'S POSTING ===
Catatan:
* Semoga posting di atas dapat bermanfaat secara positif bagi kita semua
* Kalau ada pertanyaan, silahkan hubungi saya di [EMAIL PROTECTED]
<mailto:ariefwt%40gmail.com>
* Mohon maaf sebesar-besarnya apabila ada kata-kata yang kurang
berkenaan di hati Anda
Salam,
(Arief Wibowo, C.Hts, RM)
Computer Programmer and Alternative Therapist
Medan, 28 Maret 2007dddddd|0)
--- In [email protected]
<mailto:Programmer-VB%40yahoogroups.com> , "faizal" <[EMAIL PROTECTED]> wrote:
>
> Halo Vb mania, minta pencerahannya donk....ada yang tau ga codingnya
"End Processes di Windows task manager" di VB 6.0....jadi kita ga usah
klik Task manager lagi kalo mau End Process baik itu application atau
process....tapi langsung dari program VBnya?
>
> Mohon bantuannya.
>
> Thanks,
> Faizal
>
This email is confidential. If you are not the addressee tell the sender
immediately and destroy this email
without using, sending or storing it. Emails are not secure and may suffer
errors, viruses, delay,
interception and amendment. Standard Chartered PLC and subsidiaries ("SCGroup")
do not accept liability for
damage caused by this email and may monitor email traffic.