[Mono-list] Processname

Bill Seddon bill.seddon at lyquidity.com
Sun Oct 9 11:48:24 EDT 2005


Paul

If you launch the process using Process.Start(), you can retain a reference to the process class instance.  The Process class contains a reference to the "MainWindowHandle" so you should be able to use this value to work out which window is the one you want.

If you not dead set on launching the mono exe as an OS process, then why not just invoke it?  The mono .exe is an assembly containing classes and so can be invoked just like any other assembly.  The only difference being that you would want to invoke its entry point, not some arbitrary class in the assembly.  If you launch the exe assembly in its own thread, you can monitor it in much the same way as you can an OS spawned thread generated via Process.Start().

In case it is of interestm I've included a couple of code snippets that illustrate how you can invoke the main entry point.  The first is a trivial class with an entry point that would be compiled to an exe.  The second shows how to invoke the first program.

Bill Seddon

=== TestConsole.exe ==================================
using System;
using System.Windows.Forms;

namespace TestConsole
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			//
			// TODO: Add code to start application here
			//
			MessageBox.Show(
				string.Format("Started. Arg 0 is {0}", 
						  (args.Length == 0 ? 
						"Undefined" : args[0])));
		}
	}
}

=======================================================

=== Invoke function ===================================

internal void Test()
{
	const string csAssemblyName =  @"<path to>\TestConsole.exe";

	Assembly asm = Assembly.LoadFile(csAssemblyName);
	MethodInfo entry = asm.EntryPoint;

	object result = null;  // Invoke result
	string[] args = { "ABC", "XYZ" };    // Argument array

	if ( asm != null )
	{
		if ( entry.GetParameters().Length == 0 )
		{
			result = entry.Invoke( null, null ) ;
		}
		else
		{
			result = entry.Invoke( null, new Object[]{ args } ) ;
		}
	}
}

=======================================================


-----Original Message-----
From: mono-list-bounces at lists.ximian.com [mailto:mono-list-bounces at lists.ximian.com] On Behalf Of Loren Bandiera
Sent: 09 October 2005 12:33
To: Mono List
Subject: Re: [Mono-list] Processname


If you have "kernel support for MISC binaries" compiled in your kernel,
you can also do it like this:

# mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
# echo ':CLR:M::MZ::/usr/bin/mono:' > /proc/sys/fs/binfmt_misc/register

On Sun, 2005-10-09 at 12:16 +0100, Paul F. Johnson wrote:
> Hi,
> 
> > 1/ is it possible to execute à file .exe (like ./mysoft.exe) without  to 
> > write  (mono mysoft.exe) ?
> 
> You should be able to associate .exe files to run with mono. How you do
> that though depends on the distro, for me, I right click on the mouse,
> select run with other program, select mono and job's done. I then just
> run the exe as normal (okay, it only works for graphic executables...)
> 
> TTFN
> 
> Paul


-- 
Loren Bandiera <lorenb at mmgsecurity.com>
MMG Security, Inc.

_______________________________________________
Mono-list maillist  -  Mono-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list




More information about the Mono-list mailing list