PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Identifying a process so that it can be killed

Reply

Identifying a process so that it can be killed

 
Thread Tools Rate Thread
Old 07-03-2006, 01:31 AM   #1
=?Utf-8?B?Qk9QTUtS?=
Guest
 
Posts: n/a
Default Identifying a process so that it can be killed


The following vb code will identify that mstsc.exe is actually running, but I
can't find a way to kill it. I've searched google groups etc. but no luck so
far. It does seem though, that a lot of people are lookig for an answer to
this.
--------------------------------------------------------
Imports OpenNETCF.ToolHelp

Dim pe()
Dim p As Process

pe = ProcessEntry.GetProcesses()

For i = 0 To UBound(pe)

If pe(i).ToString = "mstsc40.exe" Then '... this works

p = Process.GetProcessById(i) ' .... this doesn't work
p.Kill() ' ..................................... so nor
does this

End If
Next i
--------------------------------------------------------
Of course (i) is not the real process ID, the question is how do I find the
real process ID for the instance of mstsc40.exe??

Thanks in advance

  Reply With Quote
Old 07-03-2006, 09:28 AM   #2
Sergey Bogdanov
Guest
 
Posts: n/a
Default Re: Identifying a process so that it can be killed

What about pe(i).ProcessID to get ProcessID and in your case it should
something like this:

For i = 0 To UBound(pe)
If pe(i).ToString = "mstsc40.exe" Then
pe(i).Kill()
End If
Next i


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com


BOPMKR wrote:
> The following vb code will identify that mstsc.exe is actually running, but I
> can't find a way to kill it. I've searched google groups etc. but no luck so
> far. It does seem though, that a lot of people are lookig for an answer to
> this.
> --------------------------------------------------------
> Imports OpenNETCF.ToolHelp
>
> Dim pe()
> Dim p As Process
>
> pe = ProcessEntry.GetProcesses()
>
> For i = 0 To UBound(pe)
>
> If pe(i).ToString = "mstsc40.exe" Then '... this works
>
> p = Process.GetProcessById(i) ' .... this doesn't work
> p.Kill() ' ..................................... so nor
> does this
>
> End If
> Next i
> --------------------------------------------------------
> Of course (i) is not the real process ID, the question is how do I find the
> real process ID for the instance of mstsc40.exe??
>
> Thanks in advance
>

  Reply With Quote
Old 07-03-2006, 03:14 PM   #3
Paul G. Tobey [eMVP]
Guest
 
Posts: n/a
Default Re: Identifying a process so that it can be killed

But you really should try closing it in a more-friendly manner than just
terminating it. Try sending WM_CLOSE to its main window, for example, and
maybe trying to send WM_QUIT to its main thread. If that doesn't work in a
few seconds, you can kill the process on the assumption that it's locked up.

Paul T.

"Sergey Bogdanov" <sergey.bogdanov@gmail.com> wrote in message
news:ebzCEmcQGHA.3804@TK2MSFTNGP15.phx.gbl...
> What about pe(i).ProcessID to get ProcessID and in your case it should
> something like this:
>
> For i = 0 To UBound(pe)
> If pe(i).ToString = "mstsc40.exe" Then
> pe(i).Kill()
> End If
> Next i
>
>
> --
> Sergey Bogdanov [.NET CF MVP, MCSD]
> http://www.sergeybogdanov.com
>
>
> BOPMKR wrote:
>> The following vb code will identify that mstsc.exe is actually running,
>> but I can't find a way to kill it. I've searched google groups etc. but
>> no luck so far. It does seem though, that a lot of people are lookig for
>> an answer to this.
>> --------------------------------------------------------
>> Imports OpenNETCF.ToolHelp
>>
>> Dim pe()
>> Dim p As Process
>>
>> pe = ProcessEntry.GetProcesses()
>> For i = 0 To UBound(pe)
>>
>> If pe(i).ToString = "mstsc40.exe" Then '... this works
>>
>> p = Process.GetProcessById(i) ' .... this doesn't work
>> p.Kill() ' ..................................... so
>> nor does this
>>
>> End If
>> Next i
>> --------------------------------------------------------
>> Of course (i) is not the real process ID, the question is how do I find
>> the real process ID for the instance of mstsc40.exe??
>>
>> Thanks in advance
>>



  Reply With Quote
