A forum for reverse engineering, OS internals and malware analysis 

Forum for discussion about kernel-mode development.
 #17382  by myid
 Wed Dec 26, 2012 10:30 pm
Close file handle in a general process is easy, use KeStackAttachProcess and ZwClose is feasible.
But how to close handle in SYSTEM process(PID=4)? Method on above is not useful. If direct use NtClose(in a kernel thread) is not useful, too.
Both ZwClose and NtClose return 0xC0000008(STATUS_INVALID_HANDLE).
Tested platform: WIN7 X64 and WIN8 X64.
Last edited by myid on Wed Dec 26, 2012 10:59 pm, edited 3 times in total.
 #17384  by myid
 Wed Dec 26, 2012 10:52 pm
Buster_BSA wrote:I did not find any program able to close handles opened by SYSTEM process.

If anyone knows a method, I will be interested to hear of it too.
A software called 360SAFE can unlock/delete file opened by SYSTEM process.
But it is a Chinese software and have no English version.
 #17388  by myid
 Thu Dec 27, 2012 3:42 am
kmd wrote:dont know how you tried. Process Explorer can close handle in System.
You are wrong. ProcExp cannot close handle in SYSTEM process on WIN7 X64, too.
If you don't believe me, I can show you the screenshot.
 #17391  by Buster_BSA
 Thu Dec 27, 2012 8:23 am
In my experience is not possible to close handles opened by SYSTEM process.

Sometimes Sandboxie´s RegHive can not be deleted. When you check who has the handle opened is SYSTEM (PID 4), and none program, Unlocker and Process Explorer included, can close the handle. The only way is rebooting.

I have confirmed this behavior consistently.