Creo haber conseguido con este código que acabo de alterar:
Code: Select all
HB_FUNC( SHELLEXECUTEEX )
{
DWORD code;
SHELLEXECUTEINFO SHExecInfo;
ZeroMemory(&SHExecInfo, sizeof(SHExecInfo));
SHExecInfo.cbSize = sizeof(SHExecInfo);
SHExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
SHExecInfo.hwnd = HB_ISNIL( 1 ) ? GetActiveWindow() : (HWND) HMG_parnl( 1 );
SHExecInfo.lpVerb = (LPCSTR) HMG_parc( 2 );
SHExecInfo.lpFile = (LPCSTR) HMG_parc( 3 );
SHExecInfo.lpParameters = (LPCSTR) HMG_parc( 4 );
SHExecInfo.lpDirectory = (LPCSTR) HMG_parc( 5 );
SHExecInfo.nShow = hb_parni( 6 );
if (ShellExecuteEx(&SHExecInfo) == FALSE || SHExecInfo.hProcess == NULL)
{
hb_retnl(-1);
}
WaitForSingleObject(SHExecInfo.hProcess, INFINITE);
if (GetExitCodeProcess(SHExecInfo.hProcess, &code) == 0)
{
hb_retnl(-1);
}
hb_retnl( (LONG) code );
}
Le saqué la funcion CoInitializeEx y coloqué SEE_MASK_NOCLOSEPROCESS para fMask. Como ya le habia puesto WaitForSingleObject/INFINITE y la funcion WaitForSingleObject, pienso que no habrá problemas ni necesidad de encerrar el proceso. Lo bueno que no tengo más que poner hb_IdleSleep para despues apagar el archivo vbs.
Lo único que está diferente es que me devuelve 0 (cero) cuando es ejecutado consuceso y diferente de cero cuando no ejecuta, sea por respuesta NO del UAC o por otra causa. Totalmente diferente del enunciado sobre GetExitCodeProcess. Pero debe ser porque adiconé al final del vbs script:
wscript.quit Err.number que me devuelve error cuando lo hay.
Interesante este mi aprendizaje. Nada mejor que aprender a los golpes...
Claudio si te parece válido hacer alguna observacion sobre mis cambios, bien venido será y buscaré testear tus sugerencias.
Gracias Claudio por tu atencion y ayuda.
Googled
I think I have gotten with this code that I have just altered:
<source code>
I took the CoInitializeEx function and placed SEE_MASK_NOCLOSEPROCESS for fMask. As I have already put WaitForSingleObject / INFINITE and the WaitForSingleObject function, I think there will be no problems or need to lock the process. The good thing I do not have to do is to put hb_IdleSleep to shut down the vbs file.
The only thing that is different is that it returns 0 (zero) when it is executed conspiracy and nonzero when it does not execute, either by NO response of the UAC or for another cause. Totally different from the GetExitCodeProcess statement. But it must be because I added at the end of the vbs script:
wscript.quit Err.number which returns me error when there is.
Interesting is my learning. Nothing better than learning thru the blows ...
Claudio if it seems valid to you to make some observation about my changes, well it will be and I will try to test your suggestions.
Thank you Claudio for your attention and help.