opennetCF Process.Kill() problems

  • Thread starter Yechezkal Gutfreund
  • Start date
Y

Yechezkal Gutfreund

We are using the source classes for OpenNETCF.Diagnostics.Process (code
taken from opennetcf.org today)
to start and stop processes.

The starting works fine. But when we try to ourprocess.Kill() we get a the
Win32 exception:

System.ComponentModel.Win32Exception: The associated process could not be
terminated



Peter Foot, any ideas?




--
==================================
Yechezkal Gutfreund
Chief Scientist
Kesser Technical Group, Inc.
==================================
 
P

Paul G. Tobey [eMVP]

You don't want to kill yourself in this way, as Alex said. If you're trying
to kill a process that you started, you'll have to tell us something about
what that process is doing when you're trying to kill it.

Paul T.
 
P

Peter Foot [MVP]

The Win32Exception should contain an error code from GetLastWin32Error
called after the TerminateProcess call fails, what is this - it will help
track down the error. Also can you post a code snippet of how you are
starting and killing the process. If you step through the code in the
debugger does your Process have a valid ID and or Handle?

Peter
 
Y

Yechezkal Gutfreund

Chuckle, Chuckle,

No. We start a different process with Process.start() and hold on to the
returned "handle" till we need to do a shutdown.

The start and stop are basically:

private Process instrument_process;

string filename = "\Storage Card\kessertech\ptmw.exe";

instrument_process = Process.Start(filename);

// much later we do a

instrument_process.Kill();



Notes: The exe is a FlashProjector (and exe that shows a flash movie)

Also, Where do we get the "GetLastWin32Error" I see something called
NativeErrorCode, but not that.


--
==================================
Yechezkal Gutfreund
Chief Scientist
Kesser Technical Group, Inc.
==================================
 
P

Peter Foot [MVP]

System.Runtime.InteropServices.Marshal.GetLastWin32Error() but this is
called within the Win32Exception constructor and is exposed by the
NativeErrorCode property.

Peter
 
S

Sergey Bogdanov

P

Peter Foot [MVP]

OpenNETCF has a wrapper for the Toolhelp APIs (Though not all Windows CE
devices support Toolhelp). You can use this to enumerate all running
processes and then kill them if necessary.
OpenNETCF.Toolhelp.ProcessEntry.GetAllProcesses()

However you should really attempt to close them cleanly before you resort to
killing processes, this can be done by sending a WM_CLOSE message to the
applications main window.

Peter
 
Y

Yechezkal Gutfreund

Peter, sorry for the delay. Here is the info on the process handle after
start, right before kill, and also the full exception with the
GetLastWin32Error (Native Error = 6 ).



PROCESS object at the time the object was created (StationMasterPDA)

- newprocess {OpenNETCF.Diagnostics.Process} OpenNETCF.Diagnostics.Process

- System.ComponentModel.Component {OpenNETCF.Diagnostics.Process}

System.ComponentModel.Component

- System.MarshalByRefObject {OpenNETCF.Diagnostics.Process}

System.MarshalByRefObject

System.Object {OpenNETCF.Diagnostics.Process} System.Object

Disposed <undefined value> System.EventHandler

ExitCode <error: an exception of type: {System.InvalidOperationException}

occurred> int

Exited <undefined value> System.EventHandler

Handle 851629302 int

HasExited false bool

Id 0 int

m_exited false bool

- m_pinfo {OpenNETCF.Diagnostics.Process.ProcessInfo}

OpenNETCF.Diagnostics.Process.ProcessInfo

System.Object {OpenNETCF.Diagnostics.Process.ProcessInfo} System.Object

dwProcessID 0 int

dwThreadID 0 int

hProcess 851629302 int

hThread 0 int

