程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> win7-Win7下如何屏蔽ctrl+alt+del鍵?

win7-Win7下如何屏蔽ctrl+alt+del鍵?

編輯:編程綜合問答
Win7下如何屏蔽ctrl+alt+del鍵?

hook什麼的已經失效了,而且將winlogon.exe掛起的方法有問題(掛起中按下ctrl+alt+del,再恢復時彈出了界面),請問還有別的方法沒?不要匯編的,只要vc的

最佳回答:


win7下,登錄頁面是無法通過hook屏蔽的,因為系統登錄頁面會優先獲取到組合鍵。我之前用過一個方法可以屏蔽ALT+CTRL+DEL,就是注入方式鎖定登錄頁面管理進程**winlogon**,但是如果按了組合鍵只是暫時不觸發,鎖定解除後,還會繼續觸發。在某些情況下,還會造成卡登陸頁面。所以我建議你通過注入方式鎖定explorer進程,會好一點。進程鎖定代碼如下

 public static class ProcessFrozenController
    {
        private const int THREADACCESS_SUSPEND_RESUME = 0x0002;

        [DllImport("kernel32.dll", SetLastError = true)]
        private static extern IntPtr OpenThread(uint dwDesiredAccess, bool bInheritHandle, uint threadId);

        [DllImport("kernel32.dll", SetLastError = true)]
        private static extern int SuspendThread(IntPtr hThread);

        [DllImport("kernel32.dll", SetLastError = true)]
        private static extern int ResumeThread(IntPtr hThread);

        [DllImport("kernel32.dll")]
        private static extern uint GetLastError();

        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        private static extern bool CloseHandle(IntPtr hobject);

        public static bool FreezeProcess(string processName, ref string msg)
        {
            Process[] processArray = Process.GetProcesses();
            Process operateProcess = null;

            foreach (Process p in processArray)
            {
                if (p.ProcessName.ToLower().Trim() != processName) continue;

                operateProcess = p;
                break;
            }

            if (operateProcess == null)
            {
                msg = "未找到進程";
                return false;
            }

            List<ProcessThread> handledList = new List<ProcessThread>();
            foreach (ProcessThread pthd in operateProcess.Threads)
            {
                if (SuspendProcessThread(pthd))
                {
                    handledList.Add(pthd);
                    continue;
                }

                foreach (ProcessThread hpthd in handledList)
                {
                    ResumeProcessThread(hpthd);
                }

                msg = "凍結進程失敗";
                return false;
            }
            operateProcess.Dispose();

            return true;
        }

        public static void UnfreezeProcess(string processName)
        {
            Process[] processArray = Process.GetProcesses();
            Process operateProcess = null;

            foreach (Process p in processArray)
            {
                if (p.ProcessName.ToLower().Trim() != processName) continue;

                operateProcess = p;
                break;
            }

            if (operateProcess == null)
            {
                return;
            }

            foreach (ProcessThread thd in operateProcess.Threads)
            {
                ResumeProcessThread(thd);
            }
            operateProcess.Dispose();
        }

        #region 私有函數

        private static bool SuspendProcessThread(ProcessThread thread)
        {
            IntPtr threadHandle = OpenThread(THREADACCESS_SUSPEND_RESUME, false, (uint)thread.Id); // Open thread with required permissions
            if (threadHandle == IntPtr.Zero) // If thread pointer is zero, means that the 'OpenThread' function has failed
            {
                return false;
            }
            if (SuspendThread(threadHandle) == -1) // If the result is -1, the funtion has failed
            {
                CloseHandle(threadHandle);
                return false;
            }
            CloseHandle(threadHandle);
            return true;
        }

        private static bool ResumeProcessThread(ProcessThread thread)
        {
            IntPtr threadHandle = OpenThread(THREADACCESS_SUSPEND_RESUME, false, (uint)thread.Id); // Open thread with required permissions
            if (threadHandle == IntPtr.Zero) // If thread pointer is zero, means that the 'OpenThread' function has failed
            {
                return false;
            }
            if (ResumeThread(threadHandle) == -1) // If the result is -1, the funtion has failed
            {
                CloseHandle(threadHandle);
                return false;
            }
            CloseHandle(threadHandle); // Don't forget close thread handle
            return true;
        }

        #endregion
    }

yangbo50304
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved