disabling the cmd close button by batch command

Solution 1:

You could create an executable that disables the [X] button for all processes named "cmd", and run that executable the first line of your batch file.

Here is a c# program that does just that:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Remove__X__Button_from_another_process
{

class Program
{
    [DllImport("user32.dll")]
    static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

    [DllImport("user32.dll")]
    static extern bool DeleteMenu(IntPtr hMenu, uint uPosition, uint uFlags);

    const uint SC_CLOSE = 0xF060;
    const uint MF_BYCOMMAND = 0x00000000;

    static void Main(string[] args)
    {
        //Console.Write("Please enter process name:"); // "cmd"
        //String process_name = Console.ReadLine();

        Process[] processes = Process.GetProcessesByName("cmd");
        foreach (Process p in processes)
        {
            IntPtr pFoundWindow = p.MainWindowHandle;

            IntPtr nSysMenu = GetSystemMenu(pFoundWindow, false);
            if (nSysMenu != IntPtr.Zero)
            {
                if (DeleteMenu(nSysMenu, SC_CLOSE, MF_BYCOMMAND))
                {

                }
            }
        }
        Environment.Exit(0);
    }
}

Solution 2:

You can't.

You could hide the execution of the batch file by using a VBScript

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("yourbatchfile.bat"), 0, True

That would hide it from the user, but it wouldn't stop them from killing it in task manager.

What you're asking can't really be done.