c# wince重啟代碼

來源:互聯網
上載者:User

標籤:

using System;using System.Collections;using System.Collections.Generic;using System.Data;using System.Diagnostics;using System.Runtime.InteropServices;namespace restart{    class Class1    {        [DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true)]        private static extern int KernelIoControl(int dwIoControlCode, IntPtr lpInBuf, int nInBufSize, IntPtr lpOutBuf, int nOutBufSize, int lpBytesReturned);        [DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true)]        private static extern void SetCleanRebootFlag();        [DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true)]        private static extern void keybd_event(byte bVk, byte bScan, long dwFlags, long dwExtraInfo);        //As Byte        private const int KEYEVENTF_KEYUP = 2;        private const int FILE_DEVICE_HAL = 0x101;        private const int FILE_DEVICE_CONSOLE = 0x102;        private const int FILE_DEVICE_PSL = 0x103;        private const int METHOD_BUFFERED = 0;        private const int METHOD_IN_DIRECT = 1;        private const int METHOD_OUT_DIRECT = 2;        private const int METHOD_NEITHER = 3;        private const int FILE_ANY_ACCESS = 0;        private const int FILE_READ_ACCESS = 0x1;        private const int FILE_WRITE_ACCESS = 0x2;        private static int CTL_CODE(int DeviceType, int func, int Method, int Access)        {            return (DeviceType << 16) | (Access << 14) | (func << 2) | Method;        }        //CTL_CODE        public static void WarmBoot()        {            int bytesReturned = 0;            int IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS);            KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, bytesReturned);        }        public static void ColdBoot()        {            int bytesReturned = 0;            int IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS);            SetCleanRebootFlag();            //JJJ            KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, bytesReturned);        }        //TestProc        public static void HardReset()        {            int IOCTL_HAL_REBOOT = 0x101003c;            int bytesReturned = 0;            SetCleanRebootFlag();            //  KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, bytesReturned) ‘一般            //  KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 4, IntPtr.Zero, 1024, bytesReturned)      ‘ 暖開機            KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 4, IntPtr.Zero, 1024, bytesReturned);            // 冷啟動        }        //HardReset        public static void hardHibernate()        {            int IOCTL_HAL_SHUTDOWN = 0x1012000;            //休眠            int bytesReturned = 0;            byte VK_OFF = 0xdf;            KernelIoControl(IOCTL_HAL_SHUTDOWN, IntPtr.Zero, 0, IntPtr.Zero, 0, bytesReturned);            //---按鍵的一個連續動作            keybd_event(VK_OFF, 0, 0, 0);            keybd_event(VK_OFF, 0, KEYEVENTF_KEYUP, 0);            //---按鍵的一個連續動作        }    }}


經本人測試,可用,都靜態方法,直接調用就行。

c# wince重啟代碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.