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