01-08-2010, 01:01 PM
kesempatan kali ini saya ingin berbagi ke pada para pembaca tentang cara untuk membuat sebuah program yang berguna untuk men-terminate proses yang sedang berjalan di memory. program ini dinamakan “The Stupid Treminator”. Program ini baik digunakan sebagai alternatif apabila taskmanager kita terkunci oleh virus. Oke langsung aja. Dalam pembuatan program ini kita membutuhkan dua buah form, tiga buah class module . Form pertama sebagai form utama dan form kedua sebagai halaman about. Beri nama FrmMain untuk form pertama, dan Frm_Splash untuk form kedua. Kemudian berinama cCRC32 untuk class module pertama, cGetFileIcon untuk class module kedua, dan cScanProcesses. Buat design form utama seperti gambar dibawah ini
![[Image: stupid_terminator.JPG]](http://2.bp.blogspot.com/_sSbAybwJeHU/SuUwxYV9KdI/AAAAAAAAAJ8/E1NhLRZ7cJY/s1600-h/stupid_terminator.JPG)
Kemudian bentuk form ke dua seperti pada gambar dibawah ini
![[Image: about_stupid.JPG]](http://1.bp.blogspot.com/_sSbAybwJeHU/SuUxKE6VzPI/AAAAAAAAAKE/YMGattgcfh8/s1600-h/about_stupid.JPG)
kopi paste kan source code dibawah ini dan letakan pada FrmMainDim WithEvents SCANPROC As cScanProcesses
Lalu kopi pastekan source code dibawah ini dan letakan pada class Module cCRC32
Lalu kopi pastekan source dibawah ini dan letakan pada class module cGetFileIcon
Lalu kopi pastekan source code dibwah ini dan letakan pada class module cScanProcesses
mohon maap kalo ada kekurangan ^^
Kemudian bentuk form ke dua seperti pada gambar dibawah ini
kopi paste kan source code dibawah ini dan letakan pada FrmMainDim WithEvents SCANPROC As cScanProcesses
Code:
Dim m_Time As Single
Dim FILEICON As cGetFileIcon
Option Explicit
Const SR = 0
Const GDI = 1
Const USR = 2
Const VER_PLATFORM_WIN32s = 0
Const VER_PLATFORM_WIN32_WINDOWS = 1
Const VER_PLATFORM_WIN32_NT = 2
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type
Private Declare Function GetComputerName Lib “kernel32.dll”
Alias “GetComputerNameA” (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function ShellExecute Lib “shell32.dll”
Alias “ShellExecuteA” (ByVal hwnd As Long, ByVal lpOperation As String,
ByVal lpFile As String, ByVal lpParameters As String,
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Sub GlobalMemoryStatus Lib “kernel32″ (lpBuffer As MEMORYSTATUS)
Private Declare Function pBGetFreeSystemResources Lib “rsrc32.dll” _
Alias “_MyGetFreeSystemResources32@4″ (ByVal iResType As Integer) As Integer
Private Declare Function GetVersionEx Lib “kernel32″ _
Alias “GetVersionExA” (lpVersionInformation As OSVERSIONINFO) As Long
Private Sub Cmd_Refresh_Click()
ListView1.ListItems.Clear
SCANPROC.SystemProcesses = True
m_Time = Timer
SCANPROC.BeginScanning
End Sub
Private Sub Cmd_terminate_Click()
If MsgBox(”Are you sure to terminate this stupid program?”,
vbExclamation + vbYesNo + vbDefaultButton2, “Terminate Process”) = vbYes Then
If SCANPROC.TerminateProcess(ListView1.SelectedItem.SubItems(2)) = True Then
Call Cmd_Refresh_Click
End If
End If
End Sub
Private Sub Form_Load()
Set SCANPROC = New cScanProcesses
Set FILEICON = New cGetFileIcon
ListView1.ListItems.Clear
SCANPROC.SystemProcesses = True
m_Time = Timer
SCANPROC.BeginScanning
End Sub
Private Sub Image1_Click()
Frm_Splash.Show
End Sub
Private Sub SCANPROC_CurrentProcess(File As String, Path As String,
ID As Long, Terminate As Boolean)
Dim p_HasImage As Boolean
If Path <> “SYSTEM” Then
p_HasImage = True
On Error Resume Next
ImageList1.ListImages(File).Tag = “”
If Not Err.Number = 0 Then
ImageList1.ListImages.Add , File, FILEICON.Icon(Path & File, SmallIcon)
Err.Clear
End If
End If
Dim lsv As ListItem
If p_HasImage Then
Set lsv = ListView1.ListItems.Add(, , File, , File)
Else
Set lsv = ListView1.ListItems.Add(, , File)
End If
Dim crc As New cCRC32
lsv.SubItems(1) = Path
lsv.SubItems(2) = ID
lsv.SubItems(3) = crc.FileChecksum(Path & File)
lsv.ListSubItems(2).ForeColor = vbBlue
lsv.Selected = True
lsv.EnsureVisible
End Sub
Private Sub SCANPROC_DoneScanning(TotalProcesses As Integer)
Dim p_Elapsed As Single
p_Elapsed = Timer – m_Time
Debug.Print “Total Number of Process Detected: ” &
TotalProcesses & vbNewLine & “Total Scan Time: ” & p_Elapsed & vbNewLine
Label3.Caption = TotalProcesses
End Sub
Private Sub Image2_Click()
End
End Sub
Private Sub Timer1_Timer()
Dim MS As MEMORYSTATUS
Dim compname As String * 255, cname As String
Dim X As Long
X = GetComputerName(compname, 255)
cname = Trim(compname)
cname = Left(cname, Len(cname) – 1)
lbl(7).Caption = cname
MS.dwLength = Len(MS)
Call GlobalMemoryStatus(MS)
With MS
lbl(0) = Format$(.dwTotalPhys / 1024, “#,###.##”) & “KB”
lbl(1) = Format$(.dwAvailPhys / 1024, “#,###.##”) & “KB”
lbl(2) = Format$(.dwTotalVirtual / 1024, “#,###.##”) & “KB”
lbl(3) = Format$(.dwAvailVirtual / 1024, “#,###.##”) & “KB”
lbl(4) = Format$(.dwTotalPageFile / 1024, “#,###.##”) & “KB”
lbl(5) = Format$(.dwAvailPageFile / 1024, “#,###.##”) & “KB”
lbl(6) = Format$(.dwMemoryLoad, “##0.00″) & ” %”
End With
End SubLalu kopi pastekan source code dibawah ini dan letakan pada class Module cCRC32
Code:
‘Author : Noel A. Dacara (noeldacara@yahoo.com)
‘Modified by: YaDoY666
Option Explicit
Private Declare Function CallWindowProc Lib “user32″
Alias “CallWindowProcA” (ByVal lpPrevWndFunc As Long,
ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long,
ByVal lParam As Long) As Long
Private m_CRC32Asmbl() As Byte
Private m_CRC32Table(0 To 255) As Long
Function FileChecksum(File As String) As String
‘Returns the CRC32 checksum value of a specified file.
‘Make sure the file isn’t empty or invalid to avoid errors later
If Len(Dir$(File)) = 0 Then
Exit Function
End If
On Error GoTo Err_Handler
Dim Arr() As Byte
Dim f As Integer
f = FreeFile ‘Get any available file number for use
Open File For Binary Access Read As f
‘Redimensionized array according to length of file
ReDim Arr(0 To LOF(f) – 1) As Byte
Get #f, , Arr() ‘Get file contents
Close #f
‘Calculate CRC32 checksum
FileChecksum = Hex$(CalculateBytes(Arr))
Err_Handler:
End Function
Function StringChecksum(Str As String) As String
If Not Len(Str) = 0 Then
StringChecksum = Hex$(CalculateBytes(StrConv(Str, vbFromUnicode)))
End If
End Function
Private Function CalculateBytes(Arr() As Byte) As Long
Dim CRC32 As Long
CRC32 = &HFFFFFFFF ‘CRC32 must have this default value
On Local Error GoTo Err_Handler
Dim i As Long
i = UBound(Arr) – LBound(Arr) + 1 ‘Precalculate size of array
Call CallWindowProc(VarPtr(m_CRC32Asmbl(0)),
VarPtr(CRC32), VarPtr(Arr(LBound(Arr))), VarPtr(m_CRC32Table(0)), i)
Err_Handler:
CalculateBytes = (Not CRC32) ‘Return CRC32 value
End Function
Private Sub Class_Initialize()
Dim i As Long
m_CRC32Table(0) = &H0
m_CRC32Table(1) = &H77073096
m_CRC32Table(2) = &HEE0E612C
m_CRC32Table(3) = &H990951BA
m_CRC32Table(4) = &H76DC419
m_CRC32Table(5) = &H706AF48F
m_CRC32Table(6) = &HE963A535
m_CRC32Table(7) = &H9E6495A3
m_CRC32Table(8) = &HEDB8832
m_CRC32Table(9) = &H79DCB8A4
m_CRC32Table(10) = &HE0D5E91E
m_CRC32Table(11) = &H97D2D988
m_CRC32Table(12) = &H9B64C2B
m_CRC32Table(13) = &H7EB17CBD
m_CRC32Table(14) = &HE7B82D07
m_CRC32Table(15) = &H90BF1D91
m_CRC32Table(16) = &H1DB71064
m_CRC32Table(17) = &H6AB020F2
m_CRC32Table(18) = &HF3B97148
m_CRC32Table(19) = &H84BE41DE
m_CRC32Table(20) = &H1ADAD47D
m_CRC32Table(21) = &H6DDDE4EB
m_CRC32Table(22) = &HF4D4B551
m_CRC32Table(23) = &H83D385C7
m_CRC32Table(24) = &H136C9856
m_CRC32Table(25) = &H646BA8C0
m_CRC32Table(26) = &HFD62F97A
m_CRC32Table(27) = &H8A65C9EC
m_CRC32Table(28) = &H14015C4F
m_CRC32Table(29) = &H63066CD9
m_CRC32Table(30) = &HFA0F3D63
m_CRC32Table(31) = &H8D080DF5
m_CRC32Table(32) = &H3B6E20C8
m_CRC32Table(33) = &H4C69105E
m_CRC32Table(34) = &HD56041E4
m_CRC32Table(35) = &HA2677172
m_CRC32Table(36) = &H3C03E4D1
m_CRC32Table(37) = &H4B04D447
m_CRC32Table(38) = &HD20D85FD
m_CRC32Table(39) = &HA50AB56B
m_CRC32Table(40) = &H35B5A8FA
m_CRC32Table(41) = &H42B2986C
m_CRC32Table(42) = &HDBBBC9D6
m_CRC32Table(43) = &HACBCF940
m_CRC32Table(44) = &H32D86CE3
m_CRC32Table(45) = &H45DF5C75
m_CRC32Table(46) = &HDCD60DCF
m_CRC32Table(47) = &HABD13D59
m_CRC32Table(48) = &H26D930AC
m_CRC32Table(49) = &H51DE003A
m_CRC32Table(50) = &HC8D75180
m_CRC32Table(51) = &HBFD06116
m_CRC32Table(52) = &H21B4F4B5
m_CRC32Table(53) = &H56B3C423
m_CRC32Table(54) = &HCFBA9599
m_CRC32Table(55) = &HB8BDA50F
m_CRC32Table(56) = &H2802B89E
m_CRC32Table(57) = &H5F058808
m_CRC32Table(58) = &HC60CD9B2
m_CRC32Table(59) = &HB10BE924
m_CRC32Table(60) = &H2F6F7C87
m_CRC32Table(61) = &H58684C11
m_CRC32Table(62) = &HC1611DAB
m_CRC32Table(63) = &HB6662D3D
m_CRC32Table(64) = &H76DC4190
m_CRC32Table(65) = &H1DB7106
m_CRC32Table(66) = &H98D220BC
m_CRC32Table(67) = &HEFD5102A
m_CRC32Table(68) = &H71B18589
m_CRC32Table(69) = &H6B6B51F
m_CRC32Table(70) = &H9FBFE4A5
m_CRC32Table(71) = &HE8B8D433
m_CRC32Table(72) = &H7807C9A2
m_CRC32Table(73) = &HF00F934
m_CRC32Table(74) = &H9609A88E
m_CRC32Table(75) = &HE10E9818
m_CRC32Table(76) = &H7F6A0DBB
m_CRC32Table(77) = &H86D3D2D
m_CRC32Table(78) = &H91646C97
m_CRC32Table(79) = &HE6635C01
m_CRC32Table(80) = &H6B6B51F4
m_CRC32Table(81) = &H1C6C6162
m_CRC32Table(82) = &H856530D8
m_CRC32Table(83) = &HF262004E
m_CRC32Table(84) = &H6C0695ED
m_CRC32Table(85) = &H1B01A57B
m_CRC32Table(86) = &H8208F4C1
m_CRC32Table(87) = &HF50FC457
m_CRC32Table(88) = &H65B0D9C6
m_CRC32Table(89) = &H12B7E950
m_CRC32Table(90) = &H8BBEB8EA
m_CRC32Table(91) = &HFCB9887C
m_CRC32Table(92) = &H62DD1DDF
m_CRC32Table(93) = &H15DA2D49
m_CRC32Table(94) = &H8CD37CF3
m_CRC32Table(95) = &HFBD44C65
m_CRC32Table(96) = &H4DB26158
m_CRC32Table(97) = &H3AB551CE
m_CRC32Table(98) = &HA3BC0074
m_CRC32Table(99) = &HD4BB30E2
m_CRC32Table(100) = &H4ADFA541
m_CRC32Table(101) = &H3DD895D7
m_CRC32Table(102) = &HA4D1C46D
m_CRC32Table(103) = &HD3D6F4FB
m_CRC32Table(104) = &H4369E96A
m_CRC32Table(105) = &H346ED9FC
m_CRC32Table(106) = &HAD678846
m_CRC32Table(107) = &HDA60B8D0
m_CRC32Table(108) = &H44042D73
m_CRC32Table(109) = &H33031DE5
m_CRC32Table(110) = &HAA0A4C5F
m_CRC32Table(111) = &HDD0D7CC9
m_CRC32Table(112) = &H5005713C
m_CRC32Table(113) = &H270241AA
m_CRC32Table(114) = &HBE0B1010
m_CRC32Table(115) = &HC90C2086
m_CRC32Table(116) = &H5768B525
m_CRC32Table(117) = &H206F85B3
m_CRC32Table(118) = &HB966D409
m_CRC32Table(119) = &HCE61E49F
m_CRC32Table(120) = &H5EDEF90E
m_CRC32Table(121) = &H29D9C998
m_CRC32Table(122) = &HB0D09822
m_CRC32Table(123) = &HC7D7A8B4
m_CRC32Table(124) = &H59B33D17
m_CRC32Table(125) = &H2EB40D81
m_CRC32Table(126) = &HB7BD5C3B
m_CRC32Table(127) = &HC0BA6CAD
m_CRC32Table(128) = &HEDB88320
m_CRC32Table(129) = &H9ABFB3B6
m_CRC32Table(130) = &H3B6E20C
m_CRC32Table(131) = &H74B1D29A
m_CRC32Table(132) = &HEAD54739
m_CRC32Table(133) = &H9DD277AF
m_CRC32Table(134) = &H4DB2615
m_CRC32Table(135) = &H73DC1683
m_CRC32Table(136) = &HE3630B12
m_CRC32Table(137) = &H94643B84
m_CRC32Table(138) = &HD6D6A3E
m_CRC32Table(139) = &H7A6A5AA8
m_CRC32Table(140) = &HE40ECF0B
m_CRC32Table(141) = &H9309FF9D
m_CRC32Table(142) = &HA00AE27
m_CRC32Table(143) = &H7D079EB1
m_CRC32Table(144) = &HF00F9344
m_CRC32Table(145) = &H8708A3D2
m_CRC32Table(146) = &H1E01F268
m_CRC32Table(147) = &H6906C2FE
m_CRC32Table(148) = &HF762575D
m_CRC32Table(149) = &H806567CB
m_CRC32Table(150) = &H196C3671
m_CRC32Table(151) = &H6E6B06E7
m_CRC32Table(152) = &HFED41B76
m_CRC32Table(153) = &H89D32BE0
m_CRC32Table(154) = &H10DA7A5A
m_CRC32Table(155) = &H67DD4ACC
m_CRC32Table(156) = &HF9B9DF6F
m_CRC32Table(157) = &H8EBEEFF9
m_CRC32Table(158) = &H17B7BE43
m_CRC32Table(159) = &H60B08ED5
m_CRC32Table(160) = &HD6D6A3E8
m_CRC32Table(161) = &HA1D1937E
m_CRC32Table(162) = &H38D8C2C4
m_CRC32Table(163) = &H4FDFF252
m_CRC32Table(164) = &HD1BB67F1
m_CRC32Table(165) = &HA6BC5767
m_CRC32Table(166) = &H3FB506DD
m_CRC32Table(167) = &H48B2364B
m_CRC32Table(168) = &HD80D2BDA
m_CRC32Table(169) = &HAF0A1B4C
m_CRC32Table(170) = &H36034AF6
m_CRC32Table(171) = &H41047A60
m_CRC32Table(172) = &HDF60EFC3
m_CRC32Table(173) = &HA867DF55
m_CRC32Table(174) = &H316E8EEF
m_CRC32Table(175) = &H4669BE79
m_CRC32Table(176) = &HCB61B38C
m_CRC32Table(177) = &HBC66831A
m_CRC32Table(178) = &H256FD2A0
m_CRC32Table(179) = &H5268E236
m_CRC32Table(180) = &HCC0C7795
m_CRC32Table(181) = &HBB0B4703
m_CRC32Table(182) = &H220216B9
m_CRC32Table(183) = &H5505262F
m_CRC32Table(184) = &HC5BA3BBE
m_CRC32Table(185) = &HB2BD0B28
m_CRC32Table(186) = &H2BB45A92
m_CRC32Table(187) = &H5CB36A04
m_CRC32Table(188) = &HC2D7FFA7
m_CRC32Table(189) = &HB5D0CF31
m_CRC32Table(190) = &H2CD99E8B
m_CRC32Table(191) = &H5BDEAE1D
m_CRC32Table(192) = &H9B64C2B0
m_CRC32Table(193) = &HEC63F226
m_CRC32Table(194) = &H756AA39C
m_CRC32Table(195) = &H26D930A
m_CRC32Table(196) = &H9C0906A9
m_CRC32Table(197) = &HEB0E363F
m_CRC32Table(198) = &H72076785
m_CRC32Table(199) = &H5005713
m_CRC32Table(200) = &H95BF4A82
m_CRC32Table(201) = &HE2B87A14
m_CRC32Table(202) = &H7BB12BAE
m_CRC32Table(203) = &HCB61B38
m_CRC32Table(204) = &H92D28E9B
m_CRC32Table(205) = &HE5D5BE0D
m_CRC32Table(206) = &H7CDCEFB7
m_CRC32Table(207) = &HBDBDF21
m_CRC32Table(208) = &H86D3D2D4
m_CRC32Table(209) = &HF1D4E242
m_CRC32Table(210) = &H68DDB3F8
m_CRC32Table(211) = &H1FDA836E
m_CRC32Table(212) = &H81BE16CD
m_CRC32Table(213) = &HF6B9265B
m_CRC32Table(214) = &H6FB077E1
m_CRC32Table(215) = &H18B74777
m_CRC32Table(216) = &H88085AE6
m_CRC32Table(217) = &HFF0F6A70
m_CRC32Table(218) = &H66063BCA
m_CRC32Table(219) = &H11010B5C
m_CRC32Table(220) = &H8F659EFF
m_CRC32Table(221) = &HF862AE69
m_CRC32Table(222) = &H616BFFD3
m_CRC32Table(223) = &H166CCF45
m_CRC32Table(224) = &HA00AE278
m_CRC32Table(225) = &HD70DD2EE
m_CRC32Table(226) = &H4E048354
m_CRC32Table(227) = &H3903B3C2
m_CRC32Table(228) = &HA7672661
m_CRC32Table(229) = &HD06016F7
m_CRC32Table(230) = &H4969474D
m_CRC32Table(231) = &H3E6E77DB
m_CRC32Table(232) = &HAED16A4A
m_CRC32Table(233) = &HD9D65ADC
m_CRC32Table(234) = &H40DF0B66
m_CRC32Table(235) = &H37D83BF0
m_CRC32Table(236) = &HA9BCAE53
m_CRC32Table(237) = &HDEBB9EC5
m_CRC32Table(238) = &H47B2CF7F
m_CRC32Table(239) = &H30B5FFE9
m_CRC32Table(240) = &HBDBDF21C
m_CRC32Table(241) = &HCABAC28A
m_CRC32Table(242) = &H53B39330
m_CRC32Table(243) = &H24B4A3A6
m_CRC32Table(244) = &HBAD03605
m_CRC32Table(245) = &HCDD70693
m_CRC32Table(246) = &H54DE5729
m_CRC32Table(247) = &H23D967BF
m_CRC32Table(248) = &HB3667A2E
m_CRC32Table(249) = &HC4614AB8
m_CRC32Table(250) = &H5D681B02
m_CRC32Table(251) = &H2A6F2B94
m_CRC32Table(252) = &HB40BBE37
m_CRC32Table(253) = &HC30C8EA1
m_CRC32Table(254) = &H5A05DF1B
m_CRC32Table(255) = &H2D02EF8D
Const ASM As String = “5589E557565053518B45088B008B750
C8B7D108B4D1431DB8A1E30C3C1E80833049F464975F28B4D08890
1595B585E5F89EC5DC21000″
ReDim m_CRC32Asmbl(0 To Len(ASM) \ 2 – 1) ‘Initialize CRC32 precompiled assembly code
For i = 1 To Len(ASM) Step 2
m_CRC32Asmbl(i \ 2) = Val(”&H” & Mid$(ASM, i, 2))
Next i
End SubLalu kopi pastekan source dibawah ini dan letakan pada class module cGetFileIcon
Code:
Option Explicit
‘Author : Noel A. Dacara (noeldacara@yahoo.com)
‘Modified by: YaDoY666
‘Modified API Declaration
Private Declare Function SHGetFileInfo Lib “shell32.dll”
Alias “SHGetFileInfoA” (ByVal pszPath As String,
ByVal dwFileAttributes As Long,
ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As ESHGetFileInfoFlagConstants) As Long
Private Declare Sub OleCreatePictureIndirect
Lib “oleaut32.dll” (ByRef lpPictDesc As PictDesc,
ByRef riid As Guid, ByVal fOwn As Long, ByRef lplpvObj
As IPictureDisp)
‘API Constants
Private Const ERRORAPI As Long = 0
Private Const MAX_PATH As Long = 260
‘API Types
Private Type Guid
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type PictDesc
cbSizeofStruct As Long
picType As Long
hImage As Long
xExt As Long
yExt As Long
End Type
Private Type SHFILEINFO
hIcon As Long ‘ : icon
iIcon As Long ‘ : icondex
dwAttributes As Long ‘ : SFGAO_ flags
szDisplayName As String * MAX_PATH ‘ : display name (or path)
szTypeName As String * 80 ‘ : type name
End Type
‘User-Defined API Enum
Private Enum ESHGetFileInfoFlagConstants
SHGFI_ATTRIBUTES = &H800 ‘get file attributes
SHGFI_DISPLAYNAME = &H200 ‘get display name
SHGFI_EXETYPE = &H2000 ‘get exe type
SHGFI_ICON = &H100 ‘get icon handle and index
SHGFI_LARGEICON = &H0 ‘get file’s large icon
SHGFI_LINKOVERLAY = &H8000 ‘add link overlay on the icon
SHGFI_OPENICON = &H2 ‘get file’s open icon
SHGFI_SELECTED = &H10000 ‘blend icon with the system highlight color
SHGFI_SHELLICONSIZE = &H4 ‘get shell-sized icon
SHGFI_SMALLICON = &H1 ‘get file’s small icon
SHGFI_SYSICONINDEX = &H4000 ‘get icon index from system image list
SHGFI_TYPENAME = &H400 ‘get file type description
SHGFI_USEFILEATTRIBUTES = &H10 ‘use dwFileAttributes parameter
End Enum
Enum EFileIconTypeConstants
LargeIcon = 0
SmallIcon = 1
End Enum
Enum EFileExeTypeConstants
MSDosApp = 2 ‘MS-DOS .EXE, .COM or .BAT file
NonExecutable = 0 ‘Nonexecutable file or an error condition
Win32Console = 3 ‘Win32 console application
WindowsApp = 1 ‘Windows application
End Enum
‘Variable Declarations
Private m_File As String
Private m_Handle As Long
Private m_IconType As EFileIconTypeConstants
Private m_OpenState As Boolean
Private m_Overlay As Boolean
Private m_Selected As Boolean
Property Get DisplayName(Optional File) As String
‘Returns the display name of the specified file.
Dim p_Null As Long
Dim p_Ret As Long
Dim p_SHFI As SHFILEINFO
If IsMissing(File) Then
File = m_File
End If
p_Ret = SHGetFileInfo(CStr(File), 0&, p_SHFI, Len(p_SHFI), SHGFI_DISPLAYNAME)
If Not p_Ret = ERRORAPI Then
DisplayName = p_SHFI.szDisplayName
p_Null = InStr(1, DisplayName, vbNullChar)
If p_Null > 0& Then
DisplayName = Left$(DisplayName, p_Null – 1)
End If
End If
End Property
Property Get ExeType(Optional File) As EFileExeTypeConstants
‘Returns the display name of the specified file.
Dim p_Ret As Long
Dim p_SHFI As SHFILEINFO
If IsMissing(File) Then
File = m_File
End If
p_Ret = SHGetFileInfo(CStr(File), 0&, p_SHFI, Len(p_SHFI), SHGFI_EXETYPE)
If p_Ret = 0 Then
ExeType = NonExecutable
Else
If HiWord(p_Ret) > 0 Then ‘NE 0×00004E45 or PE 0×00005045
ExeType = WindowsApp
Else
Select Case LoWord(p_Ret)
Case 23117 ‘MZ 0×00004D5A
ExeType = MSDosApp
Case 17744 ‘PE 0×00005045
ExeType = Win32Console
End Select
End If
End If
End Property
Property Get File() As String
‘Returns/sets the complete file path to be used.
File = m_File
End Property
Property Let File(Value As String)
m_File = Value
End Property
Property Get Handle() As Long
‘Returns/sets the icon handle to be used by the IconEx property.
Handle = m_Handle
End Property
Property Let Handle(Value As Long)
m_Handle = Value
End Property
Property Get IconType() As EFileIconTypeConstants
‘Returns/sets the type of icon to retrieve.
IconType = m_IconType
End Property
Property Let IconType(Value As EFileIconTypeConstants)
m_IconType = Value
End Property
Property Get Icon(Optional File, Optional IconType) As IPictureDisp
‘Returns the icon of the specified file.
If IsMissing(File) Then
File = m_File
End If
If IsMissing(IconType) Then
IconType = m_IconType
End If
Dim p_Flags As ESHGetFileInfoFlagConstants
Dim p_hIcon As Long
Dim p_Ret As Long
Dim p_SHFI As SHFILEINFO
If m_IconType = LargeIcon Then
p_Flags = SHGFI_ICON Or SHGFI_LARGEICON
Else
p_Flags = SHGFI_ICON Or SHGFI_SMALLICON
End If
If m_Overlay Then
p_Flags = p_Flags Or SHGFI_LINKOVERLAY
End If
If m_Selected Then
p_Flags = p_Flags Or SHGFI_SELECTED
Else
p_Flags = p_Flags And Not SHGFI_SELECTED
End If
If m_OpenState Then
p_Flags = p_Flags Or SHGFI_OPENICON
Else
p_Flags = p_Flags And Not SHGFI_OPENICON
End If
p_Ret = SHGetFileInfo(CStr(File), 0&, p_SHFI, Len(p_SHFI), p_Flags)
If Not p_Ret = ERRORAPI Then
p_hIcon = p_SHFI.hIcon
If Not p_hIcon = 0& Then
Set Icon = IconEx(p_hIcon)
End If
End If
End Property
Property Get IconEx(Optional hIcon As Long) As IPictureDisp
‘Returns the file’s icon using the specified icon handle.
If hIcon = 0& Then
hIcon = m_Handle
If hIcon = 0& Then
Exit Property
End If
End If
Dim p_Picture As IPictureDisp
Dim p_PicDesc As PictDesc
Dim p_Guid As Guid
p_PicDesc.cbSizeofStruct = Len(p_PicDesc)
p_PicDesc.picType = vbPicTypeIcon
p_PicDesc.hImage = hIcon
‘IPicture GUID {7BF80980-BF32-101A-8BBB-00AA00300CAB}
With p_Guid
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With
‘From vbAccelerator… (http://www.vbaccelerator.com)
OleCreatePictureIndirect p_PicDesc, p_Guid, True, p_Picture
Set IconEx = p_Picture
End Property
Property Get LinkOverlay() As Boolean
‘Returns/sets a value to determine if a linkoverlay icon is displayed on the icon.
LinkOverlay = m_Overlay
End Property
Property Let LinkOverlay(Value As Boolean)
m_Overlay = Value
End Property
Property Get OpenState() As Boolean
‘Returns/sets a value to determine if the icon will be in open state. (Ex. Folders)
OpenState = m_OpenState
End Property
Property Let OpenState(Value As Boolean)
m_OpenState = Value
End Property
Property Get Selected() As Boolean
‘Returns/sets a value to determine if the icon is in selected state.
Selected = m_Selected
End Property
Property Let Selected(Value As Boolean)
m_Selected = Value
End Property
Property Get TypeName(Optional File) As String
‘Returns the type name of the specified file.
Dim p_Null As Long
Dim p_Ret As Long
Dim p_SHFI As SHFILEINFO
If IsMissing(File) Then
File = m_File
End If
p_Ret = SHGetFileInfo(CStr(File), 0&, p_SHFI, Len(p_SHFI), SHGFI_TYPENAME)
If Not p_Ret = ERRORAPI Then
TypeName = p_SHFI.szTypeName
p_Null = InStr(1, TypeName, vbNullChar)
If p_Null > 0& Then
TypeName = Left$(TypeName, p_Null – 1)
End If
End If
End Property
‘Private properties
Private Property Get HiWord(DWord As Long) As Long
HiWord = (DWord And &HFFFF0000) \ &H10000
End Property
Private Property Get LoWord(DWord As Long) As Long
If DWord And &H8000& Then
LoWord = DWord Or &HFFFF0000
Else
LoWord = DWord And &HFFFF&
End If
End PropertyLalu kopi pastekan source code dibwah ini dan letakan pada class module cScanProcesses
Code:
Option Explicit
‘Author : Noel A. Dacara (noeldacara@yahoo.com)
‘Modified by: YaDoY666
‘API Declarations
Private Declare Function CloseHandle Lib “kernel32.dll” (ByVal hObject As Long) As Long
Private Declare Function CreateToolhelp32Snapshot Lib “kernel32.dll”
(ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function EnumProcessModules Lib “psapi.dll”
(ByVal hProcess As Long, ByRef lphModule As Long,
ByVal cb As Long, ByRef lpcbNeeded As Long) As Long
Private Declare Function GetCurrentProcess Lib “kernel32.dll” () As Long
Private Declare Function GetModuleFileNameEx Lib “psapi.dll”
Alias “GetModuleFileNameExA” (ByVal hProcess As Long,
ByVal hModule As Long, ByVal lpFilename As String,
ByVal nSize As Long) As Long
Private Declare Function GetVersion Lib “kernel32.dll” () As Long
Private Declare Function GetWindowsDirectory Lib “kernel32.dll”
Alias “GetWindowsDirectoryA” (ByVal lpBuffer As String,
ByVal nSize As Long) 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 OpenProcessToken Lib “advapi32.dll”
(ByVal ProcessHandle As Long, ByVal DesiredAccess
As Long, ByRef TokenHandle As Long) As Long
Private Declare Function Process32First Lib “kernel32.dll”
(ByVal hSnapshot As Long, ByRef lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib “kernel32.dll”
(ByVal hSnapshot As Long, ByRef lppe As PROCESSENTRY32) As Long
‘Modified API Declaration
Private Declare Function AdjustTokenPrivileges Lib “advapi32.dll”
(ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long,
ByRef NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long,
ByVal PreviousState As Long, ByVal ReturnLength As Long) As Long
Private Declare Function LookupPrivilegeValue Lib “advapi32.dll”
Alias “LookupPrivilegeValueA” (ByVal lpSystemName As String,
ByVal lpName As String, ByRef lpLuid As LUID) As Long
Private Declare Function TerminateProcess32 Lib “kernel32.dll”
Alias “TerminateProcess” (ByVal hProcess As Long,
ByVal uExitCode As Long) As Long
‘API Constants
Private Const ANYSIZE_ARRAY As Long = 1
Private Const MAX_PATH As Long = 260
Private Const PROCESS_QUERY_INFORMATION As Long = (&H400)
Private Const PROCESS_VM_READ As Long = (&H10)
Private Const SE_DEBUG_NAME As String = “SeDebugPrivilege”
Private Const SE_PRIVILEGE_ENABLED As Long = &H2
Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
Private Const SYNCHRONIZE As Long = &H100000
Private Const TH32CS_SNAPPROCESS As Long = &H2
Private Const TOKEN_ADJUST_PRIVILEGES As Long = &H20
Private Const TOKEN_QUERY As Long = &H8
Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED
Or SYNCHRONIZE Or &HFFF)
‘API Types
Private Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
Private Type LUID
lowpart As Long
highpart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
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 Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
‘Variable Declarations
Private m_Cancel As Boolean
Private m_FullPathName As String
Private m_NumProcesses As Integer
Private m_ProcessID As Long
Private m_Scanning As Boolean
Private m_SystemProcess As Boolean
Event CurrentProcess(File As String, Path As String, ID As Long,
Terminate As Boolean)
‘Occurs everytime a process is scanned.
Event DoneScanning(TotalProcesses As Integer)
‘Occures after scanning all processes.
#If False Then
Private File, Path, ID, Terminate, TotalProcesses
#End If
Property Get SystemProcesses() As Boolean
SystemProcesses = m_SystemProcess
End Property
Property Let SystemProcesses(Value As Boolean)
m_SystemProcess = Value
End Property
Property Get CurrentProcessID() As Long
CurrentProcessID = m_ProcessID
End Property
Property Get CurrentProcessPath() As String
CurrentProcessPath = m_FullPathName
End Property
Property Get Scanning() As Boolean
Scanning = m_Scanning
End Property
Property Get TotalProcesses() As Integer
TotalProcesses = m_NumProcesses
End Property
‘Procedures
Sub BeginScanning()
m_Cancel = False
m_FullPathName = “”
m_NumProcesses = 0
m_Scanning = True
Call ScanForProcesses
m_Scanning = False
m_Cancel = False
m_FullPathName = “”
m_ProcessID = -1
RaiseEvent DoneScanning((m_NumProcesses))
End Sub
Sub CancelScanning()
m_Cancel = True
End Sub
Function TerminateProcess(Optional ProcessID As Long = -1) As Boolean
scanned process.
If ProcessID = -1 Then
ProcessID = Me.CurrentProcessID ‘Get ID of currently scanned process
If ProcessID = -1 Then
Exit Function
End If
End If
Dim p_Privileges As TOKEN_PRIVILEGES
Dim p_Token As Long
If GetVersion >= 0 Then
If OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, p_Token) = 0 Then
GoTo End_Function
End If
If LookupPrivilegeValue(”", SE_DEBUG_NAME, p_Privileges.Privileges(ANYSIZE_ARRAY).pLuid) = 0 Then
GoTo End_Function
End If
p_Privileges.PrivilegeCount = 1
p_Privileges.Privileges(ANYSIZE_ARRAY).Attributes = SE_PRIVILEGE_ENABLED
If AdjustTokenPrivileges(p_Token, 0&, p_Privileges, 0&, 0&, 0&) = 0 Then
GoTo End_Function
End If
End If
Dim p_Process As Long
Dim p_Result As Long
p_Process = OpenProcess(PROCESS_ALL_ACCESS, 0&, ProcessID)
If Not p_Process = 0 Then
‘Attempt to terminate the process
p_Result = TerminateProcess32(p_Process, 0&)
DoEvents
TerminateProcess = (Not p_Result = 0)
CloseHandle p_Process
End If
If GetVersion >= 0 Then
‘Restore original privilege
p_Privileges.Privileges(ANYSIZE_ARRAY).Attributes = 0
AdjustTokenPrivileges p_Token, 0&, p_Privileges, 0&, 0&, 0&
End_Function:
If Not p_Token = 0 Then
Call CloseHandle(p_Token)
End If
End If
End Function
‘Private Procedures
Private Sub ScanForProcesses()
DoEvents ‘Process other system events before scanning for processes
Dim p_Snapshot As Long
p_Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If Not p_Snapshot = 0 Then
Dim p_NullPos As Integer
Dim p_Process As Long
Dim p_ProcessEntry As PROCESSENTRY32
Dim p_ProcessID As Long
Dim p_ProcessName As String
Dim p_ProcessPath As String
Dim p_Terminate As Boolean
p_ProcessEntry.dwSize = Len(p_ProcessEntry)
p_Process = Process32First(p_Snapshot, p_ProcessEntry)
Do While p_Process ‘Iterate through all processes
If m_Cancel Then
Exit Do ‘Abort the whole scanning process
End If
DoEvents ‘Ensure that the system processes other events
p_ProcessName = p_ProcessEntry.szExeFile
p_NullPos = InStr(1, p_ProcessName, vbNullChar)
If Not p_NullPos = 0 Then
p_ProcessName = Left(p_ProcessName, p_NullPos – 1)
End If
p_ProcessID = p_ProcessEntry.th32ProcessID
p_ProcessPath = ProcessPath(p_ProcessID)
If Not m_SystemProcess Then
If p_ProcessPath = “SYSTEM” Then
GoTo Next_Process ‘System processes not included. Get next process instead.
End If
End If
m_ProcessID = p_ProcessID
m_NumProcesses = m_NumProcesses + 1
p_Terminate = False
RaiseEvent CurrentProcess((p_ProcessName), (p_ProcessPath), (p_ProcessID), p_Terminate)
If p_Terminate Then
Call TerminateProcess(p_ProcessID)
End If
Next_Process:
p_ProcessEntry.szExeFile = String(MAX_PATH, 0)
p_Process = Process32Next(p_Snapshot, p_ProcessEntry)
Loop
End If
End Sub
‘Private Functions
Private Function ProcessPath(ByVal ID As Long) As String
If m_Cancel Then
Exit Function ‘Abort the whole scanning process
End If
Dim p_Process As Long
p_Process = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0&, ID)
If Not p_Process = 0 Then
Dim p_Modules(1 To 200) As Long
Dim p_Needed As Long
Dim p_Ret As Long
p_Ret = EnumProcessModules(p_Process, p_Modules(1), 200, p_Needed)
If Not p_Ret = 0 Then
Dim p_ModuleName As String * MAX_PATH
Dim p_Size As Long
p_Size = 500
p_Ret = GetModuleFileNameEx(p_Process, p_Modules(1), p_ModuleName, p_Size)
ProcessPath = Left$(p_ModuleName, p_Ret)
ProcessPath = Replace$(ProcessPath, “\??\”, Empty)
ProcessPath = Replace$(ProcessPath, “\SystemRoot\”, WindowsDirectory & “\”)
m_FullPathName = ProcessPath ‘Save full path with filename
ProcessPath = Left$(ProcessPath, InStrRev(ProcessPath, “\”)) ‘Return without the filename
End If
p_Ret = CloseHandle(p_Process)
End If
If ProcessPath = Empty Then
ProcessPath = “THIS IS A SYSTEM PROCESS”
End If
End Function
‘Private Properties
Private Property Get WindowsDirectory()
Dim p_Buffer As String * MAX_PATH
Dim p_NullPos As Integer
If Not GetWindowsDirectory(p_Buffer, MAX_PATH) = 0 Then
p_NullPos = InStr(1, p_Buffer, vbNullChar)
WindowsDirectory = Left(p_Buffer, p_NullPos – 1)
End If
End Property
‘Class Procedures
Private Sub Class_Initialize()
m_FullPathName = Empty
m_ProcessID = -1
m_SystemProcess = False
End Submohon maap kalo ada kekurangan ^^




![[Image: 630681.png]](http://luveronation.nice-forum.net/users/2212/35/35/96/smiles/630681.png)


