Thread: Restarting a Program (via restarting process or making new one)

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    16

    Restarting a Program (via restarting process or making new one)

    I am using Visual Studio. I have a program which calls a function that can fail (Bluetooth initialization, closed source). If this certain function fails, then I'll need to restart the process. I found this way to do it from MSDN:

    WinExec("filename.exe", SW_SHOW);

    However, I believe this is a Windows library function. It works, but the .exe filename can change sometimes. I know there is a __FILE__ macro predefined, but this only gets the source file of the main(). What is a better way to restart the process without needing to know the .exe ?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That sounds a bit broken in itself. Can't you just release all resources and let your application start over within itself. Surely there is no need to close the app down and start again?

    There are windows specific API calls that will get you the process's executable name. Search the forum for "get name of executable" and I'm sure you can find a relevant post within a few seconds - I can't remember what it is.

    And no there, is no __FILE__ corresponding that gives you the executable file - and what happens when the user renames your "foo.exe" to "bar.exe"?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    WinExec is there for compatibility with really old programs (think pre-Win95). Don't use it. Use ShellExecute or CreateProcess.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-21-2008, 02:07 AM
  2. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  3. C program for Inter Process communication ( Tx and RX)
    By hiharsh in forum C Programming
    Replies: 3
    Last Post: 05-03-2007, 10:23 AM
  4. Help making Program Better/More Effecient
    By toonlover in forum C++ Programming
    Replies: 14
    Last Post: 04-29-2006, 11:40 PM
  5. Making a cgi program!!!
    By dapernia in forum C Programming
    Replies: 3
    Last Post: 09-02-2003, 10:17 PM