Problem with CreateProcess

G

Guest

Hi,

When I start up my device, instead of explorer.exe I am starting a VB.Net
program. The VB.Net program checks to see if I have ever aligned my ELO touch
screen (I create a file to indicate this) I call ELO's alignment program
using CreateProcess. My problem is that even though I think the calling
program is waiting for the ELO Alignment program to finish, it does not seem
to. The calling program continues on its' merry way and I only see my
alignment screen for a few seconds. I assume I am using CreateProcess
incorrectly, does any one see any problems with my code?

Thank you for your help,

Hari

Overloads Declare Function CreateProcess Lib "CoreDll.dll" (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 lpszCurrentDir
As IntPtr, ByVal si As Byte(), ByVal pi As ProcessInfo) As Integer

Public Declare Function WaitForSingleObject Lib "CoreDll.dll" (ByVal Handle
As IntPtr, ByVal Wait As Int32) As Int32

Public Declare Function CloseHandle Lib "CoreDll.dll" (ByVal Handle As
IntPtr) As Int32

Public Sub Align_Me()
Dim bAlignmentOK As Boolean = False

File.Delete(alignmentPath)

While bAlignmentOK = False
Dim progPath As String = "\Windows\EloVa.exe"
Dim pi As New ProcessInfo
CreateProcess(progPath, "", pi)
Dim swAlign As StreamWriter = File.CreateText(alignmentPath)
swAlign.WriteLine("Aligned on " + Now().ToLongDateString +
Now().ToLongTimeString)
swAlign.Flush()
swAlign.Close()
If RegFlushKey(HKEY_LOCAL_MACHINE) = SUCCESS Then
If MsgBox("Click anywhere on the screen to see if the pointer follows
your finger correctly." + vbCrLf + _
"When you are satisfied that the alignment is
correct click OK, to align again click cancel.", _
MsgBoxStyle.OKCancel, "Alignment Verification") = MsgBoxResult.OK
Then
bAlignmentOK = True
End If
End If
End While
End Sub

Public Class ProcessInfo
Public hProcess As IntPtr
Public hThread As IntPtr
Public ProcessId As Int32
Public ThreadId As Int32
End Class 'ProcessInfo

Public Overloads Shared Function CreateProcess(ByVal ExeName As String,
ByVal CmdLine As String, ByVal pi As ProcessInfo) As Boolean
Dim INFINITE As Int32
INFINITE = &HFFFFFFFF

Dim WAIT_OBJECT_0 As Int32 = 0
Dim result As Int32

If pi Is Nothing Then
pi = New ProcessInfo
End If
Dim si(128) As Byte

result = CreateProcess(ExeName, CmdLine, IntPtr.Zero, IntPtr.Zero, 0, 0,
IntPtr.Zero, IntPtr.Zero, si, pi)
System.Threading.Thread.Sleep(10000)
If 0 = result Then
Return False
End If

result = WaitForSingleObject(pi.hProcess, INFINITE)
CloseHandle(pi.hThread)
CloseHandle(pi.hProcess)
If WAIT_OBJECT_0 <> result Then
Return False
End If
Return True
End Function
 
P

Paul G. Tobey [eMVP]

If you feel that you must post the same question to multiple groups, list
the groups in a single To line of one message. This keeps the answers
together with the questions and keeps from annoying those who read several
groups. Please *read* the answers to your questions in the other groups...

Paul T.
 
G

Guest

Paul,
You have helped me in the past and I greatly appreciate it.

I have solved this particular problem, as it turns out a hardware problem
was causing the alignment program to terminate and CreateProcess was not to
blame.

As for my bad manners in multiple posting, it was your response to my
initial posting that led to me reposting on another news group. Please excuse
my ignorance but I make all my posts though the msdn site and do not know how
to “add a group to a listâ€.

Please do not take this posting as sarcastic or ungrateful, if you or anyone
else would publish or point me to a “Rules of Etiquette†for using these
groups, I would more than happy to follow them to the letter.

Again I am truly grateful for all the help given in this group,

Hari
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top