Link to home
Start Free TrialLog in
Avatar of Admigha
Admigha

asked on

Close a DOS program without a windows pop-up "CANNOT END PROGRAM"

Hi,
I'm using Visual Foxpro 9 vfp9 to control an old dos apllication AccPac Plus for DOS,
Sometimes the users leave an active application opened at night,
I found a way to track this behavior and to stop the program,
But I always have a message from Windows "CANNOT END PROGRAM" that requiers a manual intervention.
Is there a way to bypass this message or reply it programatically using VFP9?
The code to colse the program is:
PARAMETERS prog_to_stop
  oWMI = GETOBJECT('winmgmts://')
    cQuery = "select * from win32_process where name='"+prog_to_stop+"'"
    oResult = oWMI.ExecQuery(cQuery)
 x = 0
   FOR EACH oProcess IN oResult
      x = x + 1        
     oProcess.Terminate(0)
     NEXT
IF x>0
     MESSAGEBOX(STR(x,5,0)+' programs were stopped')
ELSE
    IF ISOPENED(prog_to_stop)
        TK ='!TASKKILL /FI "WINDOWTITLE EQ ' + prog_to_stop + '"'
        &TK
    ELSE       
       MESSAGEBOX('No such programs were found active to be stopped')
   ENDIF       
ENDIF
SOLUTION
Avatar of Chris H
Chris H
Flag of United States of America image

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
If you only have the problem in the branch using TASKKILL: Find a way to better specify the process to terminate, so the WMI query finds it.

I can say from experience oProcess.Terminate(0) works well. And there is more than just the name you can query to find a process, see http://msdn.microsoft.com/en-us/library/windows/desktop/aa394372(v=vs.85).aspx

For example, if you know how you started the DOS process, you can find it by the CommandLine property of the process. Or by it's path or description.

Bye, Olaf.
Avatar of Admigha
Admigha

ASKER

Thank you Olaf for replying,
this does not work and I tried it before (!TASKKILL /F /FI) acts like aswering cancel to the warning message, and what is strange in this command, that it removes the PID but the program still active.
SOLUTION
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
Avatar of Admigha

ASKER

Thank you Olaf,
Yes you are right I had to address to choward16980 for the /F switch.

What I'm doing is run the shortcout that itself points to a batch file xxx.bat and this btach runs the yyy.exe, when I kill the task it kills the DOS window and not the yyy.exe

can somebody tell me how to end the all tasks produced by running the shortcut?

knowing that I don't want to use the task manager, because it is an automated procedure.

Thanks everybody!
ASKER CERTIFIED SOLUTION
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
SOLUTION
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
FWIW,

I have a program that uses the NTVDM.exe process along with crystal reports.  I use the attached script (kill.txt) with the process.exe download from the url below and it works like a charm.  The script is also terminal server friendly so it only kills the process belonging to the user who runs it:


http://retired.beyondlogic.org/solutions/processutil/process203.zip
kill.txt
SOLUTION
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
Avatar of Admigha

ASKER

Thaks for help.
Antoine Lama.
Avatar of Admigha

ASKER

I did not find out how to close Accpac, the btach file is named appac.bat that runs a program plus.ese but the task manager shows NTVDM.EXE
You'll never find a .bat listed as task, the file extension .bat starts cmd.exe or command.com and these are in the task list. Also ESE files, as far as I googled, are database files (extensible storage engine) and likely start something else when you "execute" them, like mdb or accdb causes access.exe to start, this ESE extension might be associated to NTVDM.EXE

There are only very few executable file types, COM, SYS, DLL, EXE, nothing else. You will have to know what really is the process running, but you can also reidentify it by the CommandLine property of a win32_process.

For example open the windows start menu, in the search box type [cmd.exe /k help] and execute that by hitting ENTER. A Dos (cmd.exe) window should start and run the help command. Now open the task manager, In the processes tab it only shows cmd.exe , but if you add the colum "commandline" you can see your original call of cmd.exe including the /k help.

If you execute a bat file something similar happens, the task manager will show "cmd /c "path and file name of bat file.bat" in the command line column, and that's also what you get from a win32_process object. Your starting of a bat file causes execution of cmd.exe with a /c option and the bat file as parameter.

I hope that adds a bit more understanding. You'll never find a .bat or .cmd in the task list, like you don't find a .doc or .pdf there, these are not the processes running.

Bye, Olaf.