Link to home
Start Free TrialLog in
Avatar of Russ Suter
Russ Suter

asked on

C# Application to Launch and Monitor a VB6 Application

I have an old application written in Visual Basic 6. We'd love nothing more than to retire it but can't yet. So, I'm trying to build a C# program that will launch and monitor the VB 6 application. Getting the application to launch and check for its exit state is trivial. The entire application is here:
	static class Program
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main()
		{
			Process remoteProcess = Process.Start(@"C:\Program Files (x86)\Test\MyProgram.exe", "user1");
			remoteProcess.EnableRaisingEvents = true;
			remoteProcess.Exited += RemoteProcess_Exited;
			remoteProcess.WaitForExit();
		}

		private static void RemoteProcess_Exited(object sender, EventArgs e)
		{
			Process remoteProcess = sender as Process;
			if (remoteProcess.ExitCode != 0)
			{
				MessageBox.Show($"The program terminated abnormally (exit code {remoteProcess.ExitCode})");
			}
		}
	}

Open in new window

This works just fine for what it does. However, I'd like to be able to monitor the application for more details like when the user opens another form from within the application. It's an old MDI application and I know the VB6 form class is something like ThunderRT6Form. I'm guessing I'll have to get into some lower level Windows hooks to make this work but I don't really know where I should start. Anyone have any ideas?
Avatar of Ares Kurklu
Ares Kurklu
Flag of Australia image

One way I can think of would be to get VB to create some sort of file in a folder indicating that a specific form is open, even some sort of log file
but then I suppose you may not want to read all the logs.
You can simply create a file and  if the user closes the form you may have to remove the file.
Then you can monitor from the C# program that folder and look for those files.
Avatar of Russ Suter
Russ Suter

ASKER

I've already considered that. There are literally hundreds of forms in the VB6 application and I'd have to alter the code on every single one of them to implement something like that. It's just not practical. I'm looking for a clever solution here.
Sorry can't really think of any other way of both programs interacting especially when one is such an outdated technology like VB6, I guess this may be your best shot.
ASKER CERTIFIED SOLUTION
Avatar of Russ Suter
Russ Suter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No alternatives provided and this worked.