BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

restart application from within the application?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Hartmut Kloppert
Guest





PostPosted: Sat Dec 16, 2006 2:32 am    Post subject: restart application from within the application? Reply with quote



I'm using BCB4.
For some reason when a user has done some configuration changes I need
to restart the application. Instead of asking the user to terminate and restart,
is there a way to have it done automatically?

Thanks, Harry
Back to top
Bob
Guest





PostPosted: Sat Dec 16, 2006 4:05 am    Post subject: Re: restart application from within the application? Reply with quote



Hartmut Kloppert wrote:

Quote:
I'm using BCB4.
For some reason when a user has done some configuration changes I need
to restart the application. Instead of asking the user to terminate
and restart, is there a way to have it done automatically?

Thanks, Harry

Launch another program which waits for your original to exit, then
launches a copy of your original, before terminating itself.
Back to top
Clayton Arends
Guest





PostPosted: Sat Dec 16, 2006 4:21 am    Post subject: Re: restart application from within the application? Reply with quote



Another approach is to design your application so that configuration changes
don't require a restart. If you have a lot of registry/ini configuration
items then re-read them or read them on-the-fly as needed.

Do you have an example of some item in your app that would absolutely
require a restart?

- Clayton
Back to top
Hartmut Kloppert
Guest





PostPosted: Sat Dec 16, 2006 5:47 am    Post subject: Re: restart application from within the application? Reply with quote

You are absolutely right. A "clean" written application should be able
to do that. But what I have now is a complex thing and it crashes at
different places when I just restart it.... I tried to make it "cleaner"
but am looking for a "cheap" way to restart the whole thing from scratch.

"Clayton Arends" <nospam_claytonarends (AT) hotmail (DOT) com> wrote in message
news:45831fa4$1 (AT) newsgroups (DOT) borland.com...
Quote:
Another approach is to design your application so that configuration changes don't
require a restart. If you have a lot of registry/ini configuration items then re-read
them or read them on-the-fly as needed.

Do you have an example of some item in your app that would absolutely require a restart?

- Clayton
Back to top
Hartmut Kloppert
Guest





PostPosted: Sat Dec 16, 2006 6:34 am    Post subject: Re: restart application from within the application? Reply with quote

Hi Bob,

how would you code a (master)programm that waits for another to exit
and how to start a program from within the (master)programm?

"Bob" <nospam (AT) does (DOT) not.exist> wrote in message news:45831c2b$1 (AT) newsgroups (DOT) borland.com...
Quote:
Hartmut Kloppert wrote:

I'm using BCB4.
For some reason when a user has done some configuration changes I need
to restart the application. Instead of asking the user to terminate
and restart, is there a way to have it done automatically?

Thanks, Harry

Launch another program which waits for your original to exit, then
launches a copy of your original, before terminating itself.
Back to top
Bob Gonder
Guest





PostPosted: Sat Dec 16, 2006 9:10 am    Post subject: Re: restart application from within the application? Reply with quote

Hartmut Kloppert wrote:

Quote:
You are absolutely right. A "clean" written application should be able
to do that. But what I have now is a complex thing and it crashes at
different places when I just restart it.... I tried to make it "cleaner"
but am looking for a "cheap" way to restart the whole thing from scratch.

Is there something wrong with

ShellExecute( 0, "open", argv[0], 0, 0, SW_SHOWNORMAL);
exit();//equivelent for your app type

Or some varient thereof?
Back to top
Bob
Guest





PostPosted: Sat Dec 16, 2006 7:00 pm    Post subject: Re: restart application from within the application? Reply with quote

Hartmut Kloppert wrote:

Quote:
Hi Bob,

how would you code a (master)programm that waits for another to exit
and how to start a program from within the (master)programm?

"Bob" <nospam (AT) does (DOT) not.exist> wrote in message
news:45831c2b$1 (AT) newsgroups (DOT) borland.com...
Hartmut Kloppert wrote:

I'm using BCB4.
For some reason when a user has done some configuration changes I
need >> to restart the application. Instead of asking the user to
terminate >> and restart, is there a way to have it done
automatically?

Thanks, Harry

Launch another program which waits for your original to exit, then
launches a copy of your original, before terminating itself.


The waiting for your program to exit part depends on how your original
program works. Some options include;

1) A loop calling FindWindow() or FindWindowEx() until that function
returns NULL. Of course, you need some knowledge of your original
application (information on the windows class name and/or title) to do
that.

