Hi all,
I've spent quite a few hours on this and haven't got anywhere. I'm writing a service application that executes Excel at some point (Excel will quit by itself after some processing due to it's macros). I want the Excel window to be hidden unless it takes too long to do it's processing, at which point it's window should be shown, and presumably the reason for it's hanging will be obvious. I can't manage to get the Excel window showing under any circumstances. I'm using this standard procedure:
and am calling it with
The 60000 is a timeout of 60 seconds, I handle this elsewhere.
That should work I thought. The service is logged in as a domain user, not the LocalSystem (has to be this way), so I don't have the opportunity to click the Interact with Desktop option in the service settings. The Interactive property in the TService object is set to True.
Maybe I have to attach the excel process to a visible window or something? like explorer.exe? I really don't know which direction I should be looking in next.
Thanks for your help!
I've spent quite a few hours on this and haven't got anywhere. I'm writing a service application that executes Excel at some point (Excel will quit by itself after some processing due to it's macros). I want the Excel window to be hidden unless it takes too long to do it's processing, at which point it's window should be shown, and presumably the reason for it's hanging will be obvious. I can't manage to get the Excel window showing under any circumstances. I'm using this standard procedure:
Code:
[b]function[/b] WinExecAndWait32(FileName: [b]string[/b]; Visibility: Integer;
TimeOut: Integer; [b]var[/b] Signal: Integer): dWord;
[b]var[/b]
zAppName: [b]array[/b][[purple]0..512[/purple]] [b]of[/b] Char;
zCurDir: [b]array[/b][[purple]0..255[/purple]] [b]of[/b] Char;
WorkDir: [b]string[/b];
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
[b]procedure[/b] ExecuteProcess;
[b]begin[/b]
Signal := WaitforSingleObject(ProcessInfo.hProcess, TimeOut);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
[b]end[/b];
[b]begin[/b]
StrPCopy(zAppName, FileName);
GetDir([purple]0[/purple], WorkDir);
StrPCopy(zCurDir, WorkDir);
FillChar(StartupInfo, Sizeof(StartupInfo), [teal]#0[/teal]);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
[b]if[/b] [b]not[/b] CreateProcess([b]nil[/b],
zAppName, [navy][i]{ pointer to command line string }[/i][/navy]
[b]nil[/b], [navy][i]{ pointer to process security attributes }[/i][/navy]
[b]nil[/b], [navy][i]{ pointer to thread security attributes }[/i][/navy]
false, [navy][i]{ handle inheritance flag }[/i][/navy]
CREATE_NEW_CONSOLE [b]or[/b] [navy][i]{ creation flags }[/i][/navy]
NORMAL_PRIORITY_CLASS,
[b]nil[/b], [navy][i]{ pointer to new environment block }[/i][/navy]
[b]nil[/b], [navy][i]{ pointer to current directory name }[/i][/navy]
StartupInfo, [navy][i]{ pointer to STARTUPINFO }[/i][/navy]
ProcessInfo) [b]then[/b]
Result := [purple]0[/purple] [navy][i]{ pointer to PROCESS_INF }[/i][/navy]
[b]else[/b]
ExecuteProcess;
[b]end[/b];
and am calling it with
Code:
WinExecAndWait32([teal]'"'[/teal] + FOfficeDir + [teal]'excel.exe" /r "blah.xls"'[/teal], SW_SHOWNORMAL, [purple]60000[/purple], m)
The 60000 is a timeout of 60 seconds, I handle this elsewhere.
That should work I thought. The service is logged in as a domain user, not the LocalSystem (has to be this way), so I don't have the opportunity to click the Interact with Desktop option in the service settings. The Interactive property in the TService object is set to True.
Maybe I have to attach the excel process to a visible window or something? like explorer.exe? I really don't know which direction I should be looking in next.
Thanks for your help!