The Windows API includes a useful function called DuplicateHandle
, which can be used to transfer HANDLEs (to files, registry keys, processes, mutexes, etc.) from one process to another. This is useful for a number of things, including when writing sandboxes where sometimes a broker process will open a HANDLE (that the sandboxed process can't access) and then pass that HANDLE down to the sandbox. This is similar to passing file descriptors between POSIX processes via Unix domain sockets.
Unfortunately, the documentation for DuplicateHandle
doesn't mention service handles (type SC_HANDLE
, used/returned by APIs like OpenSCManager
) as a supported HANDLE type. Is there a way to duplicate (or otherwise transfer) those between processes?
These handles cannot be duplicated. The other process would need to call OpenSCManager
.