From c67728f7c67f5b847d4d145aeaf62ba84a0258f2 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 17 Mar 2006 23:08:27 +0100 Subject: [PATCH] setupapi: Added support for calling executables in a RegisterDlls section. --- dlls/setupapi/install.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/dlls/setupapi/install.c b/dlls/setupapi/install.c index 4cdfdcf5356..43544da0396 100644 --- a/dlls/setupapi/install.c +++ b/dlls/setupapi/install.c @@ -444,6 +444,7 @@ static BOOL do_register_dll( const struct register_dll_info *info, const WCHAR * HMODULE module; HRESULT res; SP_REGISTER_CONTROL_STATUSW status; + IMAGE_NT_HEADERS *nt; status.cbSize = sizeof(status); status.FileName = path; @@ -473,6 +474,45 @@ static BOOL do_register_dll( const struct register_dll_info *info, const WCHAR * goto done; } + if ((nt = RtlImageNtHeader( module )) && !(nt->FileHeader.Characteristics & IMAGE_FILE_DLL)) + { + /* file is an executable, not a dll */ + STARTUPINFOW startup; + PROCESS_INFORMATION info; + WCHAR *cmd_line; + BOOL res; + static const WCHAR format[] = {'"','%','s','"',' ','%','s',0}; + static const WCHAR default_args[] = {'/','R','e','g','S','e','r','v','e','r',0}; + + FreeLibrary( module ); + module = NULL; + if (!args) args = default_args; + cmd_line = HeapAlloc( GetProcessHeap(), 0, (strlenW(path) + strlenW(args) + 4) * sizeof(WCHAR) ); + sprintfW( cmd_line, format, path, args ); + memset( &startup, 0, sizeof(startup) ); + startup.cb = sizeof(startup); + TRACE( "executing %s\n", debugstr_w(cmd_line) ); + res = CreateProcessW( NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info ); + HeapFree( GetProcessHeap(), 0, cmd_line ); + if (!res) + { + status.FailureCode = SPREG_LOADLIBRARY; + status.Win32Error = GetLastError(); + goto done; + } + CloseHandle( info.hThread ); + + if (WaitForSingleObject( info.hProcess, timeout*1000 ) == WAIT_TIMEOUT) + { + /* timed out, kill the process */ + TerminateProcess( info.hProcess, 1 ); + status.FailureCode = SPREG_TIMEOUT; + status.Win32Error = ERROR_TIMEOUT; + } + CloseHandle( info.hProcess ); + goto done; + } + if (flags & FLG_REGSVR_DLLREGISTER) { const char *entry_point = info->unregister ? "DllUnregisterServer" : "DllRegisterServer";