Problem Replacing Folder

I can’t figure out what is going on with a problem I’m having launching a Windows application from a child folder.

I have an app in the folder RR2, and I want to run an app that will launch in the parent folder of RR2 that replaces the RR2 folder with a new one using the RNR2_Import.exe app I wrote.

See image:

On a Mac this is possible, but in Windows, you can’t replace a folder if the folder is being used by your running app.

So the idea was to run this separate program using the f.Launch code, and then shut down the main app in the folder that is being replaced. So the code I have for that is.

If TargetWin32 Then dim f as folderitem=getfolderitem("").parent.child("RNR2_Import.exe") Roster.Close //Roster is a database that I want to close. frmContents.Close //closes current window Quit //Quits application f.Launch Exit End If

When I run this code, my app closes down and starts the RNR2_Import.exe that is in the parent folder. But when I run that app, it does not replace the RR2 folder like it is supposed to do.

If I close out the RR2_Import.exe and restart it on its own from the Parent folder, the application replaces the RR2 folder just fine.

So, somehow I’m not closing the original app down correctly with the code above. Is there a way I can just kill the original app after it launches the RNR2_Import.exe app so it will work as if I ran it directly from the parent folder?

Good news James, just like on macOS, there is an Application folder on Windows where we are supposed to place our applications. Doing so avoid any of the troubles you have (read above).

Hi Emile,

On macOs you can install an app in the Applications folder, but you cannot write data to it. Apple made this change with Lion or Mountain Lion. You have to have a database in a writable part of the OS.

In my case, I don’t want to store the data in an ApplicationData folder. I want the user to have easy access to it. So the app is stored in a writable part of the OS in the Users/Public folder. That works well.

My problem is that the app launching the other app in the parent folder will not shut down completely so Windows thinks its still in use and the RR2 is not replaced.

Kem has live app updating/swapping working in Kaju, so I might look there for guidance.
Sorry I can’t be of more help.

You could have RNR2_Import.exe kill your application before attempting to replace it.

You can pass the name of the executable in arguments and then kill that process (or hard code it if you’d like).

taskkill /F /IM nameofyourapplication.exe

Thanks Tim. I saw that a few years ago and it looked great. Just did not figure out how it works. I will look at it again.

[quote=375207:@Jared Feder]You could have RNR2_Import.exe kill your application before attempting to replace it.

You can pass the name of the executable in arguments and then kill that process (or hard code it if you’d like).[/quote]

Hi Jared. When I hit Control, ALT, Delete and look at the Task Manager the app I want to close is not listed, so maybe it really is closed, but it still will not replace the folder. RNR2_Import.exe only works when I launch the app directly from the parent folder, by double-clicking on it.

I also don’t know how to launch the taskkill /F /IM nameofyourapplication.exe

That is a command that needs to be executed in a shell.

If you do end up going that route, you should remove Quit //Quits application from your method and allow the RNR2_Import.exe to kill the process in a shell.
By doing it that way, the synchronous nature of the shell.Execute command should ensure that the application has fully quit before your code to replace it gets executed.

Again, I just don’t know how to write that code.

Dim sh As New Shell sh.Execute(taskkill /F /IM Runs And Rosters 2.0.exe)

When you run this, you get taskkill does not exist, so I don’t know what the path is and if the syntax is correct.

[quote=375196:@James Redway]
Quit //Quits application
f.Launch[/quote]

I wouldn’t have expected this to work at all, regardless of the OS. Quit terminates the app, which means that f.Launch should never be reached. What happens if you reverse the order and call Quit last?

You wouldn’t think that it works, but it does for some reason. Also. placing the Quit command last still does not do anything. It still does not copy.

Even if I don’t put the Quit command in and close the app before running the code that replaces the folder, it still does not work. The only time it works is if I launch the RNR2_Import.exe app right from the folder by clicking on it. Then it works perfectly.

[quote=375218:@James Redway]Again, I just don’t know how to write that code.

Dim sh As New Shell sh.Execute(taskkill /F /IM Runs And Rosters 2.0.exe)

When you run this, you get taskkill does not exist, so I don’t know what the path is and if the syntax is correct.[/quote]

It just needs to be quoted properly.

dim sh as new Shell sh.Execute("taskkill /F /IM ""Runs And Rosters 2.0.exe""")

That was tested by replacing Runs And Rosters 2.0.exe with Chrome.exe in a Windows console application and it worked.

[quote=375226:@Jared Feder]dim sh as new Shell
sh.Execute(“taskkill /F /IM ““Runs And Rosters 2.0.exe”””)[/quote]

Hi Jared, Thank you for your help. I appreciate you helping me. That code did shut down the app, but when I run the RNR2_Import.exe it still does not replace the RR2 folder for some crazy reason.

I just can’t figure out why when you launch RNR2_Import.exe from an app and close down that app using the task kill code, that it will not replace the folder. Yet, when you run it by clicking the RNR2_Import.exe right from the folder it works fine.

Maybe, I’m just going to have to have the customers launch RNR2_Import.exe by itself. I was just trying to make it easier and seamless.

Might it help to delay any action in the Import program for 5 seconds or so via a timer to give the OS time to clean up file allocations?

Maybe I have misunderstood - I tend to do that then look a complete fool.

Try looking at this:
http://www.blackdiamond.co.za/TestCopy.zip

Find and run testa.exe, which should run testb.exe one folder up, which in turn should delete and replace testa.exe. I have not made the effort to do subfolders, and this is in RB under Win7/32. Maybe that will help.