When operating Excel, you can see that one way is to kill all the "Excel" processes. In this way, if a document is opened, it will be closed without prompting whether to save it. the user will go crazy, the following method can only kill the current process
Microsoft. Office. InterOP. Excel. Application m_xlapp = New Microsoft. Office. InterOP. Excel. Application ();
Int M_k = M_xlapp.hwnd;
//Operation
Killprocess (m_k );//Close Process
// Closing Method
[Dllimport ( " User32.dll " , Charset = Charset. Auto)]
Public Static Extern Int Getwindowthreadprocessid (intptr hwnd, Out Int ID );
/// <Summary>
/// Kill Process
/// </Summary>
/// <Param name = "ID"> </param>
Private Static Void Killprocess ( Int ID)
{
Intptr t = New Intptr (ID );
Int K = 0 ;
Getwindowthreadprocessid (t, Out K ); // Obtain the unique identifier K of the process.
If (K ! = 0 )
{
System. Diagnostics. PROCESS p = System. Diagnostics. process. getprocpolicyid (k ); // Get reference to process K
P. Kill (); // Disable process K
}
}
In this way, it can be operated, and it is even more useful in loop operations. In the past, when I export Sina Blog to word, I killed all input methods. The method is easy to use, but it is not reasonable, it feels good to use the above example.