2 * Setupapi install routines
4 * Copyright 2002 Alexandre Julliard for CodeWeavers
5 * 2005 Hervé Poussineau (hpoussin@reactos.org)
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
22 #include "setupapi_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
26 /* info passed to callback functions dealing with files */
27 struct files_callback_info
35 /* info passed to callback functions dealing with the registry */
36 struct registry_callback_info
42 /* info passed to callback functions dealing with registering dlls */
43 struct register_dll_info
45 PSP_FILE_CALLBACK_W callback
;
46 PVOID callback_context
;
50 /* info passed to callback functions dealing with Needs directives */
51 struct needs_callback_info
63 PSP_DEVINFO_DATA devinfo_data
;
68 typedef BOOL (*iterate_fields_func
)( HINF hinf
, PCWSTR field
, void *arg
);
70 /* Unicode constants */
71 static const WCHAR AddService
[] = {'A','d','d','S','e','r','v','i','c','e',0};
72 static const WCHAR CopyFiles
[] = {'C','o','p','y','F','i','l','e','s',0};
73 static const WCHAR DelFiles
[] = {'D','e','l','F','i','l','e','s',0};
74 static const WCHAR RenFiles
[] = {'R','e','n','F','i','l','e','s',0};
75 static const WCHAR Ini2Reg
[] = {'I','n','i','2','R','e','g',0};
76 static const WCHAR LogConf
[] = {'L','o','g','C','o','n','f',0};
77 static const WCHAR AddReg
[] = {'A','d','d','R','e','g',0};
78 static const WCHAR DelReg
[] = {'D','e','l','R','e','g',0};
79 static const WCHAR BitReg
[] = {'B','i','t','R','e','g',0};
80 static const WCHAR UpdateInis
[] = {'U','p','d','a','t','e','I','n','i','s',0};
81 static const WCHAR CopyINF
[] = {'C','o','p','y','I','N','F',0};
82 static const WCHAR UpdateIniFields
[] = {'U','p','d','a','t','e','I','n','i','F','i','e','l','d','s',0};
83 static const WCHAR RegisterDlls
[] = {'R','e','g','i','s','t','e','r','D','l','l','s',0};
84 static const WCHAR UnregisterDlls
[] = {'U','n','r','e','g','i','s','t','e','r','D','l','l','s',0};
85 static const WCHAR ProfileItems
[] = {'P','r','o','f','i','l','e','I','t','e','m','s',0};
86 static const WCHAR Include
[] = {'I','n','c','l','u','d','e',0};
87 static const WCHAR Needs
[] = {'N','e','e','d','s',0};
90 /***********************************************************************
93 * Retrieve the contents of a field, dynamically growing the buffer if necessary.
95 static WCHAR
*get_field_string( INFCONTEXT
*context
, DWORD index
, WCHAR
*buffer
,
96 WCHAR
*static_buffer
, DWORD
*size
)
100 if (SetupGetStringFieldW( context
, index
, buffer
, *size
, &required
)) return buffer
;
101 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
103 /* now grow the buffer */
104 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
105 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, required
*sizeof(WCHAR
) ))) return NULL
;
107 if (SetupGetStringFieldW( context
, index
, buffer
, *size
, &required
)) return buffer
;
109 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
114 /***********************************************************************
115 * copy_files_callback
117 * Called once for each CopyFiles entry in a given section.
119 static BOOL
copy_files_callback( HINF hinf
, PCWSTR field
, void *arg
)
121 struct files_callback_info
*info
= arg
;
123 if (field
[0] == '@') /* special case: copy single file */
124 SetupQueueDefaultCopyW( info
->queue
, info
->layout
, info
->src_root
, NULL
, field
, info
->copy_flags
);
126 SetupQueueCopySectionW( info
->queue
, info
->src_root
, info
->layout
, hinf
, field
, info
->copy_flags
);
131 /***********************************************************************
132 * delete_files_callback
134 * Called once for each DelFiles entry in a given section.
136 static BOOL
delete_files_callback( HINF hinf
, PCWSTR field
, void *arg
)
138 struct files_callback_info
*info
= arg
;
139 SetupQueueDeleteSectionW( info
->queue
, hinf
, 0, field
);
144 /***********************************************************************
145 * rename_files_callback
147 * Called once for each RenFiles entry in a given section.
149 static BOOL
rename_files_callback( HINF hinf
, PCWSTR field
, void *arg
)
151 struct files_callback_info
*info
= arg
;
152 SetupQueueRenameSectionW( info
->queue
, hinf
, 0, field
);
157 /***********************************************************************
160 * Retrieve the registry root key from its name.
162 static HKEY
get_root_key( const WCHAR
*name
, HKEY def_root
)
164 static const WCHAR HKCR
[] = {'H','K','C','R',0};
165 static const WCHAR HKCU
[] = {'H','K','C','U',0};
166 static const WCHAR HKLM
[] = {'H','K','L','M',0};
167 static const WCHAR HKU
[] = {'H','K','U',0};
168 static const WCHAR HKR
[] = {'H','K','R',0};
170 if (!strcmpiW( name
, HKCR
)) return HKEY_CLASSES_ROOT
;
171 if (!strcmpiW( name
, HKCU
)) return HKEY_CURRENT_USER
;
172 if (!strcmpiW( name
, HKLM
)) return HKEY_LOCAL_MACHINE
;
173 if (!strcmpiW( name
, HKU
)) return HKEY_USERS
;
174 if (!strcmpiW( name
, HKR
)) return def_root
;
179 /***********************************************************************
180 * append_multi_sz_value
182 * Append a multisz string to a multisz registry value.
184 static void append_multi_sz_value( HKEY hkey
, const WCHAR
*value
, const WCHAR
*strings
,
187 DWORD size
, type
, total
;
190 if (RegQueryValueExW( hkey
, value
, NULL
, &type
, NULL
, &size
)) return;
191 if (type
!= REG_MULTI_SZ
) return;
193 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (size
+ str_size
) * sizeof(WCHAR
) ))) return;
194 if (RegQueryValueExW( hkey
, value
, NULL
, NULL
, (BYTE
*)buffer
, &size
)) goto done
;
196 /* compare each string against all the existing ones */
200 int len
= strlenW(strings
) + 1;
202 for (p
= buffer
; *p
; p
+= strlenW(p
) + 1)
203 if (!strcmpiW( p
, strings
)) break;
205 if (!*p
) /* not found, need to append it */
207 memcpy( p
, strings
, len
* sizeof(WCHAR
) );
215 TRACE( "setting value %s to %s\n", debugstr_w(value
), debugstr_w(buffer
) );
216 RegSetValueExW( hkey
, value
, 0, REG_MULTI_SZ
, (BYTE
*)buffer
, total
);
219 HeapFree( GetProcessHeap(), 0, buffer
);
223 /***********************************************************************
224 * delete_multi_sz_value
226 * Remove a string from a multisz registry value.
228 static void delete_multi_sz_value( HKEY hkey
, const WCHAR
*value
, const WCHAR
*string
)
231 WCHAR
*buffer
, *src
, *dst
;
233 if (RegQueryValueExW( hkey
, value
, NULL
, &type
, NULL
, &size
)) return;
234 if (type
!= REG_MULTI_SZ
) return;
235 /* allocate double the size, one for value before and one for after */
236 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
* 2 * sizeof(WCHAR
) ))) return;
237 if (RegQueryValueExW( hkey
, value
, NULL
, NULL
, (BYTE
*)buffer
, &size
)) goto done
;
242 int len
= strlenW(src
) + 1;
243 if (strcmpiW( src
, string
))
245 memcpy( dst
, src
, len
* sizeof(WCHAR
) );
251 if (dst
!= buffer
+ 2*size
) /* did we remove something? */
253 TRACE( "setting value %s to %s\n", debugstr_w(value
), debugstr_w(buffer
+ size
) );
254 RegSetValueExW( hkey
, value
, 0, REG_MULTI_SZ
,
255 (BYTE
*)(buffer
+ size
), dst
- (buffer
+ size
) );
258 HeapFree( GetProcessHeap(), 0, buffer
);
262 /***********************************************************************
265 * Perform an add/delete registry operation depending on the flags.
267 static BOOL
do_reg_operation( HKEY hkey
, const WCHAR
*value
, INFCONTEXT
*context
, INT flags
)
271 if (flags
& (FLG_ADDREG_DELREG_BIT
| FLG_ADDREG_DELVAL
)) /* deletion */
273 if (*value
&& !(flags
& FLG_DELREG_KEYONLY_COMMON
))
275 if ((flags
& FLG_DELREG_MULTI_SZ_DELSTRING
) == FLG_DELREG_MULTI_SZ_DELSTRING
)
279 if (!SetupGetStringFieldW( context
, 5, NULL
, 0, &size
) || !size
) return TRUE
;
280 if (!(str
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) return FALSE
;
281 SetupGetStringFieldW( context
, 5, str
, size
, NULL
);
282 delete_multi_sz_value( hkey
, value
, str
);
283 HeapFree( GetProcessHeap(), 0, str
);
285 else RegDeleteValueW( hkey
, value
);
287 else RegDeleteKeyW( hkey
, NULL
);
291 if (flags
& (FLG_ADDREG_KEYONLY
|FLG_ADDREG_KEYONLY_COMMON
)) return TRUE
;
293 if (flags
& (FLG_ADDREG_NOCLOBBER
|FLG_ADDREG_OVERWRITEONLY
))
295 BOOL exists
= !RegQueryValueExW( hkey
, value
, NULL
, NULL
, NULL
, NULL
);
296 if (exists
&& (flags
& FLG_ADDREG_NOCLOBBER
)) return TRUE
;
297 if (!exists
& (flags
& FLG_ADDREG_OVERWRITEONLY
)) return TRUE
;
300 switch(flags
& FLG_ADDREG_TYPE_MASK
)
302 case FLG_ADDREG_TYPE_SZ
: type
= REG_SZ
; break;
303 case FLG_ADDREG_TYPE_MULTI_SZ
: type
= REG_MULTI_SZ
; break;
304 case FLG_ADDREG_TYPE_EXPAND_SZ
: type
= REG_EXPAND_SZ
; break;
305 case FLG_ADDREG_TYPE_BINARY
: type
= REG_BINARY
; break;
306 case FLG_ADDREG_TYPE_DWORD
: type
= REG_DWORD
; break;
307 case FLG_ADDREG_TYPE_NONE
: type
= REG_NONE
; break;
308 default: type
= flags
>> 16; break;
311 if (!(flags
& FLG_ADDREG_BINVALUETYPE
) ||
312 (type
== REG_DWORD
&& SetupGetFieldCount(context
) == 5))
314 static const WCHAR empty
;
317 if (type
== REG_MULTI_SZ
)
319 if (!SetupGetMultiSzFieldW( context
, 5, NULL
, 0, &size
)) size
= 0;
322 if (!(str
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) return FALSE
;
323 SetupGetMultiSzFieldW( context
, 5, str
, size
, NULL
);
325 if (flags
& FLG_ADDREG_APPEND
)
327 if (!str
) return TRUE
;
328 append_multi_sz_value( hkey
, value
, str
, size
);
329 HeapFree( GetProcessHeap(), 0, str
);
332 /* else fall through to normal string handling */
336 if (!SetupGetStringFieldW( context
, 5, NULL
, 0, &size
)) size
= 0;
339 if (!(str
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) return FALSE
;
340 SetupGetStringFieldW( context
, 5, str
, size
, NULL
);
344 if (type
== REG_DWORD
)
346 DWORD dw
= str
? strtoulW( str
, NULL
, 0 ) : 0;
347 TRACE( "setting dword %s to %lx\n", debugstr_w(value
), dw
);
348 RegSetValueExW( hkey
, value
, 0, type
, (BYTE
*)&dw
, sizeof(dw
) );
352 TRACE( "setting value %s to %s\n", debugstr_w(value
), debugstr_w(str
) );
353 if (str
) RegSetValueExW( hkey
, value
, 0, type
, (BYTE
*)str
, size
* sizeof(WCHAR
) );
354 else RegSetValueExW( hkey
, value
, 0, type
, (const BYTE
*)&empty
, sizeof(WCHAR
) );
356 HeapFree( GetProcessHeap(), 0, str
);
359 else /* get the binary data */
363 if (!SetupGetBinaryField( context
, 5, NULL
, 0, &size
)) size
= 0;
366 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
367 TRACE( "setting binary data %s len %ld\n", debugstr_w(value
), size
);
368 SetupGetBinaryField( context
, 5, data
, size
, NULL
);
370 RegSetValueExW( hkey
, value
, 0, type
, data
, size
);
371 HeapFree( GetProcessHeap(), 0, data
);
377 /***********************************************************************
380 * Called once for each AddReg and DelReg entry in a given section.
382 static BOOL
registry_callback( HINF hinf
, PCWSTR field
, void *arg
)
384 struct registry_callback_info
*info
= arg
;
388 BOOL ok
= SetupFindFirstLineW( hinf
, field
, NULL
, &context
);
390 for (; ok
; ok
= SetupFindNextLine( &context
, &context
))
392 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
396 if (!SetupGetStringFieldW( &context
, 1, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
398 if (!(root_key
= get_root_key( buffer
, info
->default_root
)))
402 if (!SetupGetStringFieldW( &context
, 2, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
406 if (!SetupGetIntField( &context
, 4, &flags
)) flags
= 0;
410 if (flags
& FLG_ADDREG_DELREG_BIT
) continue; /* ignore this entry */
414 if (!flags
) flags
= FLG_ADDREG_DELREG_BIT
;
415 else if (!(flags
& FLG_ADDREG_DELREG_BIT
)) continue; /* ignore this entry */
418 if (info
->delete || (flags
& FLG_ADDREG_OVERWRITEONLY
))
420 if (RegOpenKeyW( root_key
, buffer
, &hkey
)) continue; /* ignore if it doesn't exist */
422 else if (RegCreateKeyW( root_key
, buffer
, &hkey
))
424 ERR( "could not create key %p %s\n", root_key
, debugstr_w(buffer
) );
427 TRACE( "key %p %s\n", root_key
, debugstr_w(buffer
) );
430 if (!SetupGetStringFieldW( &context
, 3, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
434 if (!do_reg_operation( hkey
, buffer
, &context
, flags
))
445 /***********************************************************************
448 * Register or unregister a dll.
450 static BOOL
do_register_dll( const struct register_dll_info
*info
, const WCHAR
*path
,
451 INT flags
, INT timeout
, const WCHAR
*args
)
455 SP_REGISTER_CONTROL_STATUSW status
;
457 status
.cbSize
= sizeof(status
);
458 status
.FileName
= path
;
459 status
.FailureCode
= SPREG_SUCCESS
;
460 status
.Win32Error
= ERROR_SUCCESS
;
464 switch(info
->callback( info
->callback_context
, SPFILENOTIFY_STARTREGISTRATION
,
465 (UINT_PTR
)&status
, !info
->unregister
))
468 SetLastError( ERROR_OPERATION_ABORTED
);
477 if (!(module
= LoadLibraryExW( path
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
)))
479 WARN( "could not load %s\n", debugstr_w(path
) );
480 status
.FailureCode
= SPREG_LOADLIBRARY
;
481 status
.Win32Error
= GetLastError();
485 if (flags
& FLG_REGSVR_DLLREGISTER
)
487 const char *entry_point
= info
->unregister
? "DllUnregisterServer" : "DllRegisterServer";
488 HRESULT (WINAPI
*func
)(void) = (void *)GetProcAddress( module
, entry_point
);
492 status
.FailureCode
= SPREG_GETPROCADDR
;
493 status
.Win32Error
= GetLastError();
497 TRACE( "calling %s in %s\n", entry_point
, debugstr_w(path
) );
502 WARN( "calling %s in %s returned error %lx\n", entry_point
, debugstr_w(path
), res
);
503 status
.FailureCode
= SPREG_REGSVR
;
504 status
.Win32Error
= res
;
509 if (flags
& FLG_REGSVR_DLLINSTALL
)
511 HRESULT (WINAPI
*func
)(BOOL
,LPCWSTR
) = (void *)GetProcAddress( module
, "DllInstall" );
515 status
.FailureCode
= SPREG_GETPROCADDR
;
516 status
.Win32Error
= GetLastError();
520 TRACE( "calling DllInstall(%d,%s) in %s\n",
521 !info
->unregister
, debugstr_w(args
), debugstr_w(path
) );
522 res
= func( !info
->unregister
, args
);
526 WARN( "calling DllInstall in %s returned error %lx\n", debugstr_w(path
), res
);
527 status
.FailureCode
= SPREG_REGSVR
;
528 status
.Win32Error
= res
;
534 if (module
) FreeLibrary( module
);
535 if (info
->callback
) info
->callback( info
->callback_context
, SPFILENOTIFY_ENDREGISTRATION
,
536 (UINT_PTR
)&status
, !info
->unregister
);
541 /***********************************************************************
542 * register_dlls_callback
544 * Called once for each RegisterDlls entry in a given section.
546 static BOOL
register_dlls_callback( HINF hinf
, PCWSTR field
, void *arg
)
548 struct register_dll_info
*info
= arg
;
551 BOOL ok
= SetupFindFirstLineW( hinf
, field
, NULL
, &context
);
553 for (; ok
; ok
= SetupFindNextLine( &context
, &context
))
555 WCHAR
*path
, *args
, *p
;
556 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
560 if (!(path
= PARSER_get_dest_dir( &context
))) continue;
563 if (!SetupGetStringFieldW( &context
, 3, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
565 if (!(p
= HeapReAlloc( GetProcessHeap(), 0, path
,
566 (strlenW(path
) + strlenW(buffer
) + 2) * sizeof(WCHAR
) ))) goto done
;
569 if (p
== path
|| p
[-1] != '\\') *p
++ = '\\';
570 strcpyW( p
, buffer
);
573 if (!SetupGetIntField( &context
, 4, &flags
)) flags
= 0;
576 if (!SetupGetIntField( &context
, 5, &timeout
)) timeout
= 60;
578 /* get command line */
580 if (SetupGetStringFieldW( &context
, 6, buffer
, sizeof(buffer
)/sizeof(WCHAR
), NULL
))
583 ret
= do_register_dll( info
, path
, flags
, timeout
, args
);
586 HeapFree( GetProcessHeap(), 0, path
);
592 /***********************************************************************
593 * update_ini_callback
595 * Called once for each UpdateInis entry in a given section.
597 static BOOL
update_ini_callback( HINF hinf
, PCWSTR field
, void *arg
)
601 BOOL ok
= SetupFindFirstLineW( hinf
, field
, NULL
, &context
);
603 for (; ok
; ok
= SetupFindNextLine( &context
, &context
))
605 WCHAR buffer
[MAX_INF_STRING_LENGTH
];
606 WCHAR filename
[MAX_INF_STRING_LENGTH
];
607 WCHAR section
[MAX_INF_STRING_LENGTH
];
608 WCHAR entry
[MAX_INF_STRING_LENGTH
];
609 WCHAR string
[MAX_INF_STRING_LENGTH
];
612 if (!SetupGetStringFieldW( &context
, 1, filename
,
613 sizeof(filename
)/sizeof(WCHAR
), NULL
))
616 if (!SetupGetStringFieldW( &context
, 2, section
,
617 sizeof(section
)/sizeof(WCHAR
), NULL
))
620 if (!SetupGetStringFieldW( &context
, 4, buffer
,
621 sizeof(buffer
)/sizeof(WCHAR
), NULL
))
624 divider
= strchrW(buffer
,'=');
628 strcpyW(entry
,buffer
);
630 strcpyW(string
,divider
);
634 strcpyW(entry
,buffer
);
638 TRACE("Writing %s = %s in %s of file %s\n",debugstr_w(entry
),
639 debugstr_w(string
),debugstr_w(section
),debugstr_w(filename
));
640 WritePrivateProfileStringW(section
,entry
,string
,filename
);
646 static BOOL
update_ini_fields_callback( HINF hinf
, PCWSTR field
, void *arg
)
648 FIXME( "should update ini fields %s\n", debugstr_w(field
) );
652 static BOOL
ini2reg_callback( HINF hinf
, PCWSTR field
, void *arg
)
654 FIXME( "should do ini2reg %s\n", debugstr_w(field
) );
658 static BOOL
logconf_callback( HINF hinf
, PCWSTR field
, void *arg
)
660 FIXME( "should do logconf %s\n", debugstr_w(field
) );
664 static BOOL
bitreg_callback( HINF hinf
, PCWSTR field
, void *arg
)
666 FIXME( "should do bitreg %s\n", debugstr_w(field
) );
670 static BOOL
profile_items_callback( HINF hinf
, PCWSTR field
, void *arg
)
672 FIXME( "should do profile items %s\n", debugstr_w(field
) );
676 static BOOL
copy_inf_callback( HINF hinf
, PCWSTR field
, void *arg
)
678 FIXME( "should do copy inf %s\n", debugstr_w(field
) );
683 /***********************************************************************
684 * iterate_section_fields
686 * Iterate over all fields of a certain key of a certain section
688 static BOOL
iterate_section_fields( HINF hinf
, PCWSTR section
, PCWSTR key
,
689 iterate_fields_func callback
, void *arg
)
691 WCHAR static_buffer
[200];
692 WCHAR
*buffer
= static_buffer
;
693 DWORD size
= sizeof(static_buffer
)/sizeof(WCHAR
);
697 BOOL ok
= SetupFindFirstLineW( hinf
, section
, key
, &context
);
700 UINT i
, count
= SetupGetFieldCount( &context
);
701 for (i
= 1; i
<= count
; i
++)
703 if (!(buffer
= get_field_string( &context
, i
, buffer
, static_buffer
, &size
)))
705 if (!callback( hinf
, buffer
, arg
))
707 WARN("callback failed for %s %s err %ld\n",
708 debugstr_w(section
), debugstr_w(buffer
), GetLastError() );
712 ok
= SetupFindNextMatchLineW( &context
, key
, &context
);
716 if (buffer
&& buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
721 /***********************************************************************
722 * SetupInstallFilesFromInfSectionA (SETUPAPI.@)
724 BOOL WINAPI
SetupInstallFilesFromInfSectionA( HINF hinf
, HINF hlayout
, HSPFILEQ queue
,
725 PCSTR section
, PCSTR src_root
, UINT flags
)
727 UNICODE_STRING sectionW
;
730 if (!RtlCreateUnicodeStringFromAsciiz( §ionW
, section
))
732 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
736 ret
= SetupInstallFilesFromInfSectionW( hinf
, hlayout
, queue
, sectionW
.Buffer
,
741 if (RtlCreateUnicodeStringFromAsciiz( &srcW
, src_root
))
743 ret
= SetupInstallFilesFromInfSectionW( hinf
, hlayout
, queue
, sectionW
.Buffer
,
744 srcW
.Buffer
, flags
);
745 RtlFreeUnicodeString( &srcW
);
747 else SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
749 RtlFreeUnicodeString( §ionW
);
754 /***********************************************************************
755 * SetupInstallFilesFromInfSectionW (SETUPAPI.@)
757 BOOL WINAPI
SetupInstallFilesFromInfSectionW( HINF hinf
, HINF hlayout
, HSPFILEQ queue
,
758 PCWSTR section
, PCWSTR src_root
, UINT flags
)
760 struct files_callback_info info
;
763 info
.src_root
= src_root
;
764 info
.copy_flags
= flags
;
765 info
.layout
= hlayout
;
766 return iterate_section_fields( hinf
, section
, CopyFiles
, copy_files_callback
, &info
);
770 /***********************************************************************
771 * SetupInstallFromInfSectionA (SETUPAPI.@)
773 BOOL WINAPI
SetupInstallFromInfSectionA( HWND owner
, HINF hinf
, PCSTR section
, UINT flags
,
774 HKEY key_root
, PCSTR src_root
, UINT copy_flags
,
775 PSP_FILE_CALLBACK_A callback
, PVOID context
,
776 HDEVINFO devinfo
, PSP_DEVINFO_DATA devinfo_data
)
778 UNICODE_STRING sectionW
, src_rootW
;
779 struct callback_WtoA_context ctx
;
782 src_rootW
.Buffer
= NULL
;
783 if (src_root
&& !RtlCreateUnicodeStringFromAsciiz( &src_rootW
, src_root
))
785 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
789 if (RtlCreateUnicodeStringFromAsciiz( §ionW
, section
))
791 ctx
.orig_context
= context
;
792 ctx
.orig_handler
= callback
;
793 ret
= SetupInstallFromInfSectionW( owner
, hinf
, sectionW
.Buffer
, flags
, key_root
,
794 src_rootW
.Buffer
, copy_flags
, QUEUE_callback_WtoA
,
795 &ctx
, devinfo
, devinfo_data
);
796 RtlFreeUnicodeString( §ionW
);
798 else SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
800 RtlFreeUnicodeString( &src_rootW
);
805 /***********************************************************************
808 * Called once for each Include entry in a given section.
810 static BOOL
include_callback( HINF hinf
, PCWSTR field
, void *arg
)
812 return SetupOpenAppendInfFileW( field
, hinf
, NULL
);
816 /***********************************************************************
819 * Called once for each Needs entry in a given section.
821 static BOOL
needs_callback( HINF hinf
, PCWSTR field
, void *arg
)
823 struct needs_callback_info
*info
= arg
;
828 return SetupInstallFromInfSectionW(info
->owner
, hinf
, field
, info
->flags
,
829 info
->key_root
, info
->src_root
, info
->copy_flags
, info
->callback
,
830 info
->context
, info
->devinfo
, info
->devinfo_data
);
832 return SetupInstallServicesFromInfSectionExW(hinf
, field
, info
->flags
,
833 info
->devinfo
, info
->devinfo_data
, info
->reserved1
, info
->reserved2
);
835 ERR("Unknown info type %ld\n", info
->type
);
841 /***********************************************************************
842 * SetupInstallFromInfSectionW (SETUPAPI.@)
844 BOOL WINAPI
SetupInstallFromInfSectionW( HWND owner
, HINF hinf
, PCWSTR section
, UINT flags
,
845 HKEY key_root
, PCWSTR src_root
, UINT copy_flags
,
846 PSP_FILE_CALLBACK_W callback
, PVOID context
,
847 HDEVINFO devinfo
, PSP_DEVINFO_DATA devinfo_data
)
849 struct needs_callback_info needs_info
;
851 /* Parse 'Include' and 'Needs' directives */
852 iterate_section_fields( hinf
, section
, Include
, include_callback
, NULL
);
854 needs_info
.owner
= owner
;
855 needs_info
.flags
= flags
;
856 needs_info
.key_root
= key_root
;
857 needs_info
.src_root
= src_root
;
858 needs_info
.copy_flags
= copy_flags
;
859 needs_info
.callback
= callback
;
860 needs_info
.context
= context
;
861 needs_info
.devinfo
= devinfo
;
862 needs_info
.devinfo_data
= devinfo_data
;
863 iterate_section_fields( hinf
, section
, Needs
, needs_callback
, &needs_info
);
865 if (flags
& SPINST_FILES
)
867 struct files_callback_info info
;
871 if (!(queue
= SetupOpenFileQueue())) return FALSE
;
873 info
.src_root
= src_root
;
874 info
.copy_flags
= copy_flags
;
876 ret
= (iterate_section_fields( hinf
, section
, CopyFiles
, copy_files_callback
, &info
) &&
877 iterate_section_fields( hinf
, section
, DelFiles
, delete_files_callback
, &info
) &&
878 iterate_section_fields( hinf
, section
, RenFiles
, rename_files_callback
, &info
) &&
879 SetupCommitFileQueueW( owner
, queue
, callback
, context
));
880 SetupCloseFileQueue( queue
);
881 if (!ret
) return FALSE
;
883 if (flags
& SPINST_INIFILES
)
885 if (!iterate_section_fields( hinf
, section
, UpdateInis
, update_ini_callback
, NULL
) ||
886 !iterate_section_fields( hinf
, section
, UpdateIniFields
,
887 update_ini_fields_callback
, NULL
))
890 if (flags
& SPINST_INI2REG
)
892 if (!iterate_section_fields( hinf
, section
, Ini2Reg
, ini2reg_callback
, NULL
))
895 if (flags
& SPINST_LOGCONFIG
)
897 if (!iterate_section_fields( hinf
, section
, LogConf
, logconf_callback
, NULL
))
900 if (flags
& SPINST_REGSVR
)
902 struct register_dll_info info
;
904 info
.unregister
= FALSE
;
905 if (flags
& SPINST_REGISTERCALLBACKAWARE
)
907 info
.callback
= callback
;
908 info
.callback_context
= context
;
910 else info
.callback
= NULL
;
912 if (!iterate_section_fields( hinf
, section
, RegisterDlls
, register_dlls_callback
, &info
))
915 if (flags
& SPINST_UNREGSVR
)
917 struct register_dll_info info
;
919 info
.unregister
= TRUE
;
920 if (flags
& SPINST_REGISTERCALLBACKAWARE
)
922 info
.callback
= callback
;
923 info
.callback_context
= context
;
925 else info
.callback
= NULL
;
927 if (!iterate_section_fields( hinf
, section
, UnregisterDlls
, register_dlls_callback
, &info
))
930 if (flags
& SPINST_REGISTRY
)
932 struct registry_callback_info info
;
934 info
.default_root
= key_root
;
936 if (!iterate_section_fields( hinf
, section
, DelReg
, registry_callback
, &info
))
939 if (!iterate_section_fields( hinf
, section
, AddReg
, registry_callback
, &info
))
942 if (flags
& SPINST_BITREG
)
944 if (!iterate_section_fields( hinf
, section
, BitReg
, bitreg_callback
, NULL
))
947 if (flags
& SPINST_PROFILEITEMS
)
949 if (!iterate_section_fields( hinf
, section
, ProfileItems
, profile_items_callback
, NULL
))
952 if (flags
& SPINST_COPYINF
)
954 if (!iterate_section_fields( hinf
, section
, CopyINF
, copy_inf_callback
, NULL
))
962 /***********************************************************************
963 * InstallHinfSectionW (SETUPAPI.@)
965 * NOTE: 'cmdline' is <section> <mode> <path> from
966 * RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection <section> <mode> <path>
968 void WINAPI
InstallHinfSectionW( HWND hwnd
, HINSTANCE handle
, LPCWSTR cmdline
, INT show
)
970 WCHAR
*p
, *path
, section
[MAX_PATH
];
971 void *callback_context
;
975 TRACE("hwnd %p, handle %p, cmdline %s\n", hwnd
, handle
, debugstr_w(cmdline
));
977 lstrcpynW( section
, cmdline
, sizeof(section
)/sizeof(WCHAR
) );
979 if (!(p
= strchrW( section
, ' ' ))) return;
981 while (*p
== ' ') p
++;
984 if (!(p
= strchrW( p
, ' ' ))) return;
986 while (*path
== ' ') path
++;
988 hinf
= SetupOpenInfFileW( path
, NULL
, INF_STYLE_WIN4
, NULL
);
989 if (hinf
== INVALID_HANDLE_VALUE
) return;
991 callback_context
= SetupInitDefaultQueueCallback( hwnd
);
992 SetupInstallFromInfSectionW( hwnd
, hinf
, section
, SPINST_ALL
, NULL
, NULL
, SP_COPY_NEWER
,
993 SetupDefaultQueueCallbackW
, callback_context
,
995 SetupTermDefaultQueueCallback( callback_context
);
996 SetupCloseInfFile( hinf
);
998 /* FIXME: should check the mode and maybe reboot */
999 /* there isn't much point in doing that since we */
1000 /* don't yet handle deferred file copies anyway. */
1004 /***********************************************************************
1005 * InstallHinfSectionA (SETUPAPI.@)
1007 void WINAPI
InstallHinfSectionA( HWND hwnd
, HINSTANCE handle
, LPCSTR cmdline
, INT show
)
1009 UNICODE_STRING cmdlineW
;
1011 if (RtlCreateUnicodeStringFromAsciiz( &cmdlineW
, cmdline
))
1013 InstallHinfSectionW( hwnd
, handle
, cmdlineW
.Buffer
, show
);
1014 RtlFreeUnicodeString( &cmdlineW
);
1019 /***********************************************************************
1020 * SetupInstallServicesFromInfSectionA (SETUPAPI.@)
1022 BOOL WINAPI
SetupInstallServicesFromInfSectionA( HINF hinf
, PCSTR sectionname
, DWORD flags
)
1024 return SetupInstallServicesFromInfSectionExA( hinf
, sectionname
, flags
,
1025 NULL
, NULL
, NULL
, NULL
);
1029 /***********************************************************************
1030 * SetupInstallServicesFromInfSectionW (SETUPAPI.@)
1032 BOOL WINAPI
SetupInstallServicesFromInfSectionW( HINF hinf
, PCWSTR sectionname
, DWORD flags
)
1034 return SetupInstallServicesFromInfSectionExW( hinf
, sectionname
, flags
,
1035 NULL
, NULL
, NULL
, NULL
);
1039 /***********************************************************************
1040 * SetupInstallServicesFromInfSectionExA (SETUPAPI.@)
1042 BOOL WINAPI
SetupInstallServicesFromInfSectionExA( HINF hinf
, PCSTR sectionname
, DWORD flags
, HDEVINFO devinfo
, PSP_DEVINFO_DATA devinfo_data
, PVOID reserved1
, PVOID reserved2
)
1044 UNICODE_STRING sectionnameW
;
1047 if (RtlCreateUnicodeStringFromAsciiz( §ionnameW
, sectionname
))
1049 ret
= SetupInstallServicesFromInfSectionExW( hinf
, sectionnameW
.Buffer
, flags
, devinfo
, devinfo_data
, reserved1
, reserved2
);
1050 RtlFreeUnicodeString( §ionnameW
);
1053 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1059 static BOOL
GetLineText( HINF hinf
, PCWSTR section_name
, PCWSTR key_name
, PWSTR
*value
)
1066 if (! SetupGetLineTextW( NULL
, hinf
, section_name
, key_name
, NULL
, 0, &required
)
1067 && GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1070 buf
= HeapAlloc( GetProcessHeap(), 0, required
* sizeof(WCHAR
) );
1073 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1077 if (! SetupGetLineTextW( NULL
, hinf
, section_name
, key_name
, buf
, required
, &required
) )
1079 HeapFree( GetProcessHeap(), 0, buf
);
1088 static BOOL
GetIntField( HINF hinf
, PCWSTR section_name
, PCWSTR key_name
, INT
*value
)
1093 if (! GetLineText( hinf
, section_name
, key_name
, &buffer
) )
1096 res
= wcstol( buffer
, &end
, 0 );
1097 if (end
!= buffer
&& !*end
)
1099 HeapFree(GetProcessHeap(), 0, buffer
);
1105 HeapFree(GetProcessHeap(), 0, buffer
);
1106 SetLastError( ERROR_INVALID_DATA
);
1112 BOOL
GetStringField( PINFCONTEXT context
, DWORD index
, PWSTR
*value
)
1117 ret
= SetupGetStringFieldW(
1124 else if (RequiredSize
== 0)
1130 /* We got the needed size for the buffer */
1131 *value
= MyMalloc(RequiredSize
* sizeof(WCHAR
));
1134 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1137 ret
= SetupGetStringFieldW(
1140 *value
, RequiredSize
, NULL
);
1148 static BOOL
InstallOneService(
1149 struct DeviceInfoSet
*list
,
1151 IN LPCWSTR ServiceSection
,
1152 IN LPCWSTR ServiceName
,
1153 IN UINT ServiceFlags
)
1155 SC_HANDLE hSCManager
= NULL
;
1156 SC_HANDLE hService
= NULL
;
1157 LPDWORD GroupOrder
= NULL
;
1158 LPQUERY_SERVICE_CONFIG ServiceConfig
= NULL
;
1161 HKEY hGroupOrderListKey
= INVALID_HANDLE_VALUE
;
1162 LPWSTR ServiceBinary
= NULL
;
1163 LPWSTR LoadOrderGroup
= NULL
;
1164 LPWSTR DisplayName
= NULL
;
1165 LPWSTR Description
= NULL
;
1166 LPWSTR Dependencies
= NULL
;
1167 INT ServiceType
, StartType
, ErrorControl
;
1169 DWORD tagId
= (DWORD
)-1;
1172 if (!GetIntField(hInf
, ServiceSection
, L
"ServiceType", &ServiceType
))
1174 if (!GetIntField(hInf
, ServiceSection
, L
"StartType", &StartType
))
1176 if (!GetIntField(hInf
, ServiceSection
, L
"ErrorControl", &ErrorControl
))
1178 useTag
= (ServiceType
== SERVICE_BOOT_START
|| ServiceType
== SERVICE_SYSTEM_START
);
1180 hSCManager
= OpenSCManagerW(NULL
, SERVICES_ACTIVE_DATABASE
, SC_MANAGER_CREATE_SERVICE
);
1181 if (hSCManager
== NULL
)
1184 if (!GetLineText(hInf
, ServiceSection
, L
"ServiceBinary", &ServiceBinary
))
1187 /* Don't check return value, as these fields are optional and
1188 * GetLineText initialize output parameter even on failure */
1189 GetLineText(hInf
, ServiceSection
, L
"LoadOrderGroup", &LoadOrderGroup
);
1190 GetLineText(hInf
, ServiceSection
, L
"DisplayName", &DisplayName
);
1191 GetLineText(hInf
, ServiceSection
, L
"Description", &Description
);
1192 GetLineText(hInf
, ServiceSection
, L
"Dependencies", &Dependencies
);
1194 hService
= OpenServiceW(
1197 GENERIC_READ
| GENERIC_WRITE
);
1198 if (hService
== NULL
&& GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST
)
1201 if (hService
&& (ServiceFlags
& SPSVCINST_DELETEEVENTLOGENTRY
))
1203 ret
= DeleteService(hService
);
1204 if (!ret
&& GetLastError() != ERROR_SERVICE_MARKED_FOR_DELETE
)
1208 if (hService
== NULL
)
1210 /* Create new service */
1211 hService
= CreateServiceW(
1221 useTag
? &tagId
: NULL
,
1224 if (hService
== NULL
)
1230 /* Read current configuration */
1231 if (!QueryServiceConfigW(hService
, NULL
, 0, &bufferSize
))
1233 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1235 ServiceConfig
= MyMalloc(bufferSize
);
1238 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1241 if (!QueryServiceConfigW(hService
, ServiceConfig
, bufferSize
, &bufferSize
))
1244 tagId
= ServiceConfig
->dwTagId
;
1246 /* Update configuration */
1247 ret
= ChangeServiceConfigW(
1250 (ServiceFlags
& SPSVCINST_NOCLOBBER_STARTTYPE
) ? SERVICE_NO_CHANGE
: StartType
,
1251 (ServiceFlags
& SPSVCINST_NOCLOBBER_ERRORCONTROL
) ? SERVICE_NO_CHANGE
: ErrorControl
,
1253 (ServiceFlags
& SPSVCINST_NOCLOBBER_LOADORDERGROUP
&& ServiceConfig
->lpLoadOrderGroup
) ? NULL
: LoadOrderGroup
,
1254 useTag
? &tagId
: NULL
,
1255 (ServiceFlags
& SPSVCINST_NOCLOBBER_DEPENDENCIES
&& ServiceConfig
->lpDependencies
) ? NULL
: Dependencies
,
1257 (ServiceFlags
& SPSVCINST_NOCLOBBER_DISPLAYNAME
&& ServiceConfig
->lpDisplayName
) ? NULL
: DisplayName
);
1262 /* FIXME: use Description and SPSVCINST_NOCLOBBER_DESCRIPTION */
1266 /* Add the tag to SYSTEM\CurrentControlSet\Control\GroupOrderList key */
1268 LPCWSTR lpLoadOrderGroup
;
1271 lpLoadOrderGroup
= LoadOrderGroup
;
1272 if ((ServiceFlags
& SPSVCINST_NOCLOBBER_LOADORDERGROUP
) && ServiceConfig
&& ServiceConfig
->lpLoadOrderGroup
)
1273 lpLoadOrderGroup
= ServiceConfig
->lpLoadOrderGroup
;
1276 list
? list
->HKLM
: HKEY_LOCAL_MACHINE
,
1277 L
"SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
1278 &hGroupOrderListKey
);
1279 if (rc
!= ERROR_SUCCESS
)
1284 rc
= RegQueryValueExW(hGroupOrderListKey
, lpLoadOrderGroup
, NULL
, &dwRegType
, NULL
, &bufferSize
);
1285 if (rc
== ERROR_FILE_NOT_FOUND
)
1286 bufferSize
= sizeof(DWORD
);
1287 else if (rc
!= ERROR_SUCCESS
)
1292 else if (dwRegType
!= REG_BINARY
|| bufferSize
== 0 || bufferSize
% sizeof(DWORD
) != 0)
1294 SetLastError(ERROR_GEN_FAILURE
);
1297 /* Allocate buffer to store existing data + the new tag */
1298 GroupOrder
= MyMalloc(bufferSize
+ sizeof(DWORD
));
1301 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1304 if (rc
== ERROR_SUCCESS
)
1306 /* Read existing data */
1307 rc
= RegQueryValueExW(
1314 if (rc
!= ERROR_SUCCESS
)
1319 if (ServiceFlags
& SPSVCINST_TAGTOFRONT
)
1320 memmove(&GroupOrder
[2], &GroupOrder
[1], bufferSize
- sizeof(DWORD
));
1327 if (ServiceFlags
& SPSVCINST_TAGTOFRONT
)
1328 GroupOrder
[1] = tagId
;
1330 GroupOrder
[bufferSize
/ sizeof(DWORD
)] = tagId
;
1332 rc
= RegSetValueExW(
1338 bufferSize
+ sizeof(DWORD
));
1339 if (rc
!= ERROR_SUCCESS
)
1349 if (hSCManager
!= NULL
)
1350 CloseServiceHandle(hSCManager
);
1351 if (hService
!= NULL
)
1352 CloseServiceHandle(hService
);
1353 if (hGroupOrderListKey
!= INVALID_HANDLE_VALUE
)
1354 RegCloseKey(hGroupOrderListKey
);
1355 MyFree(ServiceConfig
);
1356 MyFree(ServiceBinary
);
1357 MyFree(LoadOrderGroup
);
1358 MyFree(DisplayName
);
1359 MyFree(Description
);
1360 MyFree(Dependencies
);
1363 TRACE("Returning %d\n", ret
);
1368 /***********************************************************************
1369 * SetupInstallServicesFromInfSectionExW (SETUPAPI.@)
1371 BOOL WINAPI
SetupInstallServicesFromInfSectionExW( HINF hinf
, PCWSTR sectionname
, DWORD flags
, HDEVINFO DeviceInfoSet
, PSP_DEVINFO_DATA DeviceInfoData
, PVOID reserved1
, PVOID reserved2
)
1373 struct DeviceInfoSet
*list
= NULL
;
1376 TRACE("%p, %s, 0x%lx, %p, %p, %p, %p\n", hinf
, debugstr_w(sectionname
),
1377 flags
, DeviceInfoSet
, DeviceInfoData
, reserved1
, reserved2
);
1380 SetLastError(ERROR_INVALID_PARAMETER
);
1381 else if (flags
& ~(SPSVCINST_TAGTOFRONT
| SPSVCINST_DELETEEVENTLOGENTRY
| SPSVCINST_NOCLOBBER_DISPLAYNAME
| SPSVCINST_NOCLOBBER_STARTTYPE
| SPSVCINST_NOCLOBBER_ERRORCONTROL
| SPSVCINST_NOCLOBBER_LOADORDERGROUP
| SPSVCINST_NOCLOBBER_DEPENDENCIES
| SPSVCINST_STOPSERVICE
))
1383 TRACE("Unknown flags: 0x%08lx\n", flags
& ~(SPSVCINST_TAGTOFRONT
| SPSVCINST_DELETEEVENTLOGENTRY
| SPSVCINST_NOCLOBBER_DISPLAYNAME
| SPSVCINST_NOCLOBBER_STARTTYPE
| SPSVCINST_NOCLOBBER_ERRORCONTROL
| SPSVCINST_NOCLOBBER_LOADORDERGROUP
| SPSVCINST_NOCLOBBER_DEPENDENCIES
| SPSVCINST_STOPSERVICE
));
1384 SetLastError(ERROR_INVALID_FLAGS
);
1386 else if (DeviceInfoSet
== (HDEVINFO
)INVALID_HANDLE_VALUE
)
1387 SetLastError(ERROR_INVALID_HANDLE
);
1388 else if (DeviceInfoSet
&& (list
= (struct DeviceInfoSet
*)DeviceInfoSet
)->magic
!= SETUP_DEV_INFO_SET_MAGIC
)
1389 SetLastError(ERROR_INVALID_HANDLE
);
1390 else if (DeviceInfoData
&& DeviceInfoData
->cbSize
!= sizeof(SP_DEVINFO_DATA
))
1391 SetLastError(ERROR_INVALID_USER_BUFFER
);
1392 else if (reserved1
!= NULL
|| reserved2
!= NULL
)
1393 SetLastError(ERROR_INVALID_PARAMETER
);
1396 struct needs_callback_info needs_info
;
1397 LPWSTR ServiceName
= NULL
;
1398 LPWSTR ServiceSection
= NULL
;
1400 INFCONTEXT ContextService
;
1401 BOOL bNeedReboot
= FALSE
;
1403 /* Parse 'Include' and 'Needs' directives */
1404 iterate_section_fields( hinf
, sectionname
, Include
, include_callback
, NULL
);
1405 needs_info
.type
= 1;
1406 needs_info
.flags
= flags
;
1407 needs_info
.devinfo
= DeviceInfoSet
;
1408 needs_info
.devinfo_data
= DeviceInfoData
;
1409 needs_info
.reserved1
= reserved1
;
1410 needs_info
.reserved2
= reserved2
;
1411 iterate_section_fields( hinf
, sectionname
, Needs
, needs_callback
, &needs_info
);
1413 if (flags
& SPSVCINST_STOPSERVICE
)
1415 FIXME("Stopping the device not implemented\n");
1416 /* This may lead to require a reboot */
1417 /* bNeedReboot = TRUE; */
1419 SERVICE_STATUS ServiceStatus
;
1420 ret
= ControlService(hService
, SERVICE_CONTROL_STOP
, &ServiceStatus
);
1421 if (!ret
&& GetLastError() != ERROR_SERVICE_NOT_ACTIVE
)
1423 if (ServiceStatus
.dwCurrentState
!= SERVICE_STOP_PENDING
&& ServiceStatus
.dwCurrentState
!= SERVICE_STOPPED
)
1425 SetLastError(ERROR_INSTALL_SERVICE_FAILURE
);
1429 flags
&= ~SPSVCINST_STOPSERVICE
;
1432 ret
= SetupFindFirstLineW(hinf
, sectionname
, AddService
, &ContextService
);
1435 if (!GetStringField(&ContextService
, 1, &ServiceName
))
1438 ret
= SetupGetIntField(
1440 2, /* Field index */
1444 /* The field may be empty. Ignore the error */
1448 if (!GetStringField(&ContextService
, 3, &ServiceSection
))
1451 ret
= InstallOneService(list
, hinf
, ServiceSection
, ServiceName
, (ServiceFlags
& ~SPSVCINST_ASSOCSERVICE
) | flags
);
1455 if (ServiceFlags
& SPSVCINST_ASSOCSERVICE
)
1457 ret
= SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet
, DeviceInfoData
, SPDRP_SERVICE
, (LPBYTE
)ServiceName
, (strlenW(ServiceName
) + 1) * sizeof(WCHAR
));
1463 HeapFree(GetProcessHeap(), 0, ServiceName
);
1464 HeapFree(GetProcessHeap(), 0, ServiceSection
);
1465 ServiceName
= ServiceSection
= NULL
;
1466 ret
= SetupFindNextMatchLineW(&ContextService
, AddService
, &ContextService
);
1470 SetLastError(ERROR_SUCCESS_REBOOT_REQUIRED
);
1472 SetLastError(ERROR_SUCCESS
);
1476 TRACE("Returning %d\n", ret
);