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.@)
53 HRESULT WINAPI
CloseINFEngine(HINF hInf
)
55 FIXME("(%p) stub\n", hInf
);
60 /***********************************************************************
63 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
65 TRACE("(%p, %ld, %p)\n",hinstDLL
, fdwReason
, lpvReserved
);
67 if (fdwReason
== DLL_PROCESS_ATTACH
)
68 DisableThreadLibraryCalls(hinstDLL
);
73 /***********************************************************************
74 * RunSetupCommand (ADVPACK.@)
76 * Executes an install section in an INF file or a program.
79 * hWnd [I] Handle to parent window, NULL for quiet mode
80 * szCmdName [I] Inf or EXE filename to execute
81 * szInfSection [I] Inf section to install, NULL for DefaultInstall
82 * szDir [I] Path to extracted files
83 * szTitle [I] Title of all dialogs
84 * phEXE [O] Handle of EXE to wait for
85 * dwFlags [I] Flags; see include/advpub.h
86 * pvReserved [I] Reserved
90 * S_ASYNCHRONOUS OK, required to wait on phEXE
91 * ERROR_SUCCESS_REBOOT_REQUIRED Reboot required
92 * E_INVALIDARG Invalid argument given
93 * HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)
94 * Not supported on this Windows version
95 * E_UNEXPECTED Unexpected error
96 * HRESULT_FROM_WIN32(GetLastError()) Some other error
101 HRESULT WINAPI
RunSetupCommand( HWND hWnd
, LPCSTR szCmdName
,
102 LPCSTR szInfSection
, LPCSTR szDir
,
103 LPCSTR lpszTitle
, HANDLE
*phEXE
,
104 DWORD dwFlags
, LPVOID pvReserved
)
106 FIXME("(%p, %s, %s, %s, %s, %p, 0x%08lx, %p): stub\n",
107 hWnd
, debugstr_a(szCmdName
), debugstr_a(szInfSection
),
108 debugstr_a(szDir
), debugstr_a(lpszTitle
),
109 phEXE
, dwFlags
, pvReserved
);
113 /***********************************************************************
114 * LaunchINFSection (ADVPACK.@)
116 * Installs an INF section without BACKUP/ROLLBACK capabilities.
119 * hWnd [I] Handle to parent window, NULL for desktop.
120 * hInst [I] Instance of the process.
121 * cmdline [I] Contains parameters in the order INF,section,flags.
122 * show [I] Reboot behaviour:
124 * 'I' default, reboot if needed
134 INT WINAPI
LaunchINFSection( HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
136 FIXME("(%p %p %s %d): stub\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
140 /***********************************************************************
141 * LaunchINFSectionEx (ADVPACK.@)
143 * Installs an INF section with BACKUP/ROLLBACK capabilities.
146 * hWnd [I] Handle to parent window, NULL for desktop.
147 * hInst [I] Instance of the process.
148 * cmdline [I] Contains parameters in the order INF,section,CAB,flags.
149 * show [I] Reboot behaviour:
151 * 'I' default, reboot if needed
161 HRESULT WINAPI
LaunchINFSectionEx( HWND hWnd
, HINSTANCE hInst
, LPSTR cmdline
, INT show
)
163 FIXME("(%p %p %s %d): stub\n", hWnd
, hInst
, debugstr_a(cmdline
), show
);
167 /* this structure very closely resembles parameters of RunSetupCommand() */
175 } SETUPCOMMAND_PARAMS
;
177 /***********************************************************************
178 * DoInfInstall (ADVPACK.@)
180 * Install an INF section.
183 * setup [I] Structure containing install information.
187 * HRESULT_FROM_WIN32(GetLastError()) Some other error
189 HRESULT WINAPI
DoInfInstall(const SETUPCOMMAND_PARAMS
*setup
)
193 void *callback_context
;
195 TRACE("%p %s %s %s %s\n", setup
->hwnd
, debugstr_a(setup
->title
),
196 debugstr_a(setup
->inf_name
), debugstr_a(setup
->dir
),
197 debugstr_a(setup
->section_name
));
199 hinf
= SetupOpenInfFileA(setup
->inf_name
, NULL
, INF_STYLE_WIN4
, NULL
);
200 if (hinf
== INVALID_HANDLE_VALUE
) return HRESULT_FROM_WIN32(GetLastError());
202 callback_context
= SetupInitDefaultQueueCallback(setup
->hwnd
);
204 ret
= SetupInstallFromInfSectionA(NULL
, hinf
, setup
->section_name
, SPINST_ALL
,
205 NULL
, NULL
, 0, SetupDefaultQueueCallbackA
,
206 callback_context
, NULL
, NULL
);
207 SetupTermDefaultQueueCallback(callback_context
);
208 SetupCloseInfFile(hinf
);
210 return ret
? S_OK
: HRESULT_FROM_WIN32(GetLastError());
213 /***********************************************************************
214 * IsNTAdmin (ADVPACK.@)
216 * Checks if the user has admin privileges.
219 * reserved [I] Reserved. Must be 0.
220 * pReserved [I] Reserved. Must be NULL.
223 * TRUE if user has admin rights, FALSE otherwise.
225 BOOL WINAPI
IsNTAdmin( DWORD reserved
, LPDWORD pReserved
)
227 SID_IDENTIFIER_AUTHORITY SidAuthority
= {SECURITY_NT_AUTHORITY
};
228 PTOKEN_GROUPS pTokenGroups
;
229 BOOL bSidFound
= FALSE
;
234 TRACE("(0x%08lx, %p)\n", reserved
, pReserved
);
236 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
))
239 if (!GetTokenInformation(hToken
, TokenGroups
, NULL
, 0, &dwSize
))
241 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
248 pTokenGroups
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
255 if (!GetTokenInformation(hToken
, TokenGroups
, pTokenGroups
, dwSize
, &dwSize
))
257 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
264 if (!AllocateAndInitializeSid(&SidAuthority
, 2, SECURITY_BUILTIN_DOMAIN_RID
,
265 DOMAIN_ALIAS_RID_ADMINS
, 0, 0, 0, 0, 0, 0, &pSid
))
267 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
271 for (i
= 0; i
< pTokenGroups
->GroupCount
; i
++)
273 if (EqualSid(pSid
, pTokenGroups
->Groups
[i
].Sid
))
280 HeapFree(GetProcessHeap(), 0, pTokenGroups
);
286 /***********************************************************************
287 * NeedRebootInit (ADVPACK.@)
289 * Sets up conditions for reboot checking.
292 * Value required by NeedReboot.
294 DWORD WINAPI
NeedRebootInit(VOID
)
300 /***********************************************************************
301 * NeedReboot (ADVPACK.@)
303 * Determines whether a reboot is required.
306 * dwRebootCheck [I] Value from NeedRebootInit.
309 * TRUE if a reboot is needed, FALSE otherwise.
314 BOOL WINAPI
NeedReboot(DWORD dwRebootCheck
)
316 FIXME("(0x%08lx): stub\n", dwRebootCheck
);
320 /***********************************************************************
321 * OpenINFEngine (ADVPACK.@)
323 * Opens and returns a handle to an INF file to be used by
324 * TranslateInfStringEx to continuously translate the INF file.
327 * pszInfFilename [I] Filename of the INF to open.
328 * pszInstallSection [I] Name of the Install section in the INF.
329 * dwFlags [I] See advpub.h.
330 * phInf [O] Handle to the loaded INF file.
331 * pvReserved [I] Reserved. Must be NULL.
340 HRESULT WINAPI
OpenINFEngine(PCSTR pszInfFilename
, PCSTR pszInstallSection
,
341 DWORD dwFlags
, HINF
*phInf
, PVOID pvReserved
)
343 FIXME("(%p, %p, %ld, %p, %p) stub\n", pszInfFilename
, pszInstallSection
,
344 dwFlags
, phInf
, pvReserved
);
349 /***********************************************************************
350 * RegisterOCX (ADVPACK.@)
352 void WINAPI
RegisterOCX( HWND hWnd
, HINSTANCE hInst
, LPCSTR cmdline
, INT show
)
354 WCHAR wszBuff
[MAX_PATH
];
357 DLLREGISTER pfnRegister
;
360 TRACE("(%s)\n", cmdline
);
362 MultiByteToWideChar(CP_ACP
, 0, cmdline
, strlen(cmdline
), wszBuff
, MAX_PATH
);
363 if ((pwcComma
= strchrW( wszBuff
, ',' ))) *pwcComma
= 0;
365 TRACE("Parsed DLL name (%s)\n", debugstr_w(wszBuff
));
367 hm
= LoadLibraryExW(wszBuff
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
);
370 ERR("Couldn't load DLL: %s\n", debugstr_w(wszBuff
));
374 pfnRegister
= (DLLREGISTER
)GetProcAddress(hm
, "DllRegisterServer");
375 if (pfnRegister
== NULL
)
377 ERR("DllRegisterServer entry point not found\n");
384 ERR("DllRegisterServer entry point returned %08lx\n", hr
);
388 TRACE("Successfully registered OCX\n");
393 /***********************************************************************
394 * ExecuteCab (ADVPACK.@)
396 * Installs the INF file extracted from a specified cabinet file.
399 * hwnd [I] Handle to the window used for the display.
400 * pCab [I] Information about the cabinet file.
401 * pReserved [I] Reserved. Must be NULL.
410 HRESULT WINAPI
ExecuteCab( HWND hwnd
, PCABINFO pCab
, LPVOID pReserved
)
412 FIXME("(%p %p %p): stub\n", hwnd
, pCab
, pReserved
);
416 /***********************************************************************
417 * SetPerUserSecValues (ADVPACK.@)
419 * Prepares the per-user stub values under IsInstalled\{GUID} that
420 * control the per-user installation.
423 * pPerUser [I] Per-user stub values.
432 HRESULT WINAPI
SetPerUserSecValues(PPERUSERSECTION pPerUser
)
434 FIXME("(%p) stub\n", pPerUser
);
439 /***********************************************************************
440 * TranslateInfString (ADVPACK.@)
442 * Translates the value of a specified key in an inf file into the
443 * current locale by expanding string macros.
446 * pszInfFilename [I] Filename of the inf file.
447 * pszInstallSection [I]
448 * pszTranslateSection [I] Inf section where the key exists.
449 * pszTranslateKey [I] Key to translate.
450 * pszBuffer [O] Contains the translated string on exit.
451 * dwBufferSize [I] Size on input of pszBuffer.
452 * pdwRequiredSize [O] Length of the translated key.
453 * pvReserved [I] Reserved, must be NULL.
457 * Failure: An hresult error code.
459 HRESULT WINAPI
TranslateInfString(PCSTR pszInfFilename
, PCSTR pszInstallSection
,
460 PCSTR pszTranslateSection
, PCSTR pszTranslateKey
, PSTR pszBuffer
,
461 DWORD dwBufferSize
, PDWORD pdwRequiredSize
, PVOID pvReserved
)
465 TRACE("(%s %s %s %s %p %ld %p %p)\n",
466 debugstr_a(pszInfFilename
), debugstr_a(pszInstallSection
),
467 debugstr_a(pszTranslateSection
), debugstr_a(pszTranslateKey
),
468 pszBuffer
, dwBufferSize
,pdwRequiredSize
, pvReserved
);
470 if (!pszInfFilename
|| !pszTranslateSection
||
471 !pszTranslateKey
|| !pdwRequiredSize
)
474 hInf
= SetupOpenInfFileA(pszInfFilename
, NULL
, INF_STYLE_WIN4
, NULL
);
475 if (hInf
== INVALID_HANDLE_VALUE
)
476 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
478 if (!SetupGetLineTextA(NULL
, hInf
, pszTranslateSection
, pszTranslateKey
,
479 pszBuffer
, dwBufferSize
, pdwRequiredSize
))
481 if (dwBufferSize
< *pdwRequiredSize
)
482 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
484 return SPAPI_E_LINE_NOT_FOUND
;
490 /***********************************************************************
491 * TranslateInfStringEx (ADVPACK.@)
493 * Using a handle to an INF file opened with OpenINFEngine, translates
494 * the value of a specified key in an inf file into the current locale
495 * by expanding string macros.
498 * hInf [I] Handle to the INF file.
499 * pszInfFilename [I] Filename of the INF file.
500 * pszTranslateSection [I] Inf section where the key exists.
501 * pszTranslateKey [I] Key to translate.
502 * pszBuffer [O] Contains the translated string on exit.
503 * dwBufferSize [I] Size on input of pszBuffer.
504 * pdwRequiredSize [O] Length of the translated key.
505 * pvReserved [I] Reserved. Must be NULL.
512 * To use TranslateInfStringEx to translate an INF file continuously,
513 * open the INF file with OpenINFEngine, call TranslateInfStringEx as
514 * many times as needed, then release the handle with CloseINFEngine.
515 * When translating more than one keys, this method is more efficient
516 * than calling TranslateInfString, because the INF file is only
522 HRESULT WINAPI
TranslateInfStringEx(HINF hInf
, PCSTR pszInfFilename
,
523 PCSTR pszTranslateSection
, PCSTR pszTranslateKey
,
524 PSTR pszBuffer
, DWORD dwBufferSize
,
525 PDWORD pdwRequiredSize
, PVOID pvReserved
)
527 FIXME("(%p, %p, %p, %p, %p, %ld, %p, %p) stub\n", hInf
, pszInfFilename
,
528 pszTranslateSection
, pszTranslateKey
, pszBuffer
, dwBufferSize
,
529 pdwRequiredSize
, pvReserved
);
534 /***********************************************************************
535 * UserInstStubWrapper (ADVPACK.@)
537 HRESULT WINAPI
UserInstStubWrapper(HWND hWnd
, HINSTANCE hInstance
,
538 PSTR pszParms
, INT nShow
)
540 FIXME("(%p, %p, %p, %i) stub\n", hWnd
, hInstance
, pszParms
, nShow
);
545 /***********************************************************************
546 * UserUnInstStubWrapper (ADVPACK.@)
548 HRESULT WINAPI
UserUnInstStubWrapper(HWND hWnd
, HINSTANCE hInstance
,
549 PSTR pszParms
, INT nShow
)
551 FIXME("(%p, %p, %p, %i) stub\n", hWnd
, hInstance
, pszParms
, nShow
);