- Code:
Skrip untuk membuat tampilan seperti task manager dengan
Visual Basic 06. Setiap process pada yang sedang berjalan
pada windows dapat dilihat dalam bentuk PID (ProcessID) dan
path. Setiap process yang ada bisa dimatikan asalkan
tidak dilindungi oleh system. Skrip ini juga
menggunakan listview yang memerlukan file component mscomctl.ocx.
Langkah awalnya adalah, Siapkan bahan2nya terlebih dahulu.
1. VB6 Portable/Initable (cari saja di google)
2. MSCOMCTL.OCX
Step by step.
• Buka VB6 Kamu, Buat project baru.
• 3 Buah Command Button, Masing2 beri nama cmdMatikan, cmdRefresh, cmdTutup inget Name bukan Caption.
• Pada 3 buah Command tersebut beri saja Caption "&Matikan", "&Refresh", "&Tutup".
• 1 Buah ListView1
• Isikan Code berikut pada Form 1 kamu
- Code:
' Silahkan gunakan baik2 source code ini.
'
'
'
'regards,
'ryanna a.K.a eriz
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Const MAX_PATH As Integer = 260
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "Kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hHandle As Long) As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
'Enum the path
Private Const PROCESS_QUERY_INFORMATION As Long = &H400
Private Const PROCESS_VM_READ = &H10
Private Declare Function EnumProcessModules Lib "psapi.dll" ( _
ByVal hProcess As Long, _
ByRef lphModule As Long, _
ByVal cb As Long, _
ByRef cbNeeded As Long) As Long
Private Declare Function GetModuleFileNameExA Lib "psapi.dll" ( _
ByVal hProcess As Long, _
ByVal hModule As Long, _
ByVal ModuleName As String, _
ByVal nSize As Long) As Long
Public Function PathByPID(pid As Long) As String
'Fungsi ini berfungsi untuk mendapatkan informasi tentang aplikasi yang sedang
'berjalan dengan menggunakan Process ID masing-masing aplikasi
'----
'Kode ini dapat dilihat di :
'http://support.microsoft.com/default.aspx?scid=kb;en-us;187913
Dim cbNeeded As Long
Dim Modules(1 To 200) As Long
Dim ret As Long
Dim ModuleName As String
Dim nSize As Long
Dim hProcess As Long
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION _
Or PROCESS_VM_READ, 0, pid)
If hProcess <> 0 Then
ret = EnumProcessModules(hProcess, Modules(1), _
200, cbNeeded)
If ret <> 0 Then
ModuleName = Space(MAX_PATH)
nSize = 500
ret = GetModuleFileNameExA(hProcess, _
Modules(1), ModuleName, nSize)
PathByPID = Left(ModuleName, ret)
End If
End If
ret = CloseHandle(hProcess)
If PathByPID = "" Then
PathByPID = ""
End If
If Left(PathByPID, 4) = "\??\" Then
PathByPID = ""
End If
If Left(PathByPID, 12) = "\SystemRoot\" Then
PathByPID = ""
End If
End Function
Private Sub List_Process()
Dim lItem As ListItem
Dim path As String
Dim hSnapShot As Long, uProcess As PROCESSENTRY32
'Memastikan agar semua List Box dalam keadaan kosong agar tidak terjadi penumpukan /duplikasi
ListView1.ListItems.Clear
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
'Mendapatkan informasi tentang semua proses yang sedang dijalankan
uProcess.dwSize = Len(uProcess)
r = Process32First(hSnapShot, uProcess)
'Mendapatkan informasi tentang proses yang pertama
Do While r
'perulangan selama r <> 0
Set lItem = ListView1.ListItems.Add
With lItem.ListSubItems
.Add , , Left$(uProcess.szExeFile, InStr(1, uProcess.szExeFile, Chr$(0), vbTextCompare) - 1)
.Add , , uProcess.th32ProcessID
path = PathByPID(uProcess.th32ProcessID)
.Add , , IIf(path <> "", path, "[Protected]")
End With
r = Process32Next(hSnapShot, uProcess)
'Mendapatkan informasi dari proses selanjutnya pada windows
Loop
CloseHandle hSnapShot
End Sub
Private Sub cmdMatikan_Click()
Dim processID As Long
processID = CLng(ListView1.SelectedItem.ListSubItems(2).Text)
TerminateProcess OpenProcess(PROCESS_ALL_ACCESS, 1, processID), 0
Call List_Process
End Sub
Private Sub cmdRefresh_Click()
List_Process
End Sub
Private Sub cmdTutup_Click()
Unload Me
End Sub
Private Sub Form_Load()
List_Process
End Sub
Selesai deh tinggal Make Project.exe
Di mohon Untuk :
• No Double Post
• No Junk
Untuk lebih jelas Baca RULES agar tidak terkena WARN .!