Solved

Windows mobile application restart

Posted on 2010-08-25
8
1,220 Views
Last Modified: 2013-12-21
Hello experts,

Is there any way to restart my windows mobile 6.1 application programmatically? i use vb.net

thanks
0
Comment
Question by:spiral2007
8 Comments
 
LVL 18

Expert Comment

by:Dennis Aries
ID: 33518981
Try this
Sub Restart(ByVal program As String)
        For Each proc As Process In Process.GetProcesses
            If proc.ProcessName = program Then proc.Kill()
        Next
        Process.Start(program)
   End Sub
0
 
LVL 3

Expert Comment

by:efatihan
ID: 33518988
Take this,

#Region "declares for softreset (KernelIOControl)"

' Control Code flags
Private Const FILE_DEVICE_UNKNOWN As UInteger = &H22
Private Const FILE_DEVICE_HAL As UInteger = &H101
Private Const FILE_DEVICE_CONSOLE As UInteger = &H102
Private Const FILE_DEVICE_PSL As UInteger = &H103
Private Const METHOD_BUFFERED As UInteger = 0
Private Const METHOD_IN_DIRECT As UInteger = 1
Private Const METHOD_OUT_DIRECT As UInteger = 2
Private Const METHOD_NEITHER As UInteger = 3
Private Const FILE_ANY_ACCESS As UInteger = 0
Private Const FILE_READ_ACCESS As UInteger = &H1
Private Const FILE_WRITE_ACCESS As UInteger = &H2

Private Shared Function CTL_CODE(DeviceType As UInteger, [Function] As UInteger, Method As UInteger, Access As UInteger) As UInteger
      Return ((DeviceType << 16) Or (Access << 14) Or ([Function] << 2) Or Method)
End Function

''' <summary>
''' This function provides the kernel with a generic I/O control for
''' carrying out I/O operations.
''' </summary>
''' <param name="dwIoControlCode">I/O control code, which should support the
''' OAL I/O controls. For a list of these I/O controls, see Supported
''' OAL APIs.</param>
''' <param name="lpInBuf">Pointer to the input buffer.</param>
''' <param name="nInBufSize">Size, in bytes, of lpInBuf.</param>
''' <param name="lpOutBuf">Pointer to the output buffer.</param>
''' <param name="nOutBufSize">Maximum number of bytes that can be returned in
''' lpOutBuf.</param>
''' <param name="lpBytesReturned">Address of a DWORD that receives the size,
''' in bytes, of the data returned.</param>
''' <returns>TRUE indicates success; FALSE indicates failure.</returns>
<DllImport("Coredll.dll")> _
Private Shared Function KernelIoControl(dwIoControlCode As UInteger, lpInBuf As IntPtr, nInBufSize As UInteger, lpOutBuf As IntPtr, nOutBufSize As UInteger, ByRef lpBytesReturned As UInteger) As UInteger
End Function
#End Region




''' <summary>
''' the method needed to be called to actually reset the device.
''' </summary>
Public Shared Sub ResetDevice()
      Dim bytesReturned As UInteger = 0
      Dim IOCTL_HAL_REBOOT As UInteger = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
      KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, bytesReturned)
End Sub
0
 
LVL 3

Expert Comment

by:efatihan
ID: 33519013
0
 

Author Comment

by:spiral2007
ID: 33519085
efatihan i want to restart my application not my device.

djjaries your way is for windows form application ? i use windows mobile 6.1 compact framework


any other suggestions?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 3

Accepted Solution

by:
efatihan earned 500 total points
ID: 33519152
sorry, i misunderstood your question.
in compact framework, to restart your application you have two choices, one is the following
(i am not sure if it is going to work on wm 6.1)

Public Shared Sub RestartApplication()
      Dim fileName As String = Assembly.GetExecutingAssembly().GetName().CodeBase
      Application.[Exit]()
      Dim startInfo As New ProcessStartInfo(fileName)
      Process.Start(startInfo)
End Sub


the other one is to schedule your application using CeRunAppAtTime to wake up after you close it.
the example is at the following url:
http://www.pinvoke.net/default.aspx/coredll.CeRunAppAtTime

just add few seconds to "now" and let the application start itself.

good luck.
0
 

Author Comment

by:spiral2007
ID: 33520080
hello efatihan i follow the http://www.pinvoke.net/default.aspx/coredll.CeRunAppAtTime
example and it works only if i schedule the wakeup after 10 sec.
is there any way to make this wakeup operation start faster or immediately? (if i change the seconds variable and put a value less than 10sec nothing happens)

thanks
0
 
LVL 3

Expert Comment

by:efatihan
ID: 33520181
hello,

this article might help you. i will still continue to look for any remedy.
http://msdn.microsoft.com/en-us/library/aa931253.aspx
0
 
LVL 24

Expert Comment

by:alexey_gusev
ID: 33520401
as the previous link states, the default is 10 seconds for CeRunAtTime() unless it is implemented differently by the vendor.

you might want to consider the dummy console app that just starts your main exe and then exits.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

With mobile becoming increasingly important to the business world, it is in your best interest to make sure that your email signature looks great across all types of devices. Find out how to create a mobile email signature with this guide.
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now