Search code examples
vbabatch-filems-accesstaskkill

Issues with Batch Taskkill of Parent MSAccess Process


Process Tree:

I have an MS Access version control macro that checks users current file version on open, and if not up-to-date, the macro launches a batch file that 1) should delete their current file, and then 2) copies the up-to-date front-end version from the network and pastes it on their local system.

My issue:

Everything works EXCEPT for the deletion of the users original file. Since this file is the parent process of the batch file I haven't found a way to Kill the task so it can be deleted.

Current Code:

TASKKILL /F /fi /IM MSACCESS.EXE /T

del "%originalFile%"

**I thought maybe I was having issues because the batch was a child of the Access process, so I've also tried with no luck:

TASKKILL /F /fi /IM MSACCESS.EXE

I always get the error:

ERROR: Invalid syntax. Value expected for '/fi'.

Its been a long day, so I assume I'm missing something simple and would love an extra set of eyes. Any help would be greatly appreciated!


Solution

  • I have a similar setup, but without TASKKILL.

    Directly after launching my update batch, I do Application.Quit

    ' If need to update
    Shell UPDATE_BATCH, vbNormalFocus
    Application.Quit
    

    And in the update batch, I wait for 3 seconds so that Access has enough time to exit (and release the lock on the frontend).

    sleep.exe 3
    REM ... copy new frontend ...
    sleep.exe 1
    REM ... start MSACCESS command line ...
    

    How to "sleep"? See here: SLEEP.exe (2003 Resource Kit) for different variants.