Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOS Batch File Issue

Status
Not open for further replies.

ajbufort

Programmer
Apr 4, 2004
50
US
Okay Guys,

I always stay on topic (Delphi-related) here, but after having scoured the forums for a DOS-specific area to post my question and not finding one, I am posting here. My app is written in Delphi, but that really has nothing to do with the question, so please have mercy on me. :)

I have written an application whose uninstaller eventually calls a .BAT file to help uninstall itself, as well as delete the directory the uninstall.exe was sitting in. For some reason, my rmdir command is failing to delete the directory. See code below:

Code:
:Repeat
    del "C:\Program Files\MM\Uninstall.exe"
    if exist "C:\Program Files\MM\Uninstall.exe" goto Repeat
    rmdir "C:\Program Files\MM"
    del "C:\fiUninst.bat";

Everything else is working, including the line right after rmdir. What could be preventing my script from deleting that folder? After uninstall.exe is successfully deleted, there's nothing left in the folder, so it can't be a straggler file that is preventing deletion. And the 'if exist' loop should guarantee that, by the time the batch file gets to the rmdir line, uninstall.exe is already gone.

I hope someone here has experience with this sort of thing, and will be able to help me out. Thanks.

-Tony
 
Just a guess, but I think it is a timing thing. Windows is reporting the deletion of the file, but it isn't really gone from the disk yet and so the folder isn't really empty.

Test it by breaking the .bat into two parts to allow a few seconds after the if exist and before the rmdir.

If running slowly allows it to behave correctly, then insert some time killer code to give it a chance. E.g. make a dummy copy of some other large file into the temp directory then delete the dummy copy.
 
Another thought, where "are" you when you run the batch file? (i.e., if you were at a DOS prompt, what would it look like?) If you (or any other program) are "in" the directory that you're trying to remove, it won't work. You have to be in a different folder in order for rmdir to work.

-D
 
Great input guys! Thanks. Here is where I am so far:

Zathras - I was thinking along exactly the lines you were, so I implemented a ping-based delay, like this:

Code:
:Repeat
    del "C:\Program Files\MegaMeeting\Uninstall.exe"
    if exist "C:\Program Files\MegaMeeting\Uninstall.exe" goto Repeat
    PING 1.1.1.1 -n 10 -w 1000 >NUL
    rmdir "C:\Program Files\MegaMeeting"
    del "C:\fiUninst.bat";

Unfortunately, it did not work. The delay worked, that is, but the folder still failed to be deleted afterwards.

hilfy - I was also considering this possibility, but thought it unlikely for the following reason - my batch file runs from C: (that is, the root). So the rmdir command is being issued by a batch file not in the MM folder. HOWEVER - I do launch the Uninstall.exe from within the MM folder, and it is that exe which runs the .BAT file. BUT, as I stated earlier, the .BAT waits until Uninstall.exe is done, and then tries to delete MM. That is why I moved on to the suspicion that Zathras and I shared.

-Tony
 
Hmmm. Works for me.

The del "C:\fiUninst.bat" threw an error "Batch file missing" when trying to find the next statement following the del "C:\fiUninst.bat" but otherwise it worked just fine. The MM folder was removed and the .bat file was deleted.

There's something else going on that you haven't told us about yet.
 
Zathras,

Which version of my fiUninst.bat were you using - the one with or without the ping delay? Whatever it was, it deleted the folder, huh? Hmmm. Well, let me review and see if I missed informing you guys about anything.

Okay, so I have an Uninstall.exe file that a user must click (within the MM folder) in order to uninstall the applications/files in the MM folder. It does this by deleting everything but itself and fiUninst.bat. After it has deleted everything else, Uninstall.exe moves fiUninst.bat to C:, and then executes it. So, as per the code I've posted, fiUninst.bat then waits for Uninstall.exe to terminate, and then deletes it and itself. The only thing failing to be done is the deletion of the MM folder.

-Tony

 
My test environment was more simplistic. I just had a folder with an .exe in it and the .bat file in C:
Perhaps the .exe is still in the stack while the .bat is running. How are you kicking off the .bat file?

Maybe if you create the .bat file "on the fly" instead of copying it?

Yes, I was using the one with the Ping in it.
 
Hi,

Okay: We all know that someone cannot currently be 'using' the directory one is trying to delete in order to be able to delete it, correct? But "not currently using" does not include having it open in Windows explorer, right? Because I know I can delete a folder in a DOS window and have an open explorer window disappear on deletion. But the user DOES have to double-click on the Uninstaller.exe in the MM folder in order to begin the uninstall process. So could it be that, even though my fiUninst.bat script is the one issuing the rmdir command, that command still does not work because the user just clicked on Uninstall.exe a few seconds ago and the MM window still HAS FOCUS?

-Tony
 
Okay, there's definitely something deeper going on here. Zathras, your theory that "Perhaps the .exe is still in the stack while the .bat is running" is one I need to check out. I have ruled out that it has anything to do with the explorer window being open or having the focus, as I have tried Uninstall from the DOS command line with no window open and it still fails to delete MM. Now that does not mean that windows does not like that I am in the folder in the first place. But it does rule out some things.

In answer to your previous question, I am using the following lines to move and then launch fiUninst.bat:

Code:
// Move fiUninst.bat file to C:

MoveFile('fiUninst.bat','C:\fiUninst.bat');

// Execute fiUninst

ShellExecute(0, 'open', pchar('C:\fiUninst.bat'), nil, nil, SW_NORMAL);

-Tony
 
Okay, here's the official scoop:

"
C:\Program Files\MegaMeeting>rmdir "C:\Program Files\MegaMeeting"

The process cannot access the file because it is being used by another process.
"

So there you have it. For some reason, even though my Uninstall.exe has finished running, Windows still thinks the folder is actively being used. Now how do i convince it otherwise?

-tony
 
FORGET IT - I found the problem. After I delete Uninstall.exe, I am still in the Program Files/MM folder!! So being in that folder obviously prevents me from deleting it later in my .BAT file.

Wow - sorry for the wild goose chase fellas!

-Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top