B
bobi_
hey,
ich möchte dritt programme pausieren. - funktioniert soweit auch perfekt bei allen diensten die von dem user "admin" (mir) ausgeführt werden.
programme die von "system" ausgeführt werden werden aber leider nicht pausiert. habt ihr ne idee?
code:
dankeschön
ich möchte dritt programme pausieren. - funktioniert soweit auch perfekt bei allen diensten die von dem user "admin" (mir) ausgeführt werden.
programme die von "system" ausgeführt werden werden aber leider nicht pausiert. habt ihr ne idee?
code:
Code:
Public Type PROCESS
ID As Long
ExeFile As String
End Type
Public Type THREAD
ID As Long
OwnerProcess As Long
End Type
Private Const TH32CS_SNAPPROCESS = &H2
Private Const TH32CS_SNAPTHREAD = &H4
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const THREAD_SUSPEND_RESUME = &H2
Private Const MAX_PATH = 260
Private Const hNull = 0
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 THREADENTRY32
dwSize As Long
cntUsage As Long
th32ThreadID As Long
th32OwnerProcessID As Long
tpBasePri As Long
tpDeltaPri As Long
dwFlags As Long
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Thread32First Lib "kernel32" (ByVal hSnapshot As Long, lpte As THREADENTRY32) As Long
Private Declare Function Thread32Next Lib "kernel32" (ByVal hSnapshot As Long, lpte As THREADENTRY32) As Long
Private Declare Function OpenThread Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwThreadId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function SuspendThread Lib "kernel32" (ByVal hThread As Long) As Long
Private Declare Function ResumeThread Lib "kernel32" (ByVal hThread As Long) As Long
Public Function ListProcesses(Processes() As PROCESS) As Long
Dim aExeName() As String
Dim f As Long, sname As String
Dim hSnap As Long, proc As PROCESSENTRY32
ReDim Processes(0)
ListProcesses = 0
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If hSnap = hNull Then Exit Function
proc.dwSize = Len(proc)
f = Process32First(hSnap, proc)
Do While f
sname = Left$(proc.szExeFile, InStr(1, proc.szExeFile, Chr(0)) - 1)
aExeName = Split(sname, "\")
sname = aExeName(UBound(aExeName))
ReDim Preserve Processes(UBound(Processes) + 1)
Processes(UBound(Processes)).ID = proc.th32ProcessID
Processes(UBound(Processes)).ExeFile = sname
ListProcesses = UBound(Processes)
f = Process32Next(hSnap, proc)
Loop
End Function
Public Function ListThreads(Threads() As THREAD) As Long
Dim f As Long
Dim hSnap As Long, THREAD As THREADENTRY32
ReDim Threads(0)
ListThreads = 0
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0)
If hSnap = hNull Then Exit Function
THREAD.dwSize = Len(THREAD)
f = Thread32First(hSnap, THREAD)
Do While f
ReDim Preserve Threads(UBound(Threads) + 1)
Threads(UBound(Threads)).ID = THREAD.th32ThreadID
Threads(UBound( _
Threads)).OwnerProcess = THREAD.th32OwnerProcessID
ListThreads = UBound(Threads)
f = Thread32Next(hSnap, THREAD)
Loop
End Function
Public Function VBSuspendThread(ThreadID As Long) As Long
Dim hThread As Long
VBSuspendThread = -1
hThread = OpenThread( _
STANDARD_RIGHTS_REQUIRED Or THREAD_SUSPEND_RESUME, 0, ThreadID)
If hThread <> hNull Then
VBSuspendThread = SuspendThread(hThread)
Call CloseHandle(hThread)
End If
End Function
Public Function VBResumeThread(ThreadID As Long) As Long
Dim hThread As Long
VBResumeThread = -1
hThread = OpenThread( _
STANDARD_RIGHTS_REQUIRED Or THREAD_SUSPEND_RESUME, 0, ThreadID)
If hThread <> hNull Then
VBResumeThread = ResumeThread(hThread)
Call CloseHandle(hThread)
End If
End Function
Public Function SuspendProcessByName(ProcName As String) As Long
Dim Processes() As PROCESS
Dim numProcesses As Long
Dim X As Long
SuspendProcessByName = 0
numProcesses = ListProcesses(Processes)
For X = 1 To numProcesses
If LCase(Processes(X).ExeFile) = LCase(ProcName) Then
SuspendProcessByName = SuspendProcessByPID(Processes(X).ID)
End If
Next
End Function
Public Function SuspendProcessByPID(ProcID As Long) As Long
Dim Threads() As THREAD
Dim numThreads As Long
Dim X As Long
Dim numThreadsSuspended As Long
numThreadsSuspended = 0
numThreads = ListThreads(Threads)
For X = 1 To numThreads
If Threads(X).OwnerProcess = ProcID Then
If VBSuspendThread(Threads(X).ID) > -1 Then
numThreadsSuspended = numThreadsSuspended + 1
End If
End If
Next
SuspendProcessByPID = numThreadsSuspended
End Function
Public Function ResumeProcessByName(ProcName As String) As Long
Dim Processes() As PROCESS
Dim numProcesses As Long
Dim X As Long
ResumeProcessByName = 0
numProcesses = ListProcesses(Processes)
For X = 1 To numProcesses
If LCase(Processes(X).ExeFile) = LCase(ProcName) Then
ResumeProcessByName = ResumeProcessByPID(Processes(X).ID)
End If
Next
End Function
Public Function ResumeProcessByPID(ProcID As Long) As Long
Dim Threads() As THREAD
Dim numThreads As Long
Dim X As Long
Dim numThreadsResumed As Long
numThreadsResumed = 0
numThreads = ListThreads(Threads)
For X = 1 To numThreads
If Threads(X).OwnerProcess = ProcID Then
If VBResumeThread(Threads(X).ID) > -1 Then
numThreadsResumed = numThreadsResumed + 1
End If
End If
Next
ResumeProcessByPID = numThreadsResumed
End Function
dankeschön
Zuletzt bearbeitet von einem Moderator: