如果知道指定进程的线程数。System.Diagnostics.Process[] arrProcess=System.Diagnostics.Process.GetProcesses("luoyong");
foreach(System.Diagnostics.Process tmpPcs in arrProcess)//遍历进程数组
{
int Threadcount=0;//线程数
ListViewItem ViewItem=listView.Items.Add(tmpPcs.ProcessName);
System.Diagnostics.ProcessThread[] arrThread=new System.Diagnostics.ProcessThread[tmpPcs.Threads.Count];
tmpPcs.Threads.CopyTo(arrThread, 0);
foreach( System.Diagnostics.ProcessThread[] thread in arrThread)
{
Threadcount++;
}
那怎么用Thread类控制指定进程的线程 挂起等操作那?
foreach(System.Diagnostics.Process tmpPcs in arrProcess)//遍历进程数组
{
int Threadcount=0;//线程数
ListViewItem ViewItem=listView.Items.Add(tmpPcs.ProcessName);
System.Diagnostics.ProcessThread[] arrThread=new System.Diagnostics.ProcessThread[tmpPcs.Threads.Count];
tmpPcs.Threads.CopyTo(arrThread, 0);
foreach( System.Diagnostics.ProcessThread[] thread in arrThread)
{
Threadcount++;
}
那怎么用Thread类控制指定进程的线程 挂起等操作那?
你怎么遍历线程啊?你怎么可能遍历出别人里面的线程那?-- 这是我的疑问
----------------------------这到提醒了我了,好像这种方式可以,lz去看看api hook方面的知识,会有启发的。我觉得你的问题通过常规的方式没法解决,只能通过windows核心编程的知识来解决了
以下是c++里面可以实现的方法:unmanaged code
1.通过EnumProcessModules来枚举出process 的handle,取得自己所要的handle
2.通过CreateToolhelp32SnapShot函数,拿到对应的pid下的snap handle
3.用Thread32First和Thread32Next这两个函数遍历
我也觉得是可行的
Dim i As Long
Dim TList() As THREADENTRY32
Dim TE32 As THREADENTRY32
Dim hThreadSnap As Long
Dim TheLoop As Long hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, ProcessID)
TE32.dwsize = Len(TE32) TheLoop = Thread32First(hThreadSnap, TE32)
While TheLoop <> 0 If TE32.th32OwnerProcessID = ProcessID Then
ReDim Preserve TList(i)
TerminateThread TE32.th32threadID, 0
TList(i) = TE32
i = i + 1
End If TheLoop = Thread32Next(hThreadSnap, TE32)
Wend CloseHandle hThreadSnap
GetThreadList = TList
End Function
Public Function KillThread(ByVal ProcessID As Long) As Boolean
Dim hThread As Long, r As Long, i As Long
Dim TList() As THREADENTRY32 TList = GetThreadList(ProcessID) For i = 0 To UBound(TList)
With TList(i)
hThread = OpenThread(PROCESS_TERMINATE, False, .th32threadID) '获取进程句柄
If hThread <> 0 Then
r = TerminateThread(hThread, 0) '关闭进程
End If
End With
Next
KillThread = r <> 0
End Function
要自己加东西... 修改...