高橋 忍のブログ

UX & モバイル、全ては心でエバンジェリズム♪

デバイスをリセットする (C#)

デバイスをリセットする (C#)

  • Comments 1

C#版。応用はそれほど広くないので、このまま使うといいですね。

public const uint FILE_DEVICE_HAL = 0x00000101;
public const uint METHOD_BUFFERED = 0;
public const uint FILE_ANY_ACCESS = 0;

public uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)
{
    return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method);
}

[DllImport("Coredll.dll")]
public extern static uint KernelIoControl
(
    uint dwIoControlCode,
    IntPtr lpInBuf,
    uint nInBufSize,
    IntPtr lpOutBuf,
    uint nOutBufSize,
    ref uint lpBytesReturned
);

private uint ResetPocketPC()
{
    uint bytesReturned = 0;
    uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15,
      METHOD_BUFFERED, FILE_ANY_ACCESS);
    return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0,
      IntPtr.Zero, 0, ref bytesReturned);
}

private void ResetDevice()
{
    DialogResult r = MessageBox.Show
    (
        "Are you sure you want to reset?",
        "Test",
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button2
    );

    if (r == DialogResult.Yes)
    {
        ResetPocketPC();
    }
}
 

 

 

Comments
Leave a Comment
  • Please add 6 and 5 and type the answer here:
  • Post