- m_pstart {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

PUserKDataARM 4294952960 uint

PUserKDataX86 22528 uint

SH_CURPROC 2 int

SH_CURTHREAD 1 int

SH_WIN32 0 int

- StartInfo {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

StillActive 259 int

SYS_HANDLE_BASE 64 int

SYSHANDLE_OFFSET 4 uint



=============================================

PROCESS object just before TerminateProcess is called in Process.cs (under

StationMasterPDA)



===============================================

- this {OpenNETCF.Diagnostics.Process} OpenNETCF.Diagnostics.Process

- System.ComponentModel.Component {OpenNETCF.Diagnostics.Process}

System.ComponentModel.Component

+ System.MarshalByRefObject {OpenNETCF.Diagnostics.Process}

System.MarshalByRefObject

Disposed <undefined value> System.EventHandler

ExitCode <error: an exception of type: {System.InvalidOperationException}

occurred> int

Exited <undefined value> System.EventHandler

Handle 862175906 int

HasExited false bool

Id 0 int

m_exited false bool

- m_pinfo {OpenNETCF.Diagnostics.Process.ProcessInfo}

OpenNETCF.Diagnostics.Process.ProcessInfo

System.Object {OpenNETCF.Diagnostics.Process.ProcessInfo} System.Object

dwProcessID 0 int

dwThreadID 0 int

hProcess 862175906 int

hThread 0 int

- m_pstart {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

PUserKDataARM 4294952960 uint

PUserKDataX86 22528 uint

SH_CURPROC 2 int

SH_CURTHREAD 1 int

SH_WIN32 0 int

- StartInfo {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

StillActive 259 int

SYS_HANDLE_BASE 64 int

SYSHANDLE_OFFSET 4 uint





PROCESS Exception error

- ex {"The associated instrument process could not be terminated" }
System.Exception

- [System.ComponentModel.Win32Exception]
{System.ComponentModel.Win32Exception}

System.ComponentModel.Win32Exception

+ System.Runtime.InteropServices.ExternalException

{System.ComponentModel.Win32Exception}

System.Runtime.InteropServices.ExternalException

m_nativeErrorCode 6 int

NativeErrorCode 6 int

System.Object {System.ComponentModel.Win32Exception} System.Object

_innerException { } System.Exception

_message "The associated instrument process could not be terminated" string

InnerException { } System.Exception

Message "The associated instrument process could not be terminated" string
 
P

Peter Foot [MVP]

The error code indicates "Handle is invalid".

Can you try the following approach:-
When you launch the process set the UseShellExecute flag to false on the
ProcessStartInfo e.g.

ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false;
psi.FileName = "MyApplication.exe";
psi.Arguments = "/command line switches if required";
Process p = Process.Start(psi);

Can you see whether valid Id and Handle are contained in the process (p)
when you come to call p.Kill.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Yechezkal Gutfreund said:
Peter, sorry for the delay. Here is the info on the process handle after
start, right before kill, and also the full exception with the
GetLastWin32Error (Native Error = 6 ).



PROCESS object at the time the object was created (StationMasterPDA)

- newprocess {OpenNETCF.Diagnostics.Process} OpenNETCF.Diagnostics.Process

- System.ComponentModel.Component {OpenNETCF.Diagnostics.Process}

System.ComponentModel.Component

- System.MarshalByRefObject {OpenNETCF.Diagnostics.Process}

System.MarshalByRefObject

System.Object {OpenNETCF.Diagnostics.Process} System.Object

Disposed <undefined value> System.EventHandler

ExitCode <error: an exception of type: {System.InvalidOperationException}

occurred> int

Exited <undefined value> System.EventHandler

Handle 851629302 int

HasExited false bool

Id 0 int

m_exited false bool

- m_pinfo {OpenNETCF.Diagnostics.Process.ProcessInfo}

OpenNETCF.Diagnostics.Process.ProcessInfo

System.Object {OpenNETCF.Diagnostics.Process.ProcessInfo} System.Object

dwProcessID 0 int

dwThreadID 0 int

hProcess 851629302 int

hThread 0 int

- m_pstart {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

PUserKDataARM 4294952960 uint

PUserKDataX86 22528 uint

SH_CURPROC 2 int

SH_CURTHREAD 1 int

SH_WIN32 0 int

- StartInfo {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

StillActive 259 int

SYS_HANDLE_BASE 64 int

SYSHANDLE_OFFSET 4 uint



=============================================

PROCESS object just before TerminateProcess is called in Process.cs (under

StationMasterPDA)



===============================================

- this {OpenNETCF.Diagnostics.Process} OpenNETCF.Diagnostics.Process

- System.ComponentModel.Component {OpenNETCF.Diagnostics.Process}

System.ComponentModel.Component

+ System.MarshalByRefObject {OpenNETCF.Diagnostics.Process}

System.MarshalByRefObject

Disposed <undefined value> System.EventHandler

ExitCode <error: an exception of type: {System.InvalidOperationException}

occurred> int

Exited <undefined value> System.EventHandler

Handle 862175906 int

HasExited false bool

Id 0 int

m_exited false bool

- m_pinfo {OpenNETCF.Diagnostics.Process.ProcessInfo}

OpenNETCF.Diagnostics.Process.ProcessInfo

System.Object {OpenNETCF.Diagnostics.Process.ProcessInfo} System.Object

dwProcessID 0 int

dwThreadID 0 int

hProcess 862175906 int

hThread 0 int

- m_pstart {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

PUserKDataARM 4294952960 uint

PUserKDataX86 22528 uint

SH_CURPROC 2 int

SH_CURTHREAD 1 int

SH_WIN32 0 int

- StartInfo {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

StillActive 259 int

SYS_HANDLE_BASE 64 int

SYSHANDLE_OFFSET 4 uint





PROCESS Exception error

- ex {"The associated instrument process could not be terminated" }
System.Exception

- [System.ComponentModel.Win32Exception]
{System.ComponentModel.Win32Exception}

System.ComponentModel.Win32Exception

+ System.Runtime.InteropServices.ExternalException

{System.ComponentModel.Win32Exception}

System.Runtime.InteropServices.ExternalException

m_nativeErrorCode 6 int

NativeErrorCode 6 int

System.Object {System.ComponentModel.Win32Exception} System.Object

_innerException { } System.Exception

_message "The associated instrument process could not be terminated"
string

InnerException { } System.Exception

Message "The associated instrument process could not be terminated" string
 
Y

Yechezkal Gutfreund

This variant on process.kill() is working. We are now able to kill the flash
program.

Thank you very much Peter. This will be a key element in our architecture,
and we really needed
this sort of process control. Thank you for writing it.





Peter Foot said:
The error code indicates "Handle is invalid".

Can you try the following approach:-
When you launch the process set the UseShellExecute flag to false on the
ProcessStartInfo e.g.

ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false;
psi.FileName = "MyApplication.exe";
psi.Arguments = "/command line switches if required";
Process p = Process.Start(psi);

Can you see whether valid Id and Handle are contained in the process (p)
when you come to call p.Kill.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Yechezkal Gutfreund said:
Peter, sorry for the delay. Here is the info on the process handle after
start, right before kill, and also the full exception with the
GetLastWin32Error (Native Error = 6 ).



PROCESS object at the time the object was created (StationMasterPDA)

- newprocess {OpenNETCF.Diagnostics.Process}
OpenNETCF.Diagnostics.Process

- System.ComponentModel.Component {OpenNETCF.Diagnostics.Process}

System.ComponentModel.Component

- System.MarshalByRefObject {OpenNETCF.Diagnostics.Process}

System.MarshalByRefObject

System.Object {OpenNETCF.Diagnostics.Process} System.Object

Disposed <undefined value> System.EventHandler

ExitCode <error: an exception of type: {System.InvalidOperationException}

occurred> int

Exited <undefined value> System.EventHandler

Handle 851629302 int

HasExited false bool

Id 0 int

m_exited false bool

- m_pinfo {OpenNETCF.Diagnostics.Process.ProcessInfo}

OpenNETCF.Diagnostics.Process.ProcessInfo

System.Object {OpenNETCF.Diagnostics.Process.ProcessInfo} System.Object

dwProcessID 0 int

dwThreadID 0 int

hProcess 851629302 int

hThread 0 int

- m_pstart {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

PUserKDataARM 4294952960 uint

PUserKDataX86 22528 uint

SH_CURPROC 2 int

SH_CURTHREAD 1 int

SH_WIN32 0 int

- StartInfo {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

StillActive 259 int

SYS_HANDLE_BASE 64 int

SYSHANDLE_OFFSET 4 uint



=============================================

PROCESS object just before TerminateProcess is called in Process.cs
(under

StationMasterPDA)



===============================================

- this {OpenNETCF.Diagnostics.Process} OpenNETCF.Diagnostics.Process

- System.ComponentModel.Component {OpenNETCF.Diagnostics.Process}

System.ComponentModel.Component

+ System.MarshalByRefObject {OpenNETCF.Diagnostics.Process}

System.MarshalByRefObject

Disposed <undefined value> System.EventHandler

ExitCode <error: an exception of type: {System.InvalidOperationException}

occurred> int

Exited <undefined value> System.EventHandler

Handle 862175906 int

HasExited false bool

Id 0 int

m_exited false bool

- m_pinfo {OpenNETCF.Diagnostics.Process.ProcessInfo}

OpenNETCF.Diagnostics.Process.ProcessInfo

System.Object {OpenNETCF.Diagnostics.Process.ProcessInfo} System.Object

dwProcessID 0 int

dwThreadID 0 int

hProcess 862175906 int

hThread 0 int

- m_pstart {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

PUserKDataARM 4294952960 uint

PUserKDataX86 22528 uint

SH_CURPROC 2 int

SH_CURTHREAD 1 int

SH_WIN32 0 int

- StartInfo {OpenNETCF.Diagnostics.ProcessStartInfo}

OpenNETCF.Diagnostics.ProcessStartInfo

System.Object {OpenNETCF.Diagnostics.ProcessStartInfo} System.Object

Arguments null string

FileName @"\Storage Card\FlashWarrior\PTMW.exe" string

m_arguments null string

m_filename @"\Storage Card\FlashWarrior\PTMW.exe" string

m_shellexecute true bool

m_verb null string

UseShellExecute true bool

Verb null string

StillActive 259 int

SYS_HANDLE_BASE 64 int

SYSHANDLE_OFFSET 4 uint





PROCESS Exception error

- ex {"The associated instrument process could not be terminated" }
System.Exception

- [System.ComponentModel.Win32Exception]
{System.ComponentModel.Win32Exception}

System.ComponentModel.Win32Exception

+ System.Runtime.InteropServices.ExternalException

{System.ComponentModel.Win32Exception}

System.Runtime.InteropServices.ExternalException

m_nativeErrorCode 6 int

NativeErrorCode 6 int

System.Object {System.ComponentModel.Win32Exception} System.Object

_innerException { } System.Exception

_message "The associated instrument process could not be terminated"
string

InnerException { } System.Exception

Message "The associated instrument process could not be terminated"
string
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top