> ## Documentation Index
> Fetch the complete documentation index at: https://ahmed-walid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting client's process handle from a COM/WinRT Server

> Useful for verifying caller client identity

This might be the shortest article ever written, so basically there's a private built-in Call Context interface that allows you to get a handle to client's process.

This can be useful for various of things, for example verifying the caller client identity from your server without having a custom interface for that which can actually be exploited.

So let's start!

Here's the interface definition:

```cpp lines theme={null}
MIDL_INTERFACE("68C6A1B9-DE39-42C3-8D28-BF40A5126541")
ICallingProcessInfo : public IUnknown
{
public:
    virtual STDMETHOD(OpenCallerProcessHandle)(DWORD dwDesiredAccess, HANDLE* handle) = 0;
};
```

And here's the usage:

```cpp lines theme={null}
// ComPtr is from WRL, you can use the interface directly instead
ComPtr<ICallingProcessInfo> callingProcessInfo;
CoGetCallContext(__uuidof(ICallingProcessInfo), (void**)callingProcessInfo.GetAddressOf());

HANDLE handle;
callingProcessInfo->OpenCallerProcessHandle(PROCESS_QUERY_LIMITED_INFORMATION, &handle);
```

You can use that handle to get the PID, for example, by using the [GetProcessId](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getprocessid) function.

And that's it, bye!
