Para quem já tentou executar um programa externo ao abrir seu programa ou clicando em algum botão esta classe vai ser de grande ajuda.
Classe:
1: Imports System.Runtime.InteropServices
2:
3: Public Class ExecutarProgramas
4: <DllImport("CoreDll.DLL", SetLastError:=True)> _
5: Private Shared Function CreateProcess(ByVal imageName As String, _
6: ByVal cmdLine As String, _
7: ByVal lpProcessAttributes As IntPtr, _
8: ByVal lpThreadAttributes As IntPtr, _
9: ByVal boolInheritHandles As Int32, _
10: ByVal dwCreationFlags As Int32, _
11: ByVal lpEnvironment As IntPtr, _
12: ByVal lpszCurrentDir As IntPtr, _
13: ByVal si() As Byte, _
14: ByVal pi As ProcessInfo) As Integer
15: End Function
16: <DllImport("CoreDll.dll")> _
17: Private Shared Function GetLastError() As Int32
18: End Function
19: Public Shared Function CreateProc(ByVal ExeName As String, _
20: ByVal CmdLine As String, _
21: ByVal pi As ProcessInfo) As Boolean
22: If pi Is Nothing Then
23: pi = New ProcessInfo
24: End If
25: Dim si(127) As Byte
26: Return CreateProcess(ExeName, CmdLine, IntPtr.Zero, _
27: IntPtr.Zero, 0, 0, _
28: IntPtr.Zero, _
29: IntPtr.Zero, si, pi) <> 0
30: End Function 'CreateProc
31: End Class 'Externals
32:
33: Public Class ProcessInfo
34: Public hProcess As IntPtr
35: Public hThread As IntPtr
36: Public ProcessId As Int32
37: Public ThreadId As Int32
38: End Class 'ProcessInfo
Programa principal:
1: ExecutarProgramas.CreateProc("\Windows\ScanWedge.exe", "ScanWedge", Nothing)
Com isso podemos executar um programa externo no Windows CE com VS.NET 2003
Um comentário:
Cristinano venho por este meio te agradecer o teu post. foi muito util para mim pois estou dentro destes temas à pouco tempo e precisava mesmo disto. Obrigado Nuno Teixeira - Portugal - Responsavel TI de empresa de logistica em Portugal. nuno.teixeira@vodafone.pt
Postar um comentário