Problem passing the Filename to a Process

cento68

New member
Joined
May 19, 2005
Messages
2
Programming Experience
1-3
Hi,

I'm trying to run an executable (ProgA.exe) from within my vb written program.
The executable is quite simple. It requires a text file of a specific format in the same directory and output to a text file again in the same directory. It was compiled in Fortran (Intel) and shows a DOS window while in operation (for a very short time).

I've been able to execute ProgA.exe from my code by using the Process class and StartInfo property. Also i have used a handler to identify when has the process exited.

Initially the user was able to choose the executable using the standard OpenDialog control, and the file name (and complete path) are then stored in a string variable which is passed to the Process.StartInfo.Filename.

However, i need to automate the call to the process and bypass the user selection. As i know the location of the executable (ProgA.exe) i just save the path as a string, ie: "C:\Documents and Settings\UserName\My Documents\...\ProgA.exe" and then pass this string to the Process.StartInfo.Filename.

To my surprise, the second method doesn't work. Only if i pass the complete path using the OpenDialog will the ProgA.exe, execute succesfully!

I would appreciate if anyone knows why this is or has a solution to the problem. I hope i'm just plain stupid and missing something obvious but this is driving me insane!
sad.gif


Thans in advance,

V

Process Component:
VB.NET:
' create the Process component.
		mDatcom = New Process

		With mDatcom

			' set EnableRaisingEvents to True.
			.EnableRaisingEvents = True

			' add an event handler to trap the Exited event.
			AddHandler .Exited, AddressOf OnProcessExit

			' build the StartInfo object and set properties
			' - set the FileName property to the argument that was passed.
			.StartInfo.UseShellExecute = False
			.StartInfo.FileName = mDatcomFilePath
			' - enable the ErrorDialog
			.StartInfo.ErrorDialog = True
			' - hide the window
			.StartInfo.CreateNoWindow = True
			'.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

			' run datcom
			mProcessTerminated = False
			ExitLoop = False
			mStartTime = Now
			.Start()

		End With


Handler:

VB.NET:
' event handler for Process.Exited Event
	Private Sub OnProcessExit(ByVal sender As Object, ByVal e As EventArgs)

		' avoid late binding and cast the object to a specific process component.
		Dim proc As Process = CType(sender, Process)

		' write out the exit information.
		'Debug.WriteLine(proc.ExitCode)
		mEndTime = proc.ExitTime

		' dispose and clear the object.
		'proc.Dispose()
		'proc = Nothing

		' set flag
		mProcessTerminated = True

	End Sub
 
kleinma in vbforums.com kindly gave the answer:

VB.NET:
mStartTime = Now
ChDir("directory where ProgA.exe is")
.Start()
[\code]

It seems like the OpenDialog control resets the current directory and which is required by the process.
 
Back
Top