Restarting the Application

I know I’ve seen this somewhere here before but my searches couldn’t seem to find it.

My application has an option that allows the user to set some application configuration changes. One of them requires the program to shut down and restart. How do I tell the system (Windows) to restart the app? Right now, I am making the configuration change, setting a NeedsRestart property, and calling ‘Quit’. Then in the App.Close event, I’m checking the NeedsRestart property and if it is ‘True’ I do an

Dim f as FolderItem = App.ExecutableFile f.Launch
as the last statements. Is this the right way to do it or am I heading for trouble? If not right, what is the right way?

Here is the snipped from my code to restart the computer and restart the app. I wrote this years ago and hope they still work:

[code]case “Restart”
#if TargetMacOS then
script = "tell application ““System Events”” " + EndOfLine + “restart” + EndOfLine + “end tell” + EndOfLine
tempShell.execute “/usr/bin/osascript -e’” + script + “’”
#elseif TargetWin32 then
tempBoolean = ExitWindowsMBS(2)
'tempShell.Execute(“shutdown -r -t 0”) '
#elseif TargetLinux then
'Normally, the shutdown command is used and recommended for rebooting the system. This command can give Users advance warning so that they can save their work and cleanly terminating specific programs.
tempShell.execute “shutdown -r”

case “RestartApp”
#if not DebugBuild then
'This will launch a second copy of your application and quit the current one
'Whilst it will work on Windows I don’t believe it is xPlat
#if TargetConsole then
‘f.launch doesn’t work!
#elseif TargetWin32 or TargetLinux then
#elseif TargetMacOS then
‘script = "tell application ““System Events”” " + EndOfLine + “open -n '” + app.ExecutableFile.NativePath + "’ + EndOfLine + “end tell” + EndOfLine
‘tempShell.execute "/usr/bin/osascript -e’" + script + "’"
tempShell.execute "open -n " + app.ExecutableFile.ShellPath

[quote=478022:@Dale Arends]Dim f as FolderItem = App.ExecutableFile

You need to quit after f.launch.

That is how I do it when I update version.

[quote=478022:@Dale Arends]Dim f as FolderItem = App.ExecutableFile
Out of curiosity, I guess this approach is not compatible with using a Mutex to avoid multiple instances of your application since a new instance is launched before the current one is closed, right?

For a Windows project we created a helper app. The main app would start the helper app, then quit. The helper app scans the Task List until the main app is no longer showing (meaning it has quit according to the operating system) and then does a FolderItem.Launch of the main app exe and then the helper app quits.

It’s worked very well for this app since occasionally serial ports don’t like to open when the machine is first powered up. So if we can’t reach devices after a few tries we restart the app and try again.

I’ve also used a small helper as sometimes replacing a running EXE and dll’s with a new one cannot be done while that exe is loaded by the OS
A helper avoids that issue

Thanks, everyone. It looks like I’ll be leaving it like it is.

[quote=478114:@Michel Bujardet]You need to quit after f.launch.

That is how I do it when I update version.[/quote]
Why? The launch statement is the last statement in the App.Quit event handler.

True. In my case, the Mutex is cleared before the Launch is executed.

Not really, since by the time the application is launched, the launcher has quit.