Old 07-03-2006, 07:11 PM   #4
=?Utf-8?B?Qk9QTUtS?=
Guest
 
Posts: n/a
Default Re: Identifying a process so that it can be killed

Thanks
This failed with a no late binding error until I changed the
pe() definition from:

Dim pe()

to

Dim pe() As ProcessEntry

"Sergey Bogdanov" wrote:

> What about pe(i).ProcessID to get ProcessID and in your case it should
> something like this:
>
> For i = 0 To UBound(pe)
> If pe(i).ToString = "mstsc40.exe" Then
> pe(i).Kill()
> End If
> Next i
>
>
> --
> Sergey Bogdanov [.NET CF MVP, MCSD]
> http://www.sergeybogdanov.com
>
>
> BOPMKR wrote:
> > The following vb code will identify that mstsc.exe is actually running, but I
> > can't find a way to kill it. I've searched google groups etc. but no luck so
> > far. It does seem though, that a lot of people are lookig for an answer to
> > this.
> > --------------------------------------------------------
> > Imports OpenNETCF.ToolHelp
> >
> > Dim pe()
> > Dim p As Process
> >
> > pe = ProcessEntry.GetProcesses()
> >
> > For i = 0 To UBound(pe)
> >
> > If pe(i).ToString = "mstsc40.exe" Then '... this works
> >
> > p = Process.GetProcessById(i) ' .... this doesn't work
> > p.Kill() ' ..................................... so nor
> > does this
> >
> > End If
> > Next i
> > --------------------------------------------------------
> > Of course (i) is not the real process ID, the question is how do I find the
> > real process ID for the instance of mstsc40.exe??
> >
> > Thanks in advance
> >

>

  Reply With Quote
Old 07-03-2006, 07:11 PM   #5
=?Utf-8?B?Qk9QTUtS?=
Guest
 
Posts: n/a
Default Re: Identifying a process so that it can be killed

Thanks Paul I will look into this as well.

"Paul G. Tobey [eMVP]" wrote:

> But you really should try closing it in a more-friendly manner than just
> terminating it. Try sending WM_CLOSE to its main window, for example, and
> maybe trying to send WM_QUIT to its main thread. If that doesn't work in a
> few seconds, you can kill the process on the assumption that it's locked up.
>
> Paul T.
>
> "Sergey Bogdanov" <sergey.bogdanov@gmail.com> wrote in message
> news:ebzCEmcQGHA.3804@TK2MSFTNGP15.phx.gbl...
> > What about pe(i).ProcessID to get ProcessID and in your case it should
> > something like this:
> >
> > For i = 0 To UBound(pe)
> > If pe(i).ToString = "mstsc40.exe" Then
> > pe(i).Kill()
> > End If
> > Next i
> >
> >
> > --
> > Sergey Bogdanov [.NET CF MVP, MCSD]
> > http://www.sergeybogdanov.com
> >
> >
> > BOPMKR wrote:
> >> The following vb code will identify that mstsc.exe is actually running,
> >> but I can't find a way to kill it. I've searched google groups etc. but
> >> no luck so far. It does seem though, that a lot of people are lookig for
> >> an answer to this.
> >> --------------------------------------------------------
> >> Imports OpenNETCF.ToolHelp
> >>
> >> Dim pe()
> >> Dim p As Process
> >>
> >> pe = ProcessEntry.GetProcesses()
> >> For i = 0 To UBound(pe)
> >>
> >> If pe(i).ToString = "mstsc40.exe" Then '... this works
> >>
> >> p = Process.GetProcessById(i) ' .... this doesn't work
> >> p.Kill() ' ..................................... so
> >> nor does this
> >>
> >> End If
> >> Next i
> >> --------------------------------------------------------
> >> Of course (i) is not the real process ID, the question is how do I find
> >> the real process ID for the instance of mstsc40.exe??
> >>
> >> Thanks in advance
> >>

>
>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off