I have a .dll library for c# that loves to pop out a 'Welcome' screen when it starts. This screen appears as an application in the task manager.

Is there some way to automatically detect this application/form being launched and close it?
Thanks! :)
I have a .dll library for c# that loves to pop out a 'Welcome' screen when it starts. This screen appears as an application in the task manager.

Is there some way to automatically detect this application/form being launched and close it?
Thanks! :)
Here us simple console application that will monitor and close specified window
class Program
{
    static void Main(string[] args)
    {
        while(true)
        {
            FindAndKill("Welcome");
            Thread.Sleep(1000);
        }
    }
    private static void FindAndKill(string caption)
    {
        Process[] processes = Process.GetProcesses();
        foreach (Process p in processes)
        {
            IntPtr pFoundWindow = p.MainWindowHandle;           
            StringBuilder windowText = new StringBuilder(256);
            GetWindowText(pFoundWindow, windowText, windowText.Capacity);
            if (windowText.ToString() == caption)
            {
                p.CloseMainWindow();
                Console.WriteLine("Excellent kill !!!");
            }
        }
    }
    [DllImport("user32.dll", EntryPoint = "GetWindowText",ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
    private static extern int GetWindowText(IntPtr hWnd,StringBuilder lpWindowText, int nMaxCount);
}
If it's running within your process and opening a Form (not a Dialog), you can use something like this to close all Forms which aren't opened by your own Assembly.
foreach (Form form in Application.OpenForms)
    if (form.GetType().Assembly != typeof(Program).Assembly)
        form.Close();
What is your own Assembly is defined by the class Program, you could also use Assembly.GetExecutingAssembly or Assembly.GetCallingAssembly, but I'm not sure it will behave correctly, if you run the Application inside Visual Studio (since it might return the VS Assembly).