Link to home
Start Free TrialLog in
Avatar of deepkash
deepkash

asked on

Get ProcessID of Excel App

We are opening an excel application in our C# application and after the completion of the task, the QUIT mentod is closing the excel workbook, but dosent terminate the excel application. Hence I thought we can use

myprocess = Process.GetProcessById(processid);
myprocess.Kill();

to achieve this, we need to get the processid of the excel applcation whcih we create.
Hence, when we open an excel applcation, is there a way to capture the process id of the opened excel application.

Thanks in advance




Avatar of Michel Sakr
Michel Sakr
Flag of Canada image

Process.ID




Process Class  [Visual Basic]See Also
Process Members | System.Diagnostics Namespace | Start | ProcessStartInfo | CloseMainWindow | Kill | ProcessThread
Requirements
Namespace: System.Diagnostics

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family

Assembly: System (in System.dll)
Language
C#

C++

JScript

Visual Basic

Show All
Provides access to local and remote processes and enables you to start and stop local system processes.

For a list of all members of this type, see Process Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Diagnostics.Process

[Visual Basic]
Public Class Process
   Inherits Component
[C#]
public class Process : Component
[C++]
public __gc class Process : public Component
[JScript]
public class Process extends Component
Thread Safety
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

Remarks
A Process component provides access to a process that is running on a computer. A process, in the simplest terms, is a running application. A thread is the basic unit to which the operating system allocates processor time. A thread can execute any part of the code of the process, including parts currently being executed by another thread.

The Process component is a useful tool for starting, stopping, controlling, and monitoring applications. Using the Process component, you can obtain a list of the processes that are running or start a new process. A Process component is used to access system processes. After a Process component has been initialized, it can be used to obtain information about the running process. Such information includes the set of threads, the loaded modules (.dll and .exe files), and performance information such as the amount of memory the process is using.

The process component obtains information about a group of properties all at once. After the Process component has obtained information about one member of any group, it will cache the values for the other properties in that group and not obtain new information about the other members of the group until you call the Refresh method. Therefore, a property value is not guaranteed to be any newer than the last call to the Refresh method. The group breakdowns are operating-system dependent.

A system process is uniquely identified on the system by its process identifier. Like many Windows resources, a process is also identified by its handle, which might not be unique on the computer. A handle is the generic term for an identifier of a resource. The operating system persists the process handle, which is accessed through the Handle property of the Process component, even when the process has exited. Thus, you can get the process's administrative information, such as the ExitCode (usually either zero for success or a nonzero error code) and the ExitTime. Handles are an extremely valuable resource, so leaking handles is more virulent than leaking memory.

Requirements
Namespace: System.Diagnostics
ASKER CERTIFIED SOLUTION
Avatar of Michel Sakr
Michel Sakr
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial