Показать сообщение отдельно
Старый 20.04.2004, 11:10   #2  
db is offline
db
Роман Долгополов (RDOL)
Лучший по профессии 2015
Лучший по профессии AXAWARD 2013
 
393 / 692 (24) +++++++
Регистрация: 01.04.2004
Адрес: Москва
Приделай куда-нибудь этот метод и счастье наступит
Параметры:

1. командная строка
2. сколько миллисекунд ждать завершения (-1 ждать вечно)
3. режим отображения окна (нормальное, максимизированое, свернутое).

PHP код:
static void shellExecuteWait(str commandLineint _waitTime = -1int cmdShow 4)
{
    
#WinAPI
    #DEFINE.STATUS_TIMEOUT(0x00000102)

    
Dll             kernel32            = new Dll("kernel32.dll");
    
DllFunction     createProcess       = new DllFunction(kernel32"CreateProcessA");
    
DllFunction     waitForSingleObject = new DllFunction(kernel32"WaitForSingleObject");
    
DllFunction     closeHandle         = new DllFunction(kernel32"CloseHandle");
    
DllFunction     terminateProcess    = new DllFunction(kernel32"TerminateProcess");
    
Binary          strartupInformation = new binary(68);
    
Binary          processInformation  = new binary(16);

    
int             hProcess;

    
createProcess.returns(ExtTypes:: DWORD);
    
createProcess.arg(ExtTypes:: DWORDExtTypes:: STRING,
                      
ExtTypes:: DWORDExtTypes:: DWORD,
                      
ExtTypes:: DWORDExtTypes:: DWORD,
                      
ExtTypes:: DWORDExtTypes:: DWORD,
                      
ExtTypes:: POINTERExtTypes:: POINTER);

    
waitForSingleObject.returns(ExtTypes:: DWORD);
    
waitForSingleObject.arg(ExtTypes:: DWORDExtTypes:: DWORD);

    
closeHandle.returns(ExtTypes:: DWORD);
    
closeHandle.arg(ExtTypes:: DWORD);

    
terminateProcess.returns(ExtTypes:: DWord);
    
terminateProcess.arg(ExtTypes:: DWordExtTypes:: DWord);

    
strartupInformation.dWord(44cmdShow);

    if (!
createProcess.call(0commandLine000000strartupInformationprocessInformation))
    {
        throw 
error(strfmt("Ошибка при запуске приложения \"%1\""commandLine));
    }

    
hProcess processInformation.dWord(0);

    if (
waitForSingleObject.call(hProcess_waitTime) == #STATUS_TIMEOUT)
    
{
        
terminateProcess.call(hProcess1);
        throw 
error(strfmt("Приложение \"%1\" закрыто, так как не завершилось за отведенное ему время"commandLine));
    }

    
closeHandle.call(hProcess);

За это сообщение автора поблагодарили: aidsua (1).