Results 1 to 4 of 4

Thread: Run Process without dependance

  1. #1
    Join Date
    Apr 2010
    Posts
    23
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Run Process without dependance

    Hey everybody,

    we are developing an updater for our software which is started by each of our products and updates all applications at once. We've nearly finished our updater, and it works perfectly fine if we run thge updaters exe directly, but the way we run the updater from within our products causes trouble.

    We're using a QProcess within the Product which starts the updater. The updater himself finds running products and terminates them via
    Qt Code:
    1. bool TerminateAppEnum(HWND hwnd, LPARAM lParam)
    2. {
    3. DWORD dwID ;
    4. GetWindowThreadProcessId(hwnd, &dwID) ;
    5. if(dwID == (DWORD)lParam)
    6. {
    7. PostMessage(hwnd, WM_CLOSE, 0, 0);
    8. PostMessage(hwnd, WM_QUIT, 0, 0);
    9. }
    10. return true;
    11. }
    To copy to clipboard, switch view to plain text mode 
    which was the only way we could find terminating the process safely without killing it.

    Now as soon as the updater termintes the product it was started from, the updater himself stops with the common windows-message saying that the application has run into a problem and needs to be stopped.

    Now we're shure that this is just because the product is listening to the updater process but we coundn't find a way, not even in WinAPI, that simply starts an exe file without any dependence to of from the product.

    The only way we've imagined, anthough we're not satisfied with it, was to dynamically write an batch-file with QFile running the updater with a single command and then run it with QProcess and terminate the process some seconds later and remove the file again.

    There must be a better way to do that and we really hope that you know a solution WinAPI or not, that could help us. Thanks in advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Run Process without dependance

    As far as I understand you, you want a single program that downloads and updates all your other programs, even when they are already running.

    If you start this updater from within any of your running programs, make sure you start it detached from the parent process. This prevents the updater from getting killed when you close all the other programs.

    You want to close the other programs gracefully so that data does not get lost.

    Instead of using the ugly windows API, why not make use of a local socket. Create a small local server that runs in the background. Start it whenever no server is available when you start one of your programs start. Then let the updater send a message to this local server to gracefully close all the running programs. You can even get feedback from running programs so all messages are displayed in the updater instead of showing multiple dialog boxes etc...

    You also might do something like a "suspend to memory" trick so you do not need to ask the user to save anything. You save the current session by yourself in some temporary file/folder. Then close the program, update it, start it again and load the saved session.

    Just some ideas of course.

  3. #3
    Join Date
    Apr 2010
    Posts
    23
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Run Process without dependance

    Thank you for your ideas! The local server is a good idea we also thought of, but we cuncluded that at the moments it's not necessary to have a seperate process running in the background all the time, that's why we came up with the solution of running the updater each time one of our applications starts. Therefore when starting the application there won't be any unsaved data to be stored.

    At the moment we only have two applications to be updated and we've added a possibility to update the updater itself, therefore we won't switch to the local server at the moment, but maybe do that in the future.

    As I found out the problem of the updater getting stuck is not the fact, that the parent process is terminated, but the termination itself. Here's the code we actually use to terminate the process, it worked fine on our developing system, but fails on two test-systems (Windows XP and 7):
    Qt Code:
    1. HANDLE hProc;
    2. hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE,pe32.th32ProcessID);
    3. EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM) pe32.th32ProcessID);
    4. if(WaitForSingleObject(hProc, 10000)!=WAIT_OBJECT_0) TerminateProcess(hProc,0);
    5. CloseHandle(hProc);
    To copy to clipboard, switch view to plain text mode 

    I hate the winAPI myself, but it was as I said the only way we cound find that didn't just kill the process but, if possible, waits for it to terminate himself. If you have know a different way to do this, I would be pleased to hear! Thanks!

  4. #4
    Join Date
    Sep 2010
    Posts
    145
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Run Process without dependance

    Your code assumes that the user account has full admin rights (sadly, very likely the case on the typical desktop). The way you've got your parent-child relationship setup with the processes is going to cause you trouble.
    solution of running the updater each time one of our applications starts
    This would require that all of your application suite have full rights, or the updater would not be able to aquire them. Instead you need the updater to be the parent process and launch the child processes with a restricted set of rights. It's simple really: Your updater just takes command line parameters that tell it which application to launch. (Using shortcuts, this is trivial to implement).

    What I've done is implement an invocation proxy that would sit between my parent and child processes. The updater takes command line parameters and sets up the environment for the proxy. The proxy uses the environment to invoc the child processes. I think this more closely resembles the unix ideology of implementation than your typical windows implemenrtation but it is surprisingly effective and very flexible (even more when you make the child processes polymorphic based on input from the proxy).

Similar Threads

  1. Determine the Process ID
    By Jimmy2775 in forum General Programming
    Replies: 5
    Last Post: 7th October 2011, 09:16
  2. Mutex between two or more process
    By bred in forum Qt Programming
    Replies: 4
    Last Post: 1st November 2010, 15:43
  3. how to process hexadecimal
    By mohanakrishnan in forum Qt Programming
    Replies: 2
    Last Post: 20th November 2009, 04:33
  4. How to communicate Qt Process with non-qt process
    By nrabara in forum Qt for Embedded and Mobile
    Replies: 9
    Last Post: 15th February 2009, 21:01
  5. Send a key to process
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2007, 17:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.