Link to home
Start Free TrialLog in
Avatar of DavidWare
DavidWareFlag for United States of America

asked on

End a batch file

Hello Experts,
I an typically making changes to the .MDB weekly.
I want those changes to go into effect the next time a user fires up my .MDE, so I compile it to the network, and have the users execute a batch file that copies the new .MDE to their local work stations, then fires up the latest version of the .MDE.

The problem is, my batch file won't end until the user terminates the .MDE.

Is there a way to force the batch file to end and close while the .MDE is still running?

here is the batch file:


*********

copy "O:\MyDir\MyOtherDir\MyProgram.mde" "C:\Program Files\MyDir\MyOtherDir\MyProgram.mde" /y
"C:\Program Files\MyDir\MyOtherDir\MyProgram.mde"

*********

Thanks,
David
SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
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
It won't quit because it should not.

Here's another method for this purpose.

Create a shortcut to run the copy and launch process.
Choose tab Program.
Set Command line to: "C:\Program Files\MyDir\MyOtherDir\MyProgram.mde"
Set Batch file to: <path and name of your batch file>
Mark Close when finished/terminated.

Reduce the batch file to:

@echo off
echo Copying current program file ...
copy "O:\MyDir\MyOtherDir\MyProgram.mde" "C:\Program Files\MyDir\MyOtherDir\MyProgram.mde"

Now, let the users run the shortcut.

/gustav
Try START first - I'm fairly certain it will work.
Avatar of DavidWare

ASKER

Hello leew and Cactus_Data
leew,
start does end the first command prompt session, but it opens another one in the C:\Program Files\MyDir\MyOtherDir directory
(My cursor is:  C:\Program Files\MyDir\MyOtherDir>_  )


gustav,
I think you are suggesting that I have 2 seperate shortcuts:
1) one to copy the .MDE over from the network to the local drive, and
2) a completely seperate shortcut for executing the .MDE.

Am I right?

If so. that is not my goal.

I want the users to

1) double-click the icon and have my batch file copy the .MDE over from the network to the local drive AND EXECUTE THE .MDE all in the same batch file.

Only one shortcut, please.

The question that will get the points is "Is there a way to force the batch file to end and close while the .MDE is still running?"

Thanks,
David
Can you post the batch file.  Start should work.
> I think you are suggesting that I have 2 seperate shortcuts

I wonder why? This is what I wrote:

Create a shortcut to run the copy and launch process.

We use this method at those of our clients with POS applications; these just have to work.
We even put the shortcut in the Start folder.

/gustav
Hello leew and gustav,
First, thanks again for the followup.  I intend to increase the points and split them.

leew,
the batch fril is just as you posted:

copy "O:\MyDir\MyOtherDir\MyProgram.mde" "C:\Program Files\MyDir\MyOtherDir\MyProgram.mde" /y
start "C:\Program Files\MyDir\MyOtherDir\MyProgram.mde"

The first command window opens and copies the .MDE from the network to the local drive, then closes.
But then another command window opens with the following text in the blue bar at the top:
          C:\Program Files\MyDir\MyOtherDir\MyProgram.mde

and the following text in the command window:

          Microsoft Windows 2000 [Version 5.00.2195]
          (C) Copyright 1985-2000 Microsoft Corp

          O:\MyDir\MyOtherDir>

and the cursor blinking to the right of the O:\MyDir\MyOtherDir>

*** my mistake in the previous post when I wrote: "(My cursor is:  C:\Program Files\MyDir\MyOtherDir>_  )"
Actually My cursor is:  O:\MyDir\MyOtherDir> ***


gustav,
Forgive me, but I am not understanding the instructions.
you said:
Create a shortcut to run the copy and launch process.
Choose tab Program.
Set Command line to: "C:\Program Files\MyDir\MyOtherDir\MyProgram.mde"
Set Batch file to: <path and name of your batch file>
Mark Close when finished/terminated.


