-1
要检查一个进程挂起Word,通过VB.Net 2003项目,我创建一个线程,使进程控制(有问题)。如果在一定数量的毫秒后该进程仍然处于活动状态,那么我会从线程中终止该进程。该系统告诉我: “System.ComponentModel.Win32Exception”, '拒绝访问'杀死进程winword
的代码如下:
这是代码VB:
Imports System
Imports System.Threading
Imports System.Threading.Thread
Imports System.Security.Permissions
Public Class ThreadMain
Public strdotName AsString
Public strdocName AsString
Public sXML AsString
Public idProcesso AsInteger
Public terminate AsInteger
Public docName AsString
Public kk AsInteger
Public finito AsBoolean= False
Public Function LaunchThread() AsInteger
Dim myT2 As Threading.Thread
myT2 = New Threading.Thread(AddressOfMe.DoWork)
myT2.IsBackground = True
myT2.Start()
Try
Console.WriteLine("Finito: {0}", finito)
Catch Ex As Exception
End Try
Return terminate
End Function
*-------**
Private Sub DoWork()
Dim j AsInteger
Dim errore AsString
Dim trovato AsBoolean
Dim colProcess AsProcess
Dim nomeProcess AsProcess()
Dim chiusura AsBoolean
Try
For j = 100 To 20000
colProcess = Process.GetProcessById(idProcesso)
If Not colProcess IsNothingThen
j = j + 1000
System.Threading.Thread.Sleep(1)
trovato = True
Else
trovato = False
End If
Next
If trovato Then
chiusura = colProcess.CloseMainWindow()
colProcess.Close()
Process.GetProcessById(idProcesso).Kill()
terminate = 1
End If
Catch ex As Exception
errore = ex.ToString
terminate = 2
End Try
End Sub 'DoWork
您是否拥有管理员权限?你试图在远程机器上杀死的进程是什么? – Tudor