2) Your original program open a file and never close it: that
effectively keeps the file locked until the original program exits.
Then all your restarter program needs to do is loop until it
successfully opens that file. No need to write anything to the
file; only things to watch are ensuring the file is properly cleaned
up by both programs.

For restarting your original application, a call to something like
CreateProcess() or ShellExecute() will be fine.

Of course, all of this assumes your original application knows it needs
to restart, and doesn't otherwise terminate abnormally (in which case
it wouldn't launch the restarter, and therefore would not be restarted).
Back to top
yod
Guest





PostPosted: Mon Dec 18, 2006 10:09 pm    Post subject: Re: restart application from within the application? Reply with quote

Bob wrote:
Quote:
Hartmut Kloppert wrote:

Hi Bob,

how would you code a (master)programm that waits for another to exit
and how to start a program from within the (master)programm?

"Bob" <nospam (AT) does (DOT) not.exist> wrote in message
news:45831c2b$1 (AT) newsgroups (DOT) borland.com...
Hartmut Kloppert wrote:

I'm using BCB4.
For some reason when a user has done some configuration changes I
need >> to restart the application. Instead of asking the user to
terminate >> and restart, is there a way to have it done
automatically?

Thanks, Harry

Launch another program which waits for your original to exit, then
launches a copy of your original, before terminating itself.


The waiting for your program to exit part depends on how your original
program works. Some options include;

1) A loop calling FindWindow() or FindWindowEx() until that function
returns NULL. Of course, you need some knowledge of your original
application (information on the windows class name and/or title) to do
that.

2) Your original program open a file and never close it: that
effectively keeps the file locked until the original program exits.
Then all your restarter program needs to do is loop until it
successfully opens that file. No need to write anything to the
file; only things to watch are ensuring the file is properly cleaned
up by both programs.

For restarting your original application, a call to something like
CreateProcess() or ShellExecute() will be fine.

Of course, all of this assumes your original application knows it needs
to restart, and doesn't otherwise terminate abnormally (in which case
it wouldn't launch the restarter, and therefore would not be restarted).
Back to top
yod
Guest





PostPosted: Mon Dec 18, 2006 10:29 pm    Post subject: Re: restart application from within the application? Reply with quote

My code didn't show in the last reply.
Let me try again...

// This funtion does the restart using CreateProcess.
HANDLE MAIN_RestartApp(LPSTR szAppName)
{
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInformation;

StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.lpReserved = NULL;
StartupInfo.lpDesktop = NULL;
StartupInfo.lpTitle = NULL;
StartupInfo.dwX = 0;
StartupInfo.dwY = 0;
StartupInfo.dwXSize = 0;
StartupInfo.dwYSize = 0;
StartupInfo.dwXCountChars = 0;
StartupInfo.dwYCountChars = 0;
StartupInfo.dwFillAttribute = 0;
StartupInfo.dwFlags = 0;
StartupInfo.wShowWindow = 0;
StartupInfo.cbReserved2 = 0;
StartupInfo.lpReserved2 = NULL;
StartupInfo.hStdInput = 0;
StartupInfo.hStdOutput = 0;
StartupInfo.hStdError = 0;

if(CreateProcess( NULL, // pointer to name of executable module
szAppName, // pointer to command line string
NULL, // pointer to process security attributes
NULL, // pointer to thread security attributes
FALSE, // handle inheritance flag
NORMAL_PRIORITY_CLASS, // CREATE_DEFAULT_ERROR_MODE, //
creation flags
NULL, // pointer to new environment block
NULL, // pointer to current directory name
&StartupInfo, // pointer to STARTUPINFO
&ProcessInformation)) // pointer to PROCESS_INFORMATION
return (ProcessInformation.hProcess);

return NULL;
}

// This function supplys the app name
void MAIN_DoRestart( void)
{
char szAppName[MAX_PATH];

GetModuleFileName( NULL, szAppName, sizeof( szAppName));
Log( D_FUNC, "Restarting Application %s", szAppName);
for (;Wink // Retry until PostMessage works. It may fail because
the queue is full
{ // Use PostMessage because we don't want to wait
if (PostMessage( ghWnd, WM_COMMAND, IDCANCEL, 0))
break;
}
MAIN_RestartApp( szAppName);
}
}

Regards,
yod
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.