Launch EXE from inside vb.net device app

jenn5175

Active member
Joined
Apr 4, 2002
Messages
35
I have given up on all of the smart device boards because no one seems to have answered so I have expanded onto you desktop programmers in hopes someone may be able to help. I am programming for a Windows CE .NET device using VS 2003 (VB). All I need to do is launch an executable from inside my program - you wouldnt think it would be causing me such grey hair. So far I have found the following are not supported in device programming: shell(), shellexecute(), process.start(), createprocess(). I heard a rumor that ShellExecuteEx() is supported, but I have only found 1 VB example which implements it and I cannot get the sample to work (it needs the window handle - me.hWnd - but Im thinking window handles dont exist in VB.NET/SD programming). Does anyone have an example of how to use ShellExecuteEx() in VB? Or have another idea? Or possibly have a clue how I can get hWnd so I can use my other example? Anything! Im getting desperate!

Jenn
 
You can get the hWnd of a form using the Form.Handle property. It will be of the IntPtr type, so make sure your api declare has the hWnd parameter defined that way too.

You could probably pass 0 to it too.
 
I tried passing it zero at first and it wouldnt launch anything so I think it didnt appreciate my workaround. Also, there is no such thing as a handle property that I can find. I have tried "me", "form", and "formName" and none support the handle property when developing for a smart device. But I found a workaround which seems to work and completely avoids using a handle. Thanks for your suggestion!

Jenn
 
Heres the solution I found for launching an application from within a VB.NET application for Smart Devices:

Imports System
Imports System.Runtime.InteropServices

Public Class frmGMNAOSetup
Inherits System.Windows.Forms.Form

<DllImport("coredll.dll")> _
Protected Shared Function CreateProcess( _
ByVal imageName As String, _
ByVal cmdLine As String, _
ByVal lpProcessAttributes As IntPtr, _
ByVal lpThreadAttributes As IntPtr, _
ByVal boolInheritHandles As Int32, _
ByVal dwCreationFlags As Int32, _
ByVal lpEnvironment As IntPtr, _
ByVal lpCurrentDir As IntPtr, _
ByVal si() As Byte, _
ByVal pi As ProcessInfo) As Int32
End Function


Private Sub frmGMNAOSetup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim si(128) As Byte
Dim pi As New ProcessInfo
Dim iRtn As Int32
iRtn = CreateProcess("\windows\pword.exe", "", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, si, pi)
MsgBox(iRtn)

End Sub

End Class
Public Class ProcessInfo
Public hProcess As Int32
Public hThread As Int32
Public ProcessID As Int32
Public ThreadID As Int32
End Class
 
Back
Top