每当我关闭我的应用程序时,我会尝试自己BSOD(强制蓝屏死机).不幸的是,当我打电话Process.EnterDebugMode();,我得到一个异常:Not all privileges or groups referenced are assigned to the caller.
我写了一个键盘记录器(那个部分已经完成),它想要监视修理我的笔记本电脑的维修人员,以便我知道他是否做了任何有趣的事情.
[DllImport("ntdll.dll", SetLastError = true)]
private static extern int NtSetInformationProcess(IntPtr hProcess, int processInformationClass, ref int processInformation, int processInformationLength);
public static void Main() {
int isCritical = 1; // we want this to be a Critical Process
int BreakOnTermination = 0x1D; // value for BreakOnTermination (flag)
Process.EnterDebugMode(); //acquire Debug Privileges
// setting the BreakOnTermination = 1 for the current process
NtSetInformationProcess(Process.GetCurrentProcess().Handle, BreakOnTermination, ref isCritical, sizeof(int));
Run Code Online (Sandbox Code Playgroud)
您的程序需要以管理员权限运行.如果您这样做,您的程序将按预期运行.
您可以使用app.manifest轻松获得app.manfest的程序请求权限 - 右键单击VS中的项目并添加应用程序清单文件.生成的注释中有说明,但您需要替换
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
Run Code Online (Sandbox Code Playgroud)
同
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Run Code Online (Sandbox Code Playgroud)