Asked by:
kill process

Question
-
User1330432403 posted
Hello everyone, my name is nicola and is the first time I write in the Forum. I have a problem like this:
To check if a process hangs Word, through a VB.Net 2003 project, I create a thread that makes process control (in question). If after a certain number of milliseconds that the process is still active, I kill the process from the thread. The system tells me "System.ComponentModel.Win32Exception", 'Access Denied'
The code is as follows:ImportsSystem
ImportsSystem.Threading
ImportsSystem.Threading.Thread
ImportsSystem.Security.Permissions
PublicClassThreadMain
PublicstrdotName AsString
PublicstrdocName AsString
PublicsXML AsString
PublicidProcesso AsInteger
Publicterminate AsInteger
PublicdocName AsString
Publickk AsInteger
Publicfinito AsBoolean= False
PublicFunctionLaunchThread() AsInteger
DimmyT2 AsThreading.Thread
myT2 = NewThreading.Thread(AddressOfMe.DoWork)
myT2.IsBackground = True
myT2.Start()
Try
Console.WriteLine("Finito: {0}", finito)
CatchEx AsException
EndTry
Returnterminate
EndFunction
<SecurityPermissionAttribute(SecurityAction.Deny, Flags:=SecurityPermissionFlag.NoFlags)> _
PrivateSubDoWork()
Dimj AsInteger
Dimerrore AsString
Dimtrovato AsBoolean
DimcolProcess AsProcess
DimnomeProcess AsProcess()
Dimchiusura AsBoolean
Try
Forj = 100 To20000
colProcess = Process.GetProcessById(idProcesso)
IfNotcolProcess IsNothingThen
j = j + 1000
System.Threading.Thread.Sleep(1)
trovato = True
Else
trovato = False
EndIf
Next
Iftrovato Then
chiusura = colProcess.CloseMainWindow()
colProcess.Close()
Process.GetProcessById(idProcesso).Kill()
terminate = 1
EndIf
Catchex AsException
errore = ex.ToString
terminate = 2
EndTry
EndSub'DoWork
Can you help me, thanks
Tuesday, July 3, 2012 4:30 AM
All replies
-
User-661350001 posted
to kill a process from another process, killer process should have access
Tuesday, July 3, 2012 4:47 AM -
User1330432403 posted
Thanks Khan, in IIS I set as a security acess Anonimus as administrator and do not let me kill the Word process in a thread. What's wrong in the code attached?
Tuesday, July 3, 2012 5:26 AM -
User1048621291 posted
Hi,
Please right click your Visual studio, choose "Run as administrator" and test again.
Wednesday, July 4, 2012 11:05 PM -
User1330432403 posted
Zhang Hello, thanks for the suggestion but I open Visual Studio as an administrator and does not kill
Thursday, July 5, 2012 3:17 AM