VB.NET Soft reset function for smart devices

Public Function SoftReset() As Integer
Dim bytesReturned As Integer = 0
Dim r As System.Windows.Forms.DialogResult
‘ Show the user a dialog first, giving them the option to cancel
r = System.Windows.Forms.MessageBox.Show( _
“Running this test will soft reset the device and cancel subsequent tests. Do you wish to continue?”, _
“ResetDevice Test”, _
System.Windows.Forms.MessageBoxButtons.YesNo, _
System.Windows.Forms.MessageBoxIcon.Question, _
System.Windows.Forms.MessageBoxDefaultButton.Button2 _
)
‘ If the user said “yes, soft reset”, then…
If r = System.Windows.Forms.DialogResult.Yes Then
Dim IOCTL_HAL_REBOOT As Integer = CTL_CODE(FILE_DEVICE_HAL, _
15, METHOD_BUFFERED, FILE_ANY_ACCESS)
‘ Run the function from coredll.dll
Return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, _
IntPtr.Zero, 0, bytesReturned)
Else
‘ If the user said “no, don’t soft reset”, then show a message
‘ box
System.Windows.Forms.MessageBox.Show(“Soft Reset aborted by user”)
Return bytesReturned
End If
End Function

Post to Twitter Post to Delicious Post to Facebook

Leave a Reply

Seek in here
Translator
Archive