WIN7 Keyboard hook stops working in another user account?

点点圈 提交于 2019-12-01 14:44:17

As long as the kids aren't administrators, you can run the program under their accounts and deny access to the process.

For example (tested):

static void SetAcl() {
    var sd = new RawSecurityDescriptor(ControlFlags.None,
        new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null),
        null, null, new RawAcl(2, 0));

    sd.SetFlags(ControlFlags.DiscretionaryAclPresent | ControlFlags.DiscretionaryAclDefaulted);
    var rawSd = new byte[sd.BinaryLength];

    sd.GetBinaryForm(rawSd, 0);
    if (!NativeMethods.SetKernelObjectSecurity(Process.GetCurrentProcess().Handle, SecurityInfos.DiscretionaryAcl, rawSd))
        throw new Win32Exception();
}

static class NativeMethods {
    [DllImport("Advapi32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool SetKernelObjectSecurity(IntPtr target, SecurityInfos info, byte[] descriptor);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!