how can i make a Critical System Process so that it can't be ended开发者_开发知识库 from task manager in C#?
In general, it is not possible to do so because it would take away control from the user. Windows even allows you to kill highly critical processes such as csrss.exe (don't try killing it, please, instant BSOD is guaranteed).
The very good reasons why this is so have been very well explained by Raymond Chen:
The arms race between programs and users
If you don't want users to kill your process make it a service and take away administrator privileges from your users.
may be a little late but this is the code I use
[DllImport("ntdll.dll", SetLastError = true)]
private static extern void RtlSetProcessIsCritical(UInt32 v1, UInt32 v2, UInt32 v3);
[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool SetKernelObjectSecurity(
IntPtr handle,
int securityInformation,
[In] byte[] securityDescriptor
);
calling the function on C#
RtlSetProcessIsCritical(1, 0, 0);
just note that
- you need administrator for this
- causes BSOD whenever you close the process
to go back to normal just do
RtlSetProcessIsCritical(0, 0, 0);
精彩评论