Mohammad.sweets
سه شنبه 10 مرداد 1391, 19:28 عصر
سلام به همه.....
 
من یه برنامه دارم و میخوام از طریق این برنامه یه برنامه ی دیگرو از کار بندازم یعنی اون برنامرو از لیست
procsses 
 
حذف کنم   task Manager 
 
من اینکارو با کد زیر انجام دادم 
Shell "taskkill /f /im " & Chr(34) & rl.Text & Chr(34), vbHide
 هست برام مشکل ساز شده  CMD  اما چون این دستور یک دستور
 
اگه میشه کدی بدید که هم کوتاه باشه ....هم سریع تر از این دستور عمل کنه.....و هم از توابع خود وی بی 
 
:ناراحت::ناراحت:....باشه
AbbasVB
سه شنبه 10 مرداد 1391, 19:54 عصر
این رو توی ماژول بذار
Public Declare Function GetVersion Lib "kernel32" () As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
Public Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Public Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Public Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As Any, ReturnLength As Any) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Public Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As Any) As Long
Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As Any) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function InitCommonControls Lib "Comctl32.dll" () As Long
Public Const TOKEN_ADJUST_PRIVILEGES = &H20
Public Const TOKEN_QUERY = &H8
Public Const SE_PRIVILEGE_ENABLED = &H2
Public Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Public Const PROCESS_VM_READ = 16
Public Const TH32CS_SNAPHEAPLIST = &H1
Public Const TH32CS_SNAPPROCESS = &H2
Public Const TH32CS_SNAPTHREAD = &H4
Public Const TH32CS_SNAPMODULE = &H8
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST + TH32CS_SNAPPROCESS + TH32CS_SNAPTHREAD + TH32CS_SNAPMODULE)
Public 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
Private Type LUID
   lowpart As Long
   highpart As Long
End Type
Public reg
Public virusName1, virusName2 As String
Public PathVirus As String
Public drivemanestr(24) As String
Public strTemp As String, strUserName As String
Private Type TOKEN_PRIVILEGES
    PrivilegeCount As Long
    LuidUDT As LUID
    Attributes As Long
End Type
Public Function GiveMeThatHandle(ExeName) As Long
Dim P_Pid, P_Proc, adr, bfLg As Long
Dim res&, ant&
Dim u As Integer
Dim Process As PROCESSENTRY32
res = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
If res <> 0 Then
   Process.dwSize = Len(Process)
   ant = Process32First(res, Process)
   u = 0
   
Do
  a = LCase(Process.szExeFile)
    If InStr(a, ExeName) Then pids = Process.th32ProcessID
    ant = Process32Next(res, Process)
  u = u + 1
Loop Until ant = 0
End If
P_Pid = pids
hProcessID = P_Pid
DoEvents
    Dim hToken As Long
    Dim hProcess As Long
    Dim tp As TOKEN_PRIVILEGES
    
    If GetVersion() >= 0 Then
        If OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES Or _
            TOKEN_QUERY, hToken) = 0 Then
            GoTo CleanUp
        End If
        If LookupPrivilegeValue("", "SeDebugPrivilege", tp.LuidUDT) = 0 Then
            GoTo CleanUp
        End If
        tp.PrivilegeCount = 1
        tp.Attributes = SE_PRIVILEGE_ENABLED
        If AdjustTokenPrivileges(hToken, False, tp, 0, ByVal 0&, _
            ByVal 0&) = 0 Then
            GoTo CleanUp
        End If
    End If
    P_Proc = OpenProcess(PROCESS_ALL_ACCESS, 0, hProcessID)
    GiveMeThatHandle = P_Proc
CleanUp:
        If hToken Then CloseHandle hToken
End Function
Public Function EndAnyProcess(ExeName) As Boolean
       Dim phandle As Long
       Const PROCESS_ALL_ACCESS = 0
       phandle = GiveMeThatHandle(ExeName)
       Kill_Process = CBool(TerminateProcess(phandle, uExitCode))
       Call CloseHandle(phandle)
End Function
این هم توی یک دکمه
EndAnyProcess "Notepad.exe"
البته قادر به بستن پروسه های محافظت شده نیست مثل آنتی ویروس ها
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.