P
PJ on Development
I just got my Treo and noting the lack of a software reset (the need
to use the stylus on the reset button really annoys me), I decided to
build my own.
The Reset and Suspend part of my little program works like a charm and
then I decided to improve a little more and add a Hard Reset feature,
which would restore the device to its factory settings.
Searching high and low on the net I found two possible ways. The first
one involved calling SetCleanRebootFlag() and then reset the device.
---- Begin Code Snippet ----
[DllImport("coredll.dll", SetLastError=true)]
public static extern void SetCleanRebootFlag();
[DllImport("coredll.dll", SetLastError=true)]
private static extern int SetSystemPowerState(IntPtr psState,
PowerStateFlags flags, uint Options);
[DllImport("coredll.dll", SetLastError=true)]
private static extern bool KernelIoControl(int dwIoControlCode, IntPtr
inBuf, int inBufSize, IntPtr outBuf, int outBufSize, ref int
bytesReturned);
public static void SoftReset()
{
if (SetSystemPowerState(IntPtr.Zero, PowerStateFlags.Reset,
0x1000) != 0)
{
int bytesReturned = 0;
if (!KernelIoControl(0x101003c, IntPtr.Zero, 0, IntPtr.Zero,
0, ref bytesReturned))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
}
public static void HardReset()
{
SetCleanRebootFlag();
SoftReset();
}
---- End Code Snippet ----
The other involved using the ConfigurationManager to process a XML
that would perform a "RemoteWipe".
---- Begin Code Snippet ----
public static void HardReset()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<wap-provisioningdoc><characteristic
type='RemoteWipe'><parm name='doWipe' value='1'/></characteristic></
wap-provisioningdoc>");
ConfigurationManager.ProcessConfiguration(doc, true);
}
---- End Code Snippet ----
The first method didn't work because after Windows Mobile 5 it ignores
the CleanBootFlag; the second method worked... too much.
It corrupted the microSD on the device to the point that it needed to
be reformatted in order to be recognized again.
Does anyone had any experience with that?
to use the stylus on the reset button really annoys me), I decided to
build my own.
The Reset and Suspend part of my little program works like a charm and
then I decided to improve a little more and add a Hard Reset feature,
which would restore the device to its factory settings.
Searching high and low on the net I found two possible ways. The first
one involved calling SetCleanRebootFlag() and then reset the device.
---- Begin Code Snippet ----
[DllImport("coredll.dll", SetLastError=true)]
public static extern void SetCleanRebootFlag();
[DllImport("coredll.dll", SetLastError=true)]
private static extern int SetSystemPowerState(IntPtr psState,
PowerStateFlags flags, uint Options);
[DllImport("coredll.dll", SetLastError=true)]
private static extern bool KernelIoControl(int dwIoControlCode, IntPtr
inBuf, int inBufSize, IntPtr outBuf, int outBufSize, ref int
bytesReturned);
public static void SoftReset()
{
if (SetSystemPowerState(IntPtr.Zero, PowerStateFlags.Reset,
0x1000) != 0)
{
int bytesReturned = 0;
if (!KernelIoControl(0x101003c, IntPtr.Zero, 0, IntPtr.Zero,
0, ref bytesReturned))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
}
public static void HardReset()
{
SetCleanRebootFlag();
SoftReset();
}
---- End Code Snippet ----
The other involved using the ConfigurationManager to process a XML
that would perform a "RemoteWipe".
---- Begin Code Snippet ----
public static void HardReset()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<wap-provisioningdoc><characteristic
type='RemoteWipe'><parm name='doWipe' value='1'/></characteristic></
wap-provisioningdoc>");
ConfigurationManager.ProcessConfiguration(doc, true);
}
---- End Code Snippet ----
The first method didn't work because after Windows Mobile 5 it ignores
the CleanBootFlag; the second method worked... too much.
It corrupted the microSD on the device to the point that it needed to
be reformatted in order to be recognized again.
Does anyone had any experience with that?