• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 818
  • Last Modified:

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
0
Admigha
Asked:
Admigha
  • 5
  • 5
  • 2
5 Solutions
 
Chris HIT DirectorCommented:
Change
!TASKKILL /FI
!TASKKILL /F /FI

That will force close the window
0
 
Olaf DoschkeSoftware DeveloperCommented:
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.
0
 
AdmighaAuthor Commented:
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.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
Olaf DoschkeSoftware DeveloperCommented:
Well, there is the DOS window and the application you run in it, isn't it so? That's two PIDs.
But why do you address me, choward16980 gave the hint about the /F switch.

I just see you only get into that branch, if the oResult from WMI has no processes. So have you debugged the code, single stepped through it to see what actually executes?

Bye, Olaf.
0
 
AdmighaAuthor Commented:
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!
0
 
AdmighaAuthor Commented:
Hi Everybody,
I found an Indirect solution to close Accpac by TASKKILL /F
1- to find the IM name of Accpac in taskmanager id did the following:
    a- tasklist  > c:\temp\taslist1.txt
    b- I run the sohortcut of Accpac
    c- tasklist  > c:\temp\taslist2.txt
    d- I compared the 2 lists taslist1 vs taslist2
I found that accpac has this  name NTVDM.EXE
2- i RUN THE AUTOPROGRAM to close the Accpac including this command line:
    TASKKILL /F /im ntvdm.exe >C:\temp\result.TXT
3- I included the C:\temp\result.TXT to check the result by the program
0
 
Olaf DoschkeSoftware DeveloperCommented:
You can also see a full task list if you run your WMI query without the WHER-Clause, so just query "select * from win32_process".

But as you know you want to stop the NTVDM.EXE pass that in as the prog_to_stop.

What did you pass in before? The name of a BAT/CMD file?

Bye, Olaf.

Edit: If you would shellexecute a DOC file it would also trigger Word.EXE to run, and not the DOC file. So you would stop Word and not the DOC.

A BAT or CMD file cause a CMD.EXE to run and the commands inside the bat cause NTVDM.EXE to run, obviously.

It seems you just tried to kill the wrong thing.
0
 
Chris HIT DirectorCommented:
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
0
 
Olaf DoschkeSoftware DeveloperCommented:
Well, thanks for sharing.

I think I'll stay with WMI. The win32_process class also gives you the Method GetOwner:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394372(v=vs.85).aspx

See http://www.foxite.com/archives/know-what-other-exes-are-runing-0000136534.htm

You can pretty much get all infos that also come from the Task Manager and do anything programmatically.

Bye, Olaf.
0
 
AdmighaAuthor Commented:
Thaks for help.
Antoine Lama.
0
 
AdmighaAuthor Commented:
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
0
 
Olaf DoschkeSoftware DeveloperCommented:
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.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 5
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now