Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: Завершить процес Добавлено: 01.09.09 06:20  

Автор вопроса:  Эдик
Привет всем. Как мне програмно Завершить процесс проги которая находиться в памяти.(Обычно я это делаю с помощью Диспетчера задач).Известно только имя проги отображ. в дисп.задач

Ответить

  Ответы Всего ответов: 6  

Номер ответа: 1
Автор ответа:
 inferno



Вопросов: 8
Ответов: 39
 Web-сайт: www.streamcash.tk
 Профиль | | #1
Добавлено: 01.09.09 09:36
  1. Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
  2. Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
  3. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
  4. Private Sub Form_Load()
  5.  
  6.     ExitProcess GetExitCodeProcess(GetCurrentProcess, 0)
  7. End Sub

Ответить

Номер ответа: 2
Автор ответа:
 inferno



Вопросов: 8
Ответов: 39
 Web-сайт: www.streamcash.tk
 Профиль | | #2
Добавлено: 01.09.09 09:37
  1. 'Это чтобы получить весь список процессов
  2. Private Sub Form_Load()
  3.     GetProcesses "explorer.exe"
  4. End Sub
  5.  
  6.  
  7.  
  8. Public Declare Function GetProcessMemoryInfo Lib "PSAPI.DLL" (ByVal hProcess As Long, ppsmemCounters As PROCESS_MEMORY_COUNTERS, ByVal cb As Long) As Long
  9. Public Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
  10. Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
  11. Public Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
  12. Public Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
  13. Public Declare Function EnumProcesses Lib "PSAPI.DLL" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
  14. Public Declare Function GetModuleFileNameExA Lib "PSAPI.DLL" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
  15. Public Declare Function EnumProcessModules Lib "PSAPI.DLL" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
  16. Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
  17. Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
  18. Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
  19. Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
  20. Public Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
  21.  
  22.  
  23.  
  24. Public Const PROCESS_QUERY_INFORMATION = 1024
  25. Public Const PROCESS_VM_READ = 16
  26. Public Const MAX_PATH = 260
  27. Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
  28. Public Const SYNCHRONIZE = &H100000
  29. Public Const PROCESS_ALL_ACCESS = &H1F0FFF
  30. Public Const TH32CS_SNAPPROCESS = &H2&
  31. Public Const hNull = 0
  32. Public Const WIN95_System_Found = 1
  33. Public Const WINNT_System_Found = 2
  34. Public Const Default_Log_Size = 10000000
  35. Public Const Default_Log_Days = 0
  36. Public Const SPECIFIC_RIGHTS_ALL = &HFFFF
  37. Public Const STANDARD_RIGHTS_ALL = &H1F0000
  38.  
  39.  
  40. Type MEMORYSTATUS
  41.     dwLength As Long
  42.     dwMemoryLoad As Long
  43.     dwTotalPhys As Long
  44.     dwAvailPhys As Long
  45.     dwTotalPageFile As Long
  46.     dwAvailPageFile As Long
  47.     dwTotalVirtual As Long
  48.     dwAvailVirtual As Long
  49. End Type
  50.  
  51.  
  52. Type PROCESS_MEMORY_COUNTERS
  53.     cb As Long
  54.     PageFaultCount As Long
  55.     PeakWorkingSetSize As Long
  56.     WorkingSetSize As Long
  57.     QuotaPeakPagedPoolUsage As Long
  58.     QuotaPagedPoolUsage As Long
  59.     QuotaPeakNonPagedPoolUsage As Long
  60.     QuotaNonPagedPoolUsage As Long
  61.     PagefileUsage As Long
  62.     PeakPagefileUsage As Long
  63. End Type
  64.  
  65.  
  66. Public Type PROCESSENTRY32
  67.     dwSize As Long
  68.     cntUsage As Long
  69.     th32ProcessID As Long ' This process
  70.     th32DefaultHeapID As Long
  71.     th32ModuleID As Long ' Associated exe
  72.     cntThreads As Long
  73.     th32ParentProcessID As Long ' This process's parent process
  74.     pcPriClassBase As Long ' Base priority of process threads
  75.     dwFlags As Long
  76.     szExeFile As String * 260 ' MAX_PATH
  77.     End Type
  78.  
  79.  
  80. Public Type OSVERSIONINFO
  81.     dwOSVersionInfoSize As Long
  82.     dwMajorVersion As Long
  83.     dwMinorVersion As Long
  84.     dwBuildNumber As Long
  85.     dwPlatformId As Long '1 = Windows 95.
  86.     '2 = Windows NT
  87.     szCSDVersion As String * 128
  88. End Type
  89.  
  90.  
  91. Public Function GetProcesses(ByVal EXEName As String)
  92.  
  93.     Dim booResult As Boolean
  94.     Dim lngLength As Long
  95.     Dim lngProcessID As Long
  96.     Dim strProcessName As String
  97.     Dim lngSnapHwnd As Long
  98.     Dim udtProcEntry As PROCESSENTRY32
  99.     Dim lngCBSize As Long 'Specifies the size, In bytes, of the lpidProcess array
  100.     Dim lngCBSizeReturned As Long 'Receives the number of bytes returned
  101.     Dim lngNumElements As Long
  102.     Dim lngProcessIDs() As Long
  103.     Dim lngCBSize2 As Long
  104.     Dim lngModules(1 To 200) As Long
  105.     Dim lngReturn As Long
  106.     Dim strModuleName As String
  107.     Dim lngSize As Long
  108.     Dim lngHwndProcess As Long
  109.     Dim lngLoop As Long
  110.     Dim b As Long
  111.     Dim c As Long
  112.     Dim e As Long
  113.     Dim d As Long
  114.     Dim pmc As PROCESS_MEMORY_COUNTERS
  115.     Dim lret As Long
  116.     Dim strProcName2 As String
  117.     Dim strProcName As String
  118.  
  119.     'Turn on Error handler
  120.     On Error GoTo Error_handler
  121.  
  122.    booResult = False
  123.  
  124.     EXEName = UCase$(Trim$(EXEName))
  125.     lngLength = Len(EXEName)
  126.  
  127.     'ProcessInfo.bolRunning = False
  128.  
  129.     Select Case getVersion()
  130.         'I'm not bothered about windows 95/98 becasue this class probably wont be used on it anyway.
  131.         Case WIN95_System_Found 'Windows 95/98
  132.  
  133.         Case WINNT_System_Found 'Windows NT
  134.  
  135.             lngCBSize = 8 ' Really needs To be 16, but Loop will increment prior to calling API
  136.             lngCBSizeReturned = 96
  137.  
  138.             Do While lngCBSize <= lngCBSizeReturned
  139.                 DoEvents
  140.                 'Increment Size
  141.                 lngCBSize = lngCBSize * 2
  142.                 'Allocate Memory for Array
  143.                 ReDim lngProcessIDs(lngCBSize / 4) As Long
  144.                 'Get Process ID's
  145.                 lngReturn = EnumProcesses(lngProcessIDs(1), lngCBSize, lngCBSizeReturned)
  146.             Loop
  147.  
  148.             'Count number of processes returned
  149.             lngNumElements = lngCBSizeReturned / 4
  150.             'Loop thru each process
  151.  
  152.             For lngLoop = 1 To lngNumElements
  153.             DoEvents
  154.  
  155.             'Get a handle to the Process and Open
  156.             lngHwndProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, lngProcessIDs(lngLoop))
  157.  
  158.             If lngHwndProcess <> 0 Then
  159.                 'Get an array of the module handles for the specified process
  160.                 lngReturn = EnumProcessModules(lngHwndProcess, lngModules(1), 200, lngCBSize2)
  161.  
  162.                 'If the Module Array is retrieved, Get the ModuleFileName
  163.                 If lngReturn <> 0 Then
  164.  
  165.                     'Buffer with spaces first to allocate memory for byte array
  166.                     strModuleName = Space(MAX_PATH)
  167.  
  168.                     'Must be set prior to calling API
  169.                     lngSize = 500
  170.  
  171.                     'Get Process Name
  172.                     lngReturn = GetModuleFileNameExA(lngHwndProcess, lngModules(1), strModuleName, lngSize)
  173.  
  174.                     'Remove trailing spaces
  175.                     strProcessName = Left(strModuleName, lngReturn)
  176.  
  177.                     'Check for Matching Upper case result
  178.                     strProcessName = UCase$(Trim$(strProcessName))
  179.  
  180.                     strProcName2 = GetElement(Trim(Replace(strProcessName, Chr$(0), "")), "\", 0, 0, GetNumElements(Trim(Replace(strProcessName, Chr$(0), "")), "\") - 1)
  181.  
  182.                     If strProcName2 = EXEName Then
  183.  
  184.                         'Get the Site of the Memory Structure
  185.                         pmc.cb = LenB(pmc)
  186.  
  187.                            lret = GetProcessMemoryInfo(lngHwndProcess, pmc, pmc.cb)
  188.  
  189.                             Debug.Print EXEName & "::" & CStr(pmc.WorkingSetSize / 1024)
  190.  
  191.                     End If
  192.                 End If
  193.             End If
  194.             'Close the handle to this process
  195.             lngReturn = CloseHandle(lngHwndProcess)
  196.             DoEvents
  197.         Next
  198.  
  199.     End Select
  200.  
  201. IsProcessRunning_Exit:
  202.  
  203. 'Exit early to avoid error handler
  204. Exit Function
  205. Error_handler:
  206.     Err.Raise Err, Err.Source, "ProcessInfo", Error
  207.     Resume Next
  208. End Function
  209.  
  210.  
  211. Private Function getVersion() As Long
  212.  
  213.     Dim osinfo As OSVERSIONINFO
  214.     Dim retvalue As Integer
  215.  
  216.     osinfo.dwOSVersionInfoSize = 148
  217.     osinfo.szCSDVersion = Space$(128)
  218.     retvalue = GetVersionExA(osinfo)
  219.     getVersion = osinfo.dwPlatformId
  220.  
  221. End Function
  222.  
  223.  
  224. Private Function StrZToStr(s As String) As String
  225.     StrZToStr = Left$(s, Len(s) - 1)
  226. End Function
  227.  
  228.  
  229.  
  230. Public Function GetElement(ByVal strList As String, ByVal strDelimiter As String, ByVal lngNumColumns As Long, ByVal lngRow As Long, ByVal lngColumn As Long) As String
  231.  
  232.     Dim lngCounter As Long
  233.  
  234.     ' Append delimiter text to the end of the list as a terminator.
  235.     strList = strList & strDelimiter
  236.  
  237.     ' Calculate the offset for the item required based on the number of columns the list
  238.     ' 'strList' has i.e. 'lngNumColumns' and from which row the element is to be
  239.     ' selected i.e. 'lngRow'.
  240.     lngColumn = IIf(lngRow = 0, lngColumn, (lngRow * lngNumColumns) + lngColumn)
  241.  
  242.     ' Search for the 'lngColumn' item from the list 'strList'.
  243.     For lngCounter = 0 To lngColumn - 1
  244.  
  245.         ' Remove each item from the list.
  246.         strList = Mid$(strList, InStr(strList, strDelimiter) + Len(strDelimiter), Len(strList))
  247.  
  248.         ' If list becomes empty before 'lngColumn' is found then just
  249.         ' return an empty string.
  250.         If Len(strList) = 0 Then
  251.             GetElement = ""
  252.             Exit Function
  253.         End If
  254.  
  255.     Next lngCounter
  256.  
  257.     ' Return the sought list element.
  258.     GetElement = Left$(strList, InStr(strList, strDelimiter) - 1)
  259.  
  260. End Function
  261.  
  262.  
  263. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  264. 'Function GetNumElements (ByVal strList As String,
  265. '                         ByVal strDelimiter As String)
  266. '                         As Integer
  267. '
  268. '  strList      = The element list.
  269. '  strDelimiter = The delimiter by which the elements in
  270. '                 'strList' are seperated.
  271. '
  272. '  The function returns an integer which is the count of the
  273. '  number of elements in 'strList'.
  274. '
  275. '  Author: Roger Taylor
  276. '
  277. '  Date:26/12/1998
  278. '
  279. '  Additional Information:
  280. '
  281. '  Revision History:
  282. '
  283. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  284.  
  285. Public Function GetNumElements(ByVal strList As String, ByVal strDelimiter As String) As Integer
  286.  
  287.     Dim intElementCount As Integer
  288.  
  289.     ' If no elements in the list 'strList' then just return 0.
  290.     If Len(strList) = 0 Then
  291.         GetNumElements = 0
  292.         Exit Function
  293.     End If
  294.  
  295.     ' Append delimiter text to the end of the list as a terminator.
  296.     strList = strList & strDelimiter
  297.  
  298.     ' Count the number of elements in 'strlist'
  299.     While InStr(strList, strDelimiter) > 0
  300.         intElementCount = intElementCount + 1
  301.         strList = Mid$(strList, InStr(strList, strDelimiter) + 1, Len(strList))
  302.     Wend
  303.  
  304.     ' Return the number of elements in 'strList'.
  305.     GetNumElements = intElementCount
  306.  
  307. End Function
  308.  
  309.  
  310. 'If you're using VB4 or VB5, uncomment the following function:
  311. 'Function Replace(sInput As String, WhatToReplace As String, ReplaceWith As String) As String
  312.     'Dim Ret As Long
  313.     'Replace = sInput
  314.     'Ret = -Len(ReplaceWith) + 1
  315.     'Do
  316.         'Ret = InStr(Ret + Len(ReplaceWith), Replace, WhatToReplace, vbTextCompare)
  317.         'If Ret = 0 Then Exit Do
  318.         'Replace = Left$(Replace, Ret - 1) + ReplaceWith + Right$(Replace, Len(Replace) - Ret - Len(WhatToReplace) + 1)
  319.     'Loop
  320. 'End Function

Ответить

Номер ответа: 3
Автор ответа:
 AWP



ICQ: 345685652 

Вопросов: 96
Ответов: 1212
 Web-сайт: xawp.narod.ru
 Профиль | | #3
Добавлено: 02.09.09 03:39
Это весь код, чтобы убить один процесс?

Известно только имя проги отображ. в дисп.задач
В приложениях или процессах?

Ответить

Номер ответа: 4
Автор ответа:
 Эдик



Вопросов: 19
Ответов: 23
 Профиль | | #4 Добавлено: 03.09.09 04:52
спасибо за отзыв.А может по проще что ни будь,может есть програмка какая .

Ответить

Номер ответа: 5
Автор ответа:
 Дмитрий Юпатов



Вопросов: 4
Ответов: 457
 Web-сайт: cargomaster.at.ua/
 Профиль | | #5
Добавлено: 03.09.09 09:41
Эдик пишет:
может есть програмка какая

есть - Диспетчер задач:) А еще PROWiSe Manager

Ответить

Номер ответа: 6
Автор ответа:
 Дмитрий Юпатов



Вопросов: 4
Ответов: 457
 Web-сайт: cargomaster.at.ua/
 Профиль | | #6
Добавлено: 03.09.09 09:43
Ну а все ж, скажи:
1) версия студии
2) имя процесса проги во вкладке "Процессы" диспетчера задач известно?

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам