C# 掛起 進程 PostMessage使用


        #region  暫停進程

        //檢測進程是否存在


        public List<IntPtr> get_pressId(string pressName = "explorer")
        {
            List<IntPtr> list = new List<IntPtr>();

            //獲得進程ID
            Process[] processes = Process.GetProcesses();
            foreach (Process process in processes)
            {
                if (process.ProcessName == pressName)
                {
                    list.Add(process.Handle);
                }
            }

            return list;
            ////掛起進程
            //NtSuspendProcess(ip);
            ////恢復
            //NtResumeProcess(ip);
        }

        [DllImport("ntdll.dll")]
        private static extern uint NtSuspendProcess([In] IntPtr processHandle);

        [DllImport("ntdll.dll")]
        private static extern uint NtResumeProcess([In] IntPtr processHandle);


        #endregion




  /// <summary>
        /// js c#回調類
        /// </summary>
        public class ScriptCallbackManager
        {
            //轉自:https://www.cnblogs.com/sntetwt/p/9269691.html

            private const Int32 WM_SYSCOMMAND = 274;
            private const UInt32 SC_CLOSE = 61536;
            [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            private static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
            [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            private static extern bool PostMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
            [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
            [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            private static extern int RegisterWindowMessage(string lpString);



            public void FindComputerInfo(IJavascriptCallback javascriptCallback)
            {
                Task.Factory.StartNew(async () =>
                {
                    using (javascriptCallback)
                    {
                        await javascriptCallback.ExecuteAsync("00");
                    }
                });
            }

            //顯示屏幕鍵盤
            public int ShowInputPanel()
            {
                try
                {
                    Process.Start("key.exe", "osk");

                    return 1;
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);

                    return 255;
                }
            }
            ////隱藏屏幕鍵盤
            public void HideInputPanel()
            {
                IntPtr TouchhWnd = new IntPtr(0);
                TouchhWnd = FindWindow("IPTip_Main_Window", null);
                if (TouchhWnd == IntPtr.Zero)
                    return;
                PostMessage(TouchhWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
            }
            //結束進程
            public void kill_key()
            {
                Form1 form = new Form1();
                var list2 = form.get_pressId("osk");


            }



        }
 
         
         
        

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM