This cannot be done from the command line. You will need something secondary (vbs, powershell or custom MyApp.exe) to catch cmd.exe when it is closed and respond accordingly.
For example, a VBS WMI monitor.
strComputer = "." Set objSWbemServices = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & "\\" & strComputer & "\root\cimv2") Set objEventSource = objSWbemServices.ExecNotificationQuery( "SELECT * FROM __InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name = 'cmd.exe'") Set objEventObject = objEventSource.NextEvent() Wscript.Echo "CMD.exe closed"
source share