First, when I create a shortcut, there are no Tabs, simply a textbox for the full file name, and a Browse button.  Then a textbox for the name.
So, I create a shortcut, then (once it's created), I open it's properties.
Now I have Tabs, but none called "Program".
So, selecting the "Shortcut" tab, I enter the full file name of the program, as you wrote:
"Set Command line to: 'C:\Program Files\MyDir\MyOtherDir\MyProgram.mde'"
Now, your instruction: "Set Batch file to: <path and name of your batch file>" is completely confusing.
There is no place to reference a Batch File in the shortcut properties.  
There is a place to reference the "Start In" directory, but that will not accept a full file name.
The error says that "The Folder... is not valid".  This "Start In" is looking for a Directory only.

So, as you can see, I am trying to follow your instructions, but your syntax seems to be non sequitur.

David
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
Hello gustav,
Well, we're getting closer.
I created the .PIF shortcut, and edited it as follows:

Program Tab
Cmd line: "C:\Program Files\MyDir\MyOtherDir\MyProgram.mde"
Working: "C:\Program Files\MyDir\MyOtherDir"
Batch File: "O:\MyDir\MyOtherDir\UpdateAndRunMagProgram.bat

So when I run it, the error tells me:

C:\DOCUME~1\DavidWare\Desktop\MyProgram.pif
C:\Program Files\MyDir\MyOtherDir\MyProgram.mde.
The file is not a valid MS-DOS program file.
MS-DOS program files must end with the extension .EXE, .COM, or .BAT.

So I tried putting just the batch file in as the CmdLine and the Command window opens for a flash but closes w/o copying or running the .MDE.
I tried substituting "O:\MyDir\MyOtherDir" in as the "Working" directory, but when there is an .MDE file listed as the "Cmd line" file, it fails with the above copied error.

It looks like it wants the .BAT file in as the "Cmd line" but that does nothing besides flash the Dos window at me.

What am I doing wrong?

Thanks,
David
You need the full command line, like:

Cmd line: "C:\Program Files\Microsoft Office\Access\MsAccess.exe" "C:\Program Files\MyDir\MyOtherDir\MyProgram.mde"

/gustav
Hello gustav,
Thanks for replying.

The shortcut opens the local copy of the .MDE, but it's last week's version.
This week's version of the program is not being copied from the network first.

Cmd line:  "C:\Program Files\Microsoft Office\Office\MSAccess.exe" "C:\Program Files\MyDir\MyOtherDir\MyProgram.mde"
Working:   "C:\Program Files\MyDir\MyOtherDir"
Batch File:  O:\MyDir\MyOtherDir\UpdateAndRunMyProgram.bat

UpdateAndRunMyProgram.bat contains the command:
copy "O:\MyDir\MyOtherDir\MyProgram.mde" "C:\Program Files\MyDir\MyOtherDir\MyProgram.mde" /y


In other words, the shortcut doesn't copy the new version of the file (from the network to the local drive) before executing the local copy.
I assume that the shortcut is executing the local copy first, then is unable to overwrite the locan .MDE, because it's in use.
(As a result, I assume, the Command window stays open while the local copy is running - which is the reason for this question in the first place).

Any ideas on how to get the .BAT file to execute first (copying over this week's version of the .MDE), and then execute the .MDE?

Thanks,
David
Tried creating 2 .BAT files - one to copy the file and one to execute it.

Cmd line:  O:\MyDir\MyOtherDir\UpdateMyProgram.bat
Working:   O:\MyDir\MyOtherDir
Batch File:  O:\MyDir\MyOtherDir\RunMyProgram.bat

And the Command window flashes, but the file is not copied over, and the .MDE does not run.

I'm confident of the syntax.  Also tried it with quotes.

Then I tried JUST copying the file over:

Cmd line:  O:\MyDir\MyOtherDir\UpdateMyProgram.bat
Working:   O:\MyDir\MyOtherDir
Batch File:

And the same thing (a milli-second flash of the Command window) occurs.

By the way, if I execute O:\MyDir\MyOtherDir\UpdateMyProgram.bat from Windows Explorer, the Command window stays open for a full 2 secongs, and the file is copied to the local drive.  Executing the shortcut that calls the same .BAT file fails.

Any ideas?

Thanks,
David
> the shortcut doesn't copy the new version of the file (from the network to the local drive) before executing the local copy.

That's strange. It works nicely at our clients.
The batch file should run initially - that's the purpose of it also according to the on-line help.

/gustav
Well, I didn't solve it, but I'm convinced that I'm doing something wrong, and I will continue to work on it.
Thanks to both
David