Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | // -=- LaunchProcess.h |
| 20 | |
| 21 | // Helper class to launch a names process from the same directory as |
| 22 | // the current process executable resides in. |
| 23 | |
| 24 | #ifndef __RFB_WIN32_LAUNCHPROCESS_H__ |
| 25 | #define __RFB_WIN32_LAUNCHPROCESS_H__ |
| 26 | |
| 27 | #include <windows.h> |
| 28 | #include <rfb_win32/TCharArray.h> |
| 29 | |
| 30 | namespace rfb { |
| 31 | |
| 32 | namespace win32 { |
| 33 | |
| 34 | class LaunchProcess { |
| 35 | public: |
| 36 | LaunchProcess(const TCHAR* exeName_, const TCHAR* params); |
| 37 | ~LaunchProcess(); |
| 38 | |
| 39 | // start() starts the specified process with the supplied |
| 40 | // command-line. |
| 41 | // If userToken is INVALID_HANDLE_VALUE then starts the process |
| 42 | // as the current user, otherwise as the specified user. |
| 43 | // If createConsole is true then CREATE_CONSOLE_WINDOW is passed |
| 44 | // as an extra flag to the process creation call. |
| 45 | void start(HANDLE userToken, bool createConsole=false); |
| 46 | |
| 47 | // Detatch from the child process. After detatching from a child |
| 48 | // process, no other methods should be called on the object |
| 49 | // that started it |
| 50 | void detach(); |
| 51 | |
| 52 | // Wait for the process to quit, up to the specified timeout, and |
| 53 | // close the handles to it once it has quit. |
| 54 | // If the process quits within the timeout then true is returned |
| 55 | // and returnCode is set. If it has not quit then false is returned. |
| 56 | // If an error occurs then an exception will be thrown. |
| 57 | bool await(DWORD timeoutMs=INFINITE); |
| 58 | |
| 59 | PROCESS_INFORMATION procInfo; |
| 60 | DWORD returnCode; |
| 61 | protected: |
| 62 | TCharArray exeName; |
| 63 | TCharArray params; |
| 64 | }; |
| 65 | |
| 66 | |
| 67 | }; |
| 68 | |
| 69 | }; |
| 70 | |
| 71 | #endif |