4 * Copyright 2004 Huw D M Davies
5 * Copyright 2005 Sami Aario
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(advpack
);
37 typedef HRESULT (WINAPI
*DLLREGISTER
) (void);
39 /***********************************************************************
40 * CloseINFEngine (ADVPACK.@)
42 * Closes a handle to an INF file opened with OpenINFEngine.
45 * hInf [I] Handle to the INF file to close.
54 HRESULT WINAPI
CloseINFEngine(HINF hInf
)
56 FIXME("(%p) stub\n", hInf
);
61 /***********************************************************************
64 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
66 TRACE("(%p, %ld, %p)\n",hinstDLL
, fdwReason
, lpvReserved
);
68 if (fdwReason
== DLL_PROCESS_ATTACH
)
69 DisableThreadLibraryCalls(hinstDLL
);
74 /***********************************************************************
75 * RunSetupCommand (ADVPACK.@)
77 * Executes an install section in an INF file or a program.
80 * hWnd [I] Handle to parent window, NULL for quiet mode
81 * szCmdName [I] Inf or EXE filename to execute
82 * szInfSection [I] Inf section to install, NULL for DefaultInstall
83 * szDir [I] Path to extracted files
84 * szTitle [I] Title of all dialogs
85 * phEXE [O] Handle of EXE to wait for
86 * dwFlags [I] Flags; see include/advpub.h
87 * pvReserved [I] Reserved
91 * S_ASYNCHRONOUS OK, required to wait on phEXE
92 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
93 * E_INVALIDARG Invalid argument given
94 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
95 * Not supported on this Windows version
96 * E_UNEXPECTED Unexpected error
97 * HRESULT_FROM_WIN32(GetLastError()) Some other error
102 HRESULT WINAPI
RunSetupCommand( HWND hWnd
, LPCSTR szCmdName
,
103 LPCSTR szInfSection
, LPCSTR szDir
,
104 LPCSTR lpszTitle
, HANDLE
*phEXE
,
105 DWORD dwFlags
, LPVOID pvReserved
)
107 FIXME("(%p, %s, %s, %s, %s, %p, 0x%08lx, %p): stub\n",
108 hWnd
, debugstr_a(szCmdName
), debugstr_a(szInfSection
),
109 debugstr_a(szDir
), debugstr_a(lpszTitle
),
110 phEXE
, dwFlags
, pvReserved
);
114 /***********************************************************************
115 * LaunchINFSection (ADVPACK.@)
117 * Installs an INF section without BACKUP/ROLLBACK capabilities.
120 * hWnd [I] Handle to parent window, NULL for desktop.
121 * hInst [I] Instance of the process.
122 * cmdline [I] Contains parameters in the order INF,section,flags.
123 * show [I] Reboot behaviour:
125 * 'I' default, reboot if needed
135 INT WINAPI
LaunchINFSection( HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
137 FIXME("(%p %p %s %d): stub\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
141 /***********************************************************************
142 * LaunchINFSectionEx (ADVPACK.@)
144 * Installs an INF section with BACKUP/ROLLBACK capabilities.
147 * hWnd [I] Handle to parent window, NULL for desktop.
148 * hInst [I] Instance of the process.
149 * cmdline [I] Contains parameters in the order INF,section,CAB,flags.
150 * show [I] Reboot behaviour:
152 * 'I' default, reboot if needed
162 HRESULT WINAPI
LaunchINFSectionEx( HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
164 FIXME("(%p %p %s %d): stub\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
168 /* this structure very closely resembles parameters of RunSetupCommand() */
176 } SETUPCOMMAND_PARAMS
;
178 /***********************************************************************
179 * DoInfInstall (ADVPACK.@)
181 * Install an INF section.
184 * setup [I] Structure containing install information.
188 * HRESULT_FROM_WIN32(GetLastError()) Some other error
190 HRESULT WINAPI
DoInfInstall(const SETUPCOMMAND_PARAMS
*setup
)
194 void *callback_context
;
196 TRACE("%p %s %s %s %s\n", setup
->hwnd
, debugstr_a(setup
->title
),
197 debugstr_a(setup
->inf_name
), debugstr_a(setup
->dir
),
198 debugstr_a(setup
->section_name
));
200 hinf
= SetupOpenInfFileA(setup
->inf_name
, NULL
, INF_STYLE_WIN4
, NULL
);
201 if (hinf
== INVALID_HANDLE_VALUE
) return HRESULT_FROM_WIN32(GetLastError());
203 callback_context
= SetupInitDefaultQueueCallback(setup
->hwnd
);
205 ret
= SetupInstallFromInfSectionA(NULL
, hinf
, setup
->section_name
, SPINST_ALL
,
206 NULL
, NULL
, 0, SetupDefaultQueueCallbackA
,
207 callback_context
, NULL
, NULL
);
208 SetupTermDefaultQueueCallback(callback_context
);
209 SetupCloseInfFile(hinf
);
211 return ret
? S_OK
: HRESULT_FROM_WIN32(GetLastError());
214 /***********************************************************************
215 * IsNTAdmin (ADVPACK.@)
217 * Checks if the user has admin privileges.
220 * reserved [I] Reserved. Must be 0.
221 * pReserved [I] Reserved. Must be NULL.
224 * TRUE if user has admin rights, FALSE otherwise.
226 BOOL WINAPI
IsNTAdmin( DWORD reserved
, LPDWORD pReserved
)
228 SID_IDENTIFIER_AUTHORITY SidAuthority
= {SECURITY_NT_AUTHORITY
};
229 PTOKEN_GROUPS pTokenGroups
;
230 BOOL bSidFound
= FALSE
;
235 TRACE("(0x%08lx, %p)\n", reserved
, pReserved
);
237 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
240 if (!GetTokenInformation(hToken
, TokenGroups
, NULL
, 0, &dwSize
))
242 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
249 pTokenGroups
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
256 if (!GetTokenInformation(hToken
, TokenGroups
, pTokenGroups
, dwSize
, &dwSize
))
258 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
265 if (!AllocateAndInitializeSid(&SidAuthority
, 2, SECURITY_BUILTIN_DOMAIN_RID
,
266 DOMAIN_ALIAS_RID_ADMINS
, 0, 0, 0, 0, 0, 0, &pSid
))
268 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
272 for (i
= 0; i
< pTokenGroups
->GroupCount
; i
++)
274 if (EqualSid(pSid
, pTokenGroups
->Groups
[i
].Sid
))
281 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
287 /***********************************************************************
288 * NeedRebootInit (ADVPACK.@)
290 * Sets up conditions for reboot checking.
293 * Value required by NeedReboot.
295 DWORD WINAPI
NeedRebootInit(VOID
)
301 /***********************************************************************
302 * NeedReboot (ADVPACK.@)
304 * Determines whether a reboot is required.
307 * dwRebootCheck [I] Value from NeedRebootInit.
310 * TRUE if a reboot is needed, FALSE otherwise.
315 BOOL WINAPI
NeedReboot(DWORD dwRebootCheck
)
317 FIXME("(0x%08lx): stub\n", dwRebootCheck
);
321 /***********************************************************************
322 * OpenINFEngine (ADVPACK.@)
324 * Opens and returns a handle to an INF file to be used by
325 * TranslateInfStringEx to continuously translate the INF file.
328 * pszInfFilename [I] Filename of the INF to open.
329 * pszInstallSection [I] Name of the Install section in the INF.
330 * dwFlags [I] See advpub.h.
331 * phInf [O] Handle to the loaded INF file.
332 * pvReserved [I] Reserved. Must be NULL.
341 HRESULT WINAPI
OpenINFEngine(PCSTR pszInfFilename
, PCSTR pszInstallSection
,
342 DWORD dwFlags
, HINF
*phInf
, PVOID pvReserved
)
344 FIXME("(%p, %p, %ld, %p, %p) stub\n", pszInfFilename
, pszInstallSection
,
345 dwFlags
, phInf
, pvReserved
);
350 /***********************************************************************
351 * RebootCheckOnInstall (ADVPACK.@)
353 * Checks if a reboot is required for an installed INF section.
356 * hWnd [I] Handle to the window used for messages.
357 * pszINF [I] Filename of the INF file.
358 * pszSec [I] INF section to check.
359 * dwReserved [I] Reserved. Must be 0.
362 * Success: S_OK - Reboot is needed if the INF section is installed.
363 * S_FALSE - Reboot is not needed.
364 * Failure: HRESULT of GetLastError().
367 * if pszSec is NULL, RebootCheckOnInstall checks the DefaultInstall
368 * or DefaultInstall.NT section.
373 HRESULT WINAPI
RebootCheckOnInstall(HWND hWnd
, LPCSTR pszINF
,
374 LPCSTR pszSec
, DWORD dwReserved
)
376 FIXME("(%p, %p, %p, %ld) stub\n", hWnd
, pszINF
, pszSec
, dwReserved
);
381 /***********************************************************************
382 * RegisterOCX (ADVPACK.@)
384 void WINAPI
RegisterOCX( HWND hWnd
, HINSTANCE hInst
, LPCSTR cmdline
, INT show
)
386 WCHAR wszBuff
[MAX_PATH
];
389 DLLREGISTER pfnRegister
;
392 TRACE("(%s)\n", cmdline
);
394 MultiByteToWideChar(CP_ACP
, 0, cmdline
, strlen(cmdline
), wszBuff
, MAX_PATH
);
395 if ((pwcComma
= strchrW( wszBuff
, ',' ))) *pwcComma
= 0;
397 TRACE("Parsed DLL name (%s)\n", debugstr_w(wszBuff
));
399 hm
= LoadLibraryExW(wszBuff
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
402 ERR("Couldn't load DLL: %s\n", debugstr_w(wszBuff
));
406 pfnRegister
= (DLLREGISTER
)GetProcAddress(hm
, "DllRegisterServer");
407 if (pfnRegister
== NULL
)
409 ERR("DllRegisterServer entry point not found\n");
416 ERR("DllRegisterServer entry point returned %08lx\n", hr
);
420 TRACE("Successfully registered OCX\n");
425 /***********************************************************************
426 * ExecuteCab (ADVPACK.@)
428 * Installs the INF file extracted from a specified cabinet file.
431 * hwnd [I] Handle to the window used for the display.
432 * pCab [I] Information about the cabinet file.
433 * pReserved [I] Reserved. Must be NULL.
442 HRESULT WINAPI
ExecuteCab( HWND hwnd
, PCABINFO pCab
, LPVOID pReserved
)
444 FIXME("(%p %p %p): stub\n", hwnd
, pCab
, pReserved
);
448 /***********************************************************************
449 * SetPerUserSecValues (ADVPACK.@)
451 * Prepares the per-user stub values under IsInstalled\{GUID} that
452 * control the per-user installation.
455 * pPerUser [I] Per-user stub values.
464 HRESULT WINAPI
SetPerUserSecValues(PPERUSERSECTION pPerUser
)
466 FIXME("(%p) stub\n", pPerUser
);
471 /***********************************************************************
472 * TranslateInfString (ADVPACK.@)
474 * Translates the value of a specified key in an inf file into the
475 * current locale by expanding string macros.
478 * pszInfFilename [I] Filename of the inf file.
479 * pszInstallSection [I]
480 * pszTranslateSection [I] Inf section where the key exists.
481 * pszTranslateKey [I] Key to translate.
482 * pszBuffer [O] Contains the translated string on exit.
483 * dwBufferSize [I] Size on input of pszBuffer.
484 * pdwRequiredSize [O] Length of the translated key.
485 * pvReserved [I] Reserved, must be NULL.
489 * Failure: An hresult error code.
491 HRESULT WINAPI
TranslateInfString(PCSTR pszInfFilename
, PCSTR pszInstallSection
,
492 PCSTR pszTranslateSection
, PCSTR pszTranslateKey
, PSTR pszBuffer
,
493 DWORD dwBufferSize
, PDWORD pdwRequiredSize
, PVOID pvReserved
)
497 TRACE("(%s %s %s %s %p %ld %p %p)\n",
498 debugstr_a(pszInfFilename
), debugstr_a(pszInstallSection
),
499 debugstr_a(pszTranslateSection
), debugstr_a(pszTranslateKey
),
500 pszBuffer
, dwBufferSize
,pdwRequiredSize
, pvReserved
);
502 if (!pszInfFilename
|| !pszTranslateSection
||
503 !pszTranslateKey
|| !pdwRequiredSize
)
506 hInf
= SetupOpenInfFileA(pszInfFilename
, NULL
, INF_STYLE_WIN4
, NULL
);
507 if (hInf
== INVALID_HANDLE_VALUE
)
508 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
510 if (!SetupGetLineTextA(NULL
, hInf
, pszTranslateSection
, pszTranslateKey
,
511 pszBuffer
, dwBufferSize
, pdwRequiredSize
))
513 if (dwBufferSize
< *pdwRequiredSize
)
514 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
516 return SPAPI_E_LINE_NOT_FOUND
;
522 /***********************************************************************
523 * TranslateInfStringEx (ADVPACK.@)
525 * Using a handle to an INF file opened with OpenINFEngine, translates
526 * the value of a specified key in an inf file into the current locale
527 * by expanding string macros.
530 * hInf [I] Handle to the INF file.
531 * pszInfFilename [I] Filename of the INF file.
532 * pszTranslateSection [I] Inf section where the key exists.
533 * pszTranslateKey [I] Key to translate.
534 * pszBuffer [O] Contains the translated string on exit.
535 * dwBufferSize [I] Size on input of pszBuffer.
536 * pdwRequiredSize [O] Length of the translated key.
537 * pvReserved [I] Reserved. Must be NULL.
544 * To use TranslateInfStringEx to translate an INF file continuously,
545 * open the INF file with OpenINFEngine, call TranslateInfStringEx as
546 * many times as needed, then release the handle with CloseINFEngine.
547 * When translating more than one keys, this method is more efficient
548 * than calling TranslateInfString, because the INF file is only
554 HRESULT WINAPI
TranslateInfStringEx(HINF hInf
, PCSTR pszInfFilename
,
555 PCSTR pszTranslateSection
, PCSTR pszTranslateKey
,
556 PSTR pszBuffer
, DWORD dwBufferSize
,
557 PDWORD pdwRequiredSize
, PVOID pvReserved
)
559 FIXME("(%p, %p, %p, %p, %p, %ld, %p, %p) stub\n", hInf
, pszInfFilename
,
560 pszTranslateSection
, pszTranslateKey
, pszBuffer
, dwBufferSize
,
561 pdwRequiredSize
, pvReserved
);
566 /***********************************************************************
567 * UserInstStubWrapper (ADVPACK.@)
569 HRESULT WINAPI
UserInstStubWrapper(HWND hWnd
, HINSTANCE hInstance
,
570 PSTR pszParms
, INT nShow
)
572 FIXME("(%p, %p, %p, %i) stub\n", hWnd
, hInstance
, pszParms
, nShow
);
577 /***********************************************************************
578 * UserUnInstStubWrapper (ADVPACK.@)
580 HRESULT WINAPI
UserUnInstStubWrapper(HWND hWnd
, HINSTANCE hInstance
,
581 PSTR pszParms
, INT nShow
)
583 FIXME("(%p, %p, %p, %i) stub\n", hWnd
, hInstance
, pszParms
, nShow
);