프로세스 클리너 프로젝트 진행 중 개발 중단
아래는 프로세스 클리너 프로젝트 내 modCleaner.bas의 코드입니다. 여러 프로젝트가 함께 겹치다보니, 프로세스 클리너가 불완전한, 완성되지 못한 상태로 남아있었습니다. 제대로 동작하지 않을 수도 있으니, 그저 참고용으로 쓰시면 되겠네요.
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 Sub CloseHandle Lib "kernel32" (ByVal hPass As Long) Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Const PROCESS_TERMINATE As Long = (&H1) Private Declare Function TerminateProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long) Private Const TH32CS_SNAPPROCESS As Long = &H2 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 * 260 End Type Public UString As String Private Function GetPidByImage(ByVal image As String) As Long On Local Error GoTo ErrOut: Dim hSnapShot As Long Dim uProcess As PROCESSENTRY32 Dim r As Long, l As Long hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&) If hSnapShot = 0 Then Exit Function uProcess.dwSize = Len(uProcess) r = Process32First(hSnapShot, uProcess) l = Len(image) If l = 0 Then Exit Function Do While r If LCase(Left(uProcess.szExeFile, l)) = LCase(image) Then GetPidByImage = uProcess.th32ProcessID Exit Do End If r = Process32Next(hSnapShot, uProcess) Loop Call CloseHandle(hSnapShot) ErrOut: End Function Private Sub KillPID(ByVal pid As Long) On Local Error Resume Next Dim h As Long If pid = 0 Then Exit Sub h = OpenProcess(PROCESS_TERMINATE, False, pid) TerminateProcess h, 0 CloseHandle h Sleep 1000 ErrOut: End Sub Public Function ProcessList(List As ListBox) As Boolean On Error GoTo WMIError Dim oWMI As Object, oQuery As Object, oProcessObject As Object arrData = Array("System Idle Process", "System", "csrss.exe", "services.exe", "lsass.exe", "svchost.exe" & _ "", "wininit.exe", "SearchIndexer.exe", "winlogon.exe", "explorer.exe", "dwm.exe", "audiodg.exe", "smss.exe" & _ "", "ctfmon.exe", "PCleaner.exe") Set oWMI = GetObject("winmgmts:") On Error GoTo 0 List.Clear Set oQuery = oWMI.ExecQuery("SELECT * FROM win32_process") For Each oProcessObject In oQuery For i = 0 To UBound(arrData) If arrData(i) = oProcessObject.Name Then GoTo Passed Next i List.AddItem oProcessObject.Name Passed: Next ProcessList = True Exit Function WMIError: ProcessList = False End Function Public Function ProcessClear(List As ListBox) As Boolean For i = 0 To List.ListCount - 1 KillPID GetPidByImage(List.List(i)) Next i End Function Public Function ProgramList(List As ListBox) As String On Error Resume Next Dim Application Dim Checker As Boolean UString = vbNullString Checker = False Set ws = CreateObject("WScript.Shell") Set Reg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\." & "\root\default:StdRegProv") kp = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" Reg.EnumKey &H80000002, kp, subkeys For Each subkey In subkeys Application = ws.RegRead("HKLM\" & kp & "\" & subkey & "\DisplayName") RawGuid = ws.RegRead("HKLM\" & kp & "\" & subkey & "\UninstallString") Publisher = ws.RegRead("HKLM\" & kp & "\" & subkey & "\Publisher") Guid = Mid(RawGuid, InStr(RawGuid, "{"), 38) If Publisher <> "Microsoft Corporation" And Publisher <> "Oracle" And Publisher <> "NVIDIA Corporation" & _ "" And Publisher <> "Sun Microsystems, Inc." And Publisher <> "Haansoft" And RawGuid <> vbNullString Then For i = 0 To List.ListCount - 1 If List.List(i) = Application Then List.RemoveItem i End If Next i List.AddItem Application & " [" & RawGuid & "]" End If Next Set ws = Nothing End Function
'소스 관련' 카테고리의 다른 글
유용한 getImageFromURL, DownloadRemoteImageFile 함수 (4) | 2012.12.02 |
---|---|
POST/GET Transmitter 프로젝트. (0) | 2012.12.02 |
캡션에 특정 단어가 들어가있으면 프로세스 종료 TerminateTask. (0) | 2012.08.01 |
위젯 용량체크 프로그램 소스 (0) | 2012.07.18 |
네이버 카페 최신글 불러오기 소스 (0) | 2012.07.14 |