2 * Copyright (C) 2002 Andreas Mohr
3 * Copyright (C) 2002 Shachar Shemesh
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 /* Wine "bootup" handler application
21 * This app handles the various "hooks" windows allows for applications to perform
22 * as part of the bootstrap process. These are roughly divided into three types.
23 * Knowledge base articles that explain this are 137367, 179365, 232487 and 232509.
24 * Also, 119941 has some info on grpconv.exe
25 * The operations performed are (by order of execution):
27 * Preboot (prior to fully loading the Windows kernel):
28 * - wininit.exe (rename operations left in wininit.ini - Win 9x only)
29 * - PendingRenameOperations (rename operations left in the registry - Win NT+ only)
31 * Startup (before the user logs in)
33 * - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce (9x, asynch)
34 * - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices (9x, asynch)
37 * - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce (all, synch)
38 * - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run (all, asynch)
39 * - HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run (all, asynch)
40 * - Startup folders (all, ?asynch?)
41 * - HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce (all, asynch)
43 * Somewhere in there is processing the RunOnceEx entries (also no imp)
46 * - If a pending rename registry does not start with \??\ the entry is
47 * processed anyways. I'm not sure that is the Windows behaviour.
48 * - Need to check what is the windows behaviour when trying to delete files
49 * and directories that are read-only
50 * - In the pending rename registry processing - there are no traces of the files
51 * processed (requires translations from Unicode to Ansi).
65 #define WIN32_NO_STATUS
71 #include <wine/svcctl.h>
73 #include <wine/debug.h>
83 WINE_DEFAULT_DEBUG_CHANNEL(wineboot
);
85 extern BOOL
shutdown_close_windows( BOOL force
);
86 extern BOOL
shutdown_all_desktops( BOOL force
);
87 extern void kill_processes( BOOL kill_desktop
);
89 static WCHAR windowsdir
[MAX_PATH
];
90 static const BOOL is_64bit
= sizeof(void *) > sizeof(int);
92 /* retrieve the path to the wine.inf file */
93 static WCHAR
*get_wine_inf_path(void)
95 WCHAR
*dir
, *name
= NULL
;
97 if ((dir
= _wgetenv( L
"WINEBUILDDIR" )))
99 if (!(name
= HeapAlloc( GetProcessHeap(), 0,
100 sizeof(L
"\\loader\\wine.inf") + lstrlenW(dir
) * sizeof(WCHAR
) )))
102 lstrcpyW( name
, dir
);
103 lstrcatW( name
, L
"\\loader" );
105 else if ((dir
= _wgetenv( L
"WINEDATADIR" )))
107 if (!(name
= HeapAlloc( GetProcessHeap(), 0, sizeof(L
"\\wine.inf") + lstrlenW(dir
) * sizeof(WCHAR
) )))
109 lstrcpyW( name
, dir
);
113 lstrcatW( name
, L
"\\wine.inf" );
114 name
[1] = '\\'; /* change \??\ to \\?\ */
118 /* update the timestamp if different from the reference time */
119 static BOOL
update_timestamp( const WCHAR
*config_dir
, unsigned long timestamp
)
124 WCHAR
*file
= HeapAlloc( GetProcessHeap(), 0, lstrlenW(config_dir
) * sizeof(WCHAR
) + sizeof(L
"\\.update-timestamp") );
126 if (!file
) return FALSE
;
127 lstrcpyW( file
, config_dir
);
128 lstrcatW( file
, L
"\\.update-timestamp" );
130 if ((fd
= _wopen( file
, O_RDWR
)) != -1)
132 if ((count
= read( fd
, buffer
, sizeof(buffer
) - 1 )) >= 0)
135 if (!strncmp( buffer
, "disable", sizeof("disable")-1 )) goto done
;
136 if (timestamp
== strtoul( buffer
, NULL
, 10 )) goto done
;
138 lseek( fd
, 0, SEEK_SET
);
143 if (errno
!= ENOENT
) goto done
;
144 if ((fd
= _wopen( file
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0666 )) == -1) goto done
;
147 count
= sprintf( buffer
, "%lu\n", timestamp
);
148 if (write( fd
, buffer
, count
) != count
)
150 WINE_WARN( "failed to update timestamp in %s\n", debugstr_w(file
) );
156 if (fd
!= -1) close( fd
);
157 HeapFree( GetProcessHeap(), 0, file
);
161 /* print the config directory in a more Unix-ish way */
162 static const WCHAR
*prettyprint_configdir(void)
164 static WCHAR buffer
[MAX_PATH
];
165 WCHAR
*p
, *path
= _wgetenv( L
"WINECONFIGDIR" );
167 lstrcpynW( buffer
, path
, ARRAY_SIZE(buffer
) );
168 if (lstrlenW( path
) >= ARRAY_SIZE(buffer
) )
169 lstrcpyW( buffer
+ ARRAY_SIZE(buffer
) - 4, L
"..." );
171 if (!wcsncmp( buffer
, L
"\\??\\unix\\", 9 ))
173 for (p
= buffer
+ 9; *p
; p
++) if (*p
== '\\') *p
= '/';
176 else if (!wcsncmp( buffer
, L
"\\??\\Z:\\", 7 ))
178 for (p
= buffer
+ 6; *p
; p
++) if (*p
== '\\') *p
= '/';
181 else return buffer
+ 4;
184 /* wrapper for RegSetValueExW */
185 static DWORD
set_reg_value( HKEY hkey
, const WCHAR
*name
, const WCHAR
*value
)
187 return RegSetValueExW( hkey
, name
, 0, REG_SZ
, (const BYTE
*)value
, (lstrlenW(value
) + 1) * sizeof(WCHAR
) );
190 static DWORD
set_reg_value_dword( HKEY hkey
, const WCHAR
*name
, DWORD value
)
192 return RegSetValueExW( hkey
, name
, 0, REG_DWORD
, (const BYTE
*)&value
, sizeof(value
) );
195 #if defined(__i386__) || defined(__x86_64__)
197 static void initialize_xstate_features(struct _KUSER_SHARED_DATA
*data
)
199 XSTATE_CONFIGURATION
*xstate
= &data
->XState
;
203 if (!data
->ProcessorFeatures
[PF_AVX_INSTRUCTIONS_AVAILABLE
])
206 __cpuidex(regs
, 0, 0);
208 TRACE("Max cpuid level %#x.\n", regs
[0]);
212 __cpuidex(regs
, 1, 0);
213 TRACE("CPU features %#x, %#x, %#x, %#x.\n", regs
[0], regs
[1], regs
[2], regs
[3]);
214 if (!(regs
[2] & (0x1 << 27))) /* xsave OS enabled */
217 __cpuidex(regs
, 0xd, 0);
218 TRACE("XSAVE details %#x, %#x, %#x, %#x.\n", regs
[0], regs
[1], regs
[2], regs
[3]);
219 if (!(regs
[0] & XSTATE_AVX
))
222 xstate
->EnabledFeatures
= (1 << XSTATE_LEGACY_FLOATING_POINT
) | (1 << XSTATE_LEGACY_SSE
) | (1 << XSTATE_AVX
);
223 xstate
->EnabledVolatileFeatures
= xstate
->EnabledFeatures
;
224 xstate
->Size
= sizeof(XSAVE_FORMAT
) + sizeof(XSTATE
);
225 xstate
->AllFeatureSize
= regs
[1];
226 xstate
->AllFeatures
[0] = offsetof(XSAVE_FORMAT
, XmmRegisters
);
227 xstate
->AllFeatures
[1] = sizeof(M128A
) * 16;
228 xstate
->AllFeatures
[2] = sizeof(YMMCONTEXT
);
230 for (i
= 0; i
< 3; ++i
)
231 xstate
->Features
[i
].Size
= xstate
->AllFeatures
[i
];
233 xstate
->Features
[1].Offset
= xstate
->Features
[0].Size
;
234 xstate
->Features
[2].Offset
= sizeof(XSAVE_FORMAT
) + offsetof(XSTATE
, YmmContext
);
236 __cpuidex(regs
, 0xd, 1);
237 xstate
->OptimizedSave
= regs
[0] & 1;
238 xstate
->CompactionEnabled
= !!(regs
[0] & 2);
240 __cpuidex(regs
, 0xd, 2);
241 TRACE("XSAVE feature 2 %#x, %#x, %#x, %#x.\n", regs
[0], regs
[1], regs
[2], regs
[3]);
246 static void initialize_xstate_features(struct _KUSER_SHARED_DATA
*data
)
252 static void create_user_shared_data(void)
254 struct _KUSER_SHARED_DATA
*data
;
255 RTL_OSVERSIONINFOEXW version
;
256 SYSTEM_CPU_INFORMATION sci
;
257 SYSTEM_BASIC_INFORMATION sbi
;
259 OBJECT_ATTRIBUTES attr
= {sizeof(attr
)};
264 RtlInitUnicodeString( &name
, L
"\\KernelObjects\\__wine_user_shared_data" );
265 InitializeObjectAttributes( &attr
, &name
, OBJ_OPENIF
, NULL
, NULL
);
266 if ((status
= NtOpenSection( &handle
, SECTION_ALL_ACCESS
, &attr
)))
268 ERR( "cannot open __wine_user_shared_data: %x\n", status
);
271 data
= MapViewOfFile( handle
, FILE_MAP_WRITE
, 0, 0, sizeof(*data
) );
272 CloseHandle( handle
);
275 ERR( "cannot map __wine_user_shared_data\n" );
279 version
.dwOSVersionInfoSize
= sizeof(version
);
280 RtlGetVersion( &version
);
281 NtQuerySystemInformation( SystemBasicInformation
, &sbi
, sizeof(sbi
), NULL
);
282 NtQuerySystemInformation( SystemCpuInformation
, &sci
, sizeof(sci
), NULL
);
284 data
->TickCountMultiplier
= 1 << 24;
285 data
->LargePageMinimum
= 2 * 1024 * 1024;
286 data
->NtBuildNumber
= version
.dwBuildNumber
;
287 data
->NtProductType
= version
.wProductType
;
288 data
->ProductTypeIsValid
= TRUE
;
289 data
->NativeProcessorArchitecture
= sci
.Architecture
;
290 data
->NtMajorVersion
= version
.dwMajorVersion
;
291 data
->NtMinorVersion
= version
.dwMinorVersion
;
292 data
->SuiteMask
= version
.wSuiteMask
;
293 data
->NumberOfPhysicalPages
= sbi
.MmNumberOfPhysicalPages
;
294 wcscpy( data
->NtSystemRoot
, L
"C:\\windows" );
296 features
= data
->ProcessorFeatures
;
297 switch (sci
.Architecture
)
299 case PROCESSOR_ARCHITECTURE_INTEL
:
300 case PROCESSOR_ARCHITECTURE_AMD64
:
301 features
[PF_COMPARE_EXCHANGE_DOUBLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_CX8
);
302 features
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_MMX
);
303 features
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_SSE
);
304 features
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_3DNOW
);
305 features
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_TSC
);
306 features
[PF_PAE_ENABLED
] = !!(sci
.FeatureSet
& CPU_FEATURE_PAE
);
307 features
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_SSE2
);
308 features
[PF_SSE3_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_SSE3
);
309 features
[PF_SSSE3_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_SSSE3
);
310 features
[PF_XSAVE_ENABLED
] = !!(sci
.FeatureSet
& CPU_FEATURE_XSAVE
);
311 features
[PF_COMPARE_EXCHANGE128
] = !!(sci
.FeatureSet
& CPU_FEATURE_CX128
);
312 features
[PF_SSE_DAZ_MODE_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_DAZ
);
313 features
[PF_NX_ENABLED
] = !!(sci
.FeatureSet
& CPU_FEATURE_NX
);
314 features
[PF_SECOND_LEVEL_ADDRESS_TRANSLATION
] = !!(sci
.FeatureSet
& CPU_FEATURE_2NDLEV
);
315 features
[PF_VIRT_FIRMWARE_ENABLED
] = !!(sci
.FeatureSet
& CPU_FEATURE_VIRT
);
316 features
[PF_RDWRFSGSBASE_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_RDFS
);
317 features
[PF_FASTFAIL_AVAILABLE
] = TRUE
;
318 features
[PF_SSE4_1_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_SSE41
);
319 features
[PF_SSE4_2_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_SSE42
);
320 features
[PF_AVX_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_AVX
);
321 features
[PF_AVX2_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_AVX2
);
323 case PROCESSOR_ARCHITECTURE_ARM
:
324 features
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_ARM_VFP_32
);
325 features
[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_ARM_NEON
);
326 features
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = (sci
.Level
>= 8);
328 case PROCESSOR_ARCHITECTURE_ARM64
:
329 features
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
330 features
[PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_ARM_V8_CRC32
);
331 features
[PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
] = !!(sci
.FeatureSet
& CPU_FEATURE_ARM_V8_CRYPTO
);
334 data
->ActiveProcessorCount
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
335 data
->ActiveGroupCount
= 1;
337 initialize_xstate_features( data
);
339 UnmapViewOfFile( data
);
342 #if defined(__i386__) || defined(__x86_64__)
344 static void regs_to_str( int *regs
, unsigned int len
, WCHAR
*buffer
)
347 unsigned char *p
= (unsigned char *)regs
;
349 for (i
= 0; i
< len
; i
++) { buffer
[i
] = *p
++; }
353 static unsigned int get_model( unsigned int reg0
, unsigned int *stepping
, unsigned int *family
)
355 unsigned int model
, family_id
= (reg0
& (0x0f << 8)) >> 8;
357 model
= (reg0
& (0x0f << 4)) >> 4;
358 if (family_id
== 6 || family_id
== 15) model
|= (reg0
& (0x0f << 16)) >> 12;
361 if (family_id
== 15) *family
+= (reg0
& (0xff << 20)) >> 20;
363 *stepping
= reg0
& 0x0f;
367 static void get_identifier( WCHAR
*buf
, size_t size
, const WCHAR
*arch
)
369 unsigned int family
, model
, stepping
;
370 int regs
[4] = {0, 0, 0, 0};
373 model
= get_model( regs
[0], &stepping
, &family
);
374 swprintf( buf
, size
, L
"%s Family %u Model %u Stepping %u", arch
, family
, model
, stepping
);
377 static void get_vendorid( WCHAR
*buf
)
379 int tmp
, regs
[4] = {0, 0, 0, 0};
382 tmp
= regs
[2]; /* swap edx and ecx */
386 regs_to_str( regs
+ 1, 12, buf
);
389 static void get_namestring( WCHAR
*buf
)
391 int regs
[4] = {0, 0, 0, 0};
394 __cpuid( regs
, 0x80000000 );
395 if (regs
[0] >= 0x80000004)
397 __cpuid( regs
, 0x80000002 );
398 regs_to_str( regs
, 16, buf
);
399 __cpuid( regs
, 0x80000003 );
400 regs_to_str( regs
, 16, buf
+ 16 );
401 __cpuid( regs
, 0x80000004 );
402 regs_to_str( regs
, 16, buf
+ 32 );
404 for (i
= lstrlenW(buf
) - 1; i
>= 0 && buf
[i
] == ' '; i
--) buf
[i
] = 0;
407 #else /* __i386__ || __x86_64__ */
409 static void get_identifier( WCHAR
*buf
, size_t size
, const WCHAR
*arch
) { }
410 static void get_vendorid( WCHAR
*buf
) { }
411 static void get_namestring( WCHAR
*buf
) { }
413 #endif /* __i386__ || __x86_64__ */
415 #include "pshpack1.h"
416 struct smbios_prologue
429 SMBIOS_TYPE_BASEBOARD
,
439 struct smbios_baseboard
441 struct smbios_header hdr
;
450 struct smbios_header hdr
;
456 UINT64 characteristics
;
457 BYTE characteristics_ext
[2];
458 BYTE system_bios_major_release
;
459 BYTE system_bios_minor_release
;
460 BYTE ec_firmware_major_release
;
461 BYTE ec_firmware_minor_release
;
466 struct smbios_header hdr
;
478 #define RSMB (('R' << 24) | ('S' << 16) | ('M' << 8) | 'B')
480 static const struct smbios_header
*find_smbios_entry( enum smbios_type type
, const char *buf
, UINT len
)
482 const char *ptr
, *start
;
483 const struct smbios_prologue
*prologue
;
484 const struct smbios_header
*hdr
;
486 if (len
< sizeof(struct smbios_prologue
)) return NULL
;
487 prologue
= (const struct smbios_prologue
*)buf
;
488 if (prologue
->length
> len
- sizeof(*prologue
) || prologue
->length
< sizeof(*hdr
)) return NULL
;
490 start
= (const char *)(prologue
+ 1);
491 hdr
= (const struct smbios_header
*)start
;
495 if ((const char *)hdr
- start
>= prologue
->length
- sizeof(*hdr
)) return NULL
;
499 WARN( "invalid entry\n" );
503 if (hdr
->type
== type
)
505 if ((const char *)hdr
- start
+ hdr
->length
> prologue
->length
) return NULL
;
508 else /* skip other entries and their strings */
510 for (ptr
= (const char *)hdr
+ hdr
->length
; ptr
- buf
< len
&& *ptr
; ptr
++)
512 for (; ptr
- buf
< len
; ptr
++) if (!*ptr
) break;
514 if (ptr
== (const char *)hdr
+ hdr
->length
) ptr
++;
515 hdr
= (const struct smbios_header
*)(ptr
+ 1);
522 static inline WCHAR
*heap_strdupAW( const char *src
)
526 if (!src
) return NULL
;
527 len
= MultiByteToWideChar( CP_ACP
, 0, src
, -1, NULL
, 0 );
528 if ((dst
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(*dst
) ))) MultiByteToWideChar( CP_ACP
, 0, src
, -1, dst
, len
);
532 static WCHAR
*get_smbios_string( BYTE id
, const char *buf
, UINT offset
, UINT buflen
)
534 const char *ptr
= buf
+ offset
;
537 if (!id
|| offset
>= buflen
) return NULL
;
538 for (ptr
= buf
+ offset
; ptr
- buf
< buflen
&& *ptr
; ptr
++)
540 if (++i
== id
) return heap_strdupAW( ptr
);
541 for (; ptr
- buf
< buflen
; ptr
++) if (!*ptr
) break;
546 static void set_value_from_smbios_string( HKEY key
, const WCHAR
*value
, BYTE id
, const char *buf
, UINT offset
, UINT buflen
)
549 str
= get_smbios_string( id
, buf
, offset
, buflen
);
550 set_reg_value( key
, value
, str
? str
: L
"" );
551 HeapFree( GetProcessHeap(), 0, str
);
554 static void create_bios_baseboard_values( HKEY bios_key
, const char *buf
, UINT len
)
556 const struct smbios_header
*hdr
;
557 const struct smbios_baseboard
*baseboard
;
560 if (!(hdr
= find_smbios_entry( SMBIOS_TYPE_BASEBOARD
, buf
, len
))) return;
561 baseboard
= (const struct smbios_baseboard
*)hdr
;
562 offset
= (const char *)baseboard
- buf
+ baseboard
->hdr
.length
;
564 set_value_from_smbios_string( bios_key
, L
"BaseBoardManufacturer", baseboard
->vendor
, buf
, offset
, len
);
565 set_value_from_smbios_string( bios_key
, L
"BaseBoardProduct", baseboard
->product
, buf
, offset
, len
);
566 set_value_from_smbios_string( bios_key
, L
"BaseBoardVersion", baseboard
->version
, buf
, offset
, len
);
569 static void create_bios_bios_values( HKEY bios_key
, const char *buf
, UINT len
)
571 const struct smbios_header
*hdr
;
572 const struct smbios_bios
*bios
;
575 if (!(hdr
= find_smbios_entry( SMBIOS_TYPE_BIOS
, buf
, len
))) return;
576 bios
= (const struct smbios_bios
*)hdr
;
577 offset
= (const char *)bios
- buf
+ bios
->hdr
.length
;
579 set_value_from_smbios_string( bios_key
, L
"BIOSVendor", bios
->vendor
, buf
, offset
, len
);
580 set_value_from_smbios_string( bios_key
, L
"BIOSVersion", bios
->version
, buf
, offset
, len
);
581 set_value_from_smbios_string( bios_key
, L
"BIOSReleaseDate", bios
->date
, buf
, offset
, len
);
583 if (bios
->hdr
.length
>= 0x18)
585 set_reg_value_dword( bios_key
, L
"BiosMajorRelease", bios
->system_bios_major_release
);
586 set_reg_value_dword( bios_key
, L
"BiosMinorRelease", bios
->system_bios_minor_release
);
587 set_reg_value_dword( bios_key
, L
"ECFirmwareMajorVersion", bios
->ec_firmware_major_release
);
588 set_reg_value_dword( bios_key
, L
"ECFirmwareMinorVersion", bios
->ec_firmware_minor_release
);
592 set_reg_value_dword( bios_key
, L
"BiosMajorRelease", 0xFF );
593 set_reg_value_dword( bios_key
, L
"BiosMinorRelease", 0xFF );
594 set_reg_value_dword( bios_key
, L
"ECFirmwareMajorVersion", 0xFF );
595 set_reg_value_dword( bios_key
, L
"ECFirmwareMinorVersion", 0xFF );
599 static void create_bios_system_values( HKEY bios_key
, const char *buf
, UINT len
)
601 const struct smbios_header
*hdr
;
602 const struct smbios_system
*system
;
605 if (!(hdr
= find_smbios_entry( SMBIOS_TYPE_SYSTEM
, buf
, len
))) return;
606 system
= (const struct smbios_system
*)hdr
;
607 offset
= (const char *)system
- buf
+ system
->hdr
.length
;
609 set_value_from_smbios_string( bios_key
, L
"SystemManufacturer", system
->vendor
, buf
, offset
, len
);
610 set_value_from_smbios_string( bios_key
, L
"SystemProductName", system
->product
, buf
, offset
, len
);
611 set_value_from_smbios_string( bios_key
, L
"SystemVersion", system
->version
, buf
, offset
, len
);
613 if (system
->hdr
.length
>= 0x1B)
615 set_value_from_smbios_string( bios_key
, L
"SystemSKU", system
->sku
, buf
, offset
, len
);
616 set_value_from_smbios_string( bios_key
, L
"SystemFamily", system
->family
, buf
, offset
, len
);
620 set_value_from_smbios_string( bios_key
, L
"SystemSKU", 0, buf
, offset
, len
);
621 set_value_from_smbios_string( bios_key
, L
"SystemFamily", 0, buf
, offset
, len
);
625 static void create_bios_key( HKEY system_key
)
631 if (RegCreateKeyExW( system_key
, L
"BIOS", 0, NULL
, REG_OPTION_VOLATILE
,
632 KEY_ALL_ACCESS
, NULL
, &bios_key
, NULL
))
635 len
= GetSystemFirmwareTable( RSMB
, 0, NULL
, 0 );
636 if (!(buf
= HeapAlloc( GetProcessHeap(), 0, len
))) goto done
;
637 len
= GetSystemFirmwareTable( RSMB
, 0, buf
, len
);
639 create_bios_baseboard_values( bios_key
, buf
, len
);
640 create_bios_bios_values( bios_key
, buf
, len
);
641 create_bios_system_values( bios_key
, buf
, len
);
644 HeapFree( GetProcessHeap(), 0, buf
);
645 RegCloseKey( bios_key
);
648 /* create the volatile hardware registry keys */
649 static void create_hardware_registry_keys(void)
652 HKEY hkey
, system_key
, cpu_key
, fpu_key
;
653 SYSTEM_CPU_INFORMATION sci
;
654 PROCESSOR_POWER_INFORMATION
* power_info
;
655 ULONG sizeof_power_info
= sizeof(PROCESSOR_POWER_INFORMATION
) * NtCurrentTeb()->Peb
->NumberOfProcessors
;
656 WCHAR id
[60], namestr
[49], vendorid
[13];
658 get_namestring( namestr
);
659 get_vendorid( vendorid
);
660 NtQuerySystemInformation( SystemCpuInformation
, &sci
, sizeof(sci
), NULL
);
662 power_info
= HeapAlloc( GetProcessHeap(), 0, sizeof_power_info
);
663 if (power_info
== NULL
)
665 if (NtPowerInformation( ProcessorInformation
, NULL
, 0, power_info
, sizeof_power_info
))
666 memset( power_info
, 0, sizeof_power_info
);
668 switch (sci
.Architecture
)
670 case PROCESSOR_ARCHITECTURE_ARM
:
671 case PROCESSOR_ARCHITECTURE_ARM64
:
672 swprintf( id
, ARRAY_SIZE(id
), L
"ARM Family %u Model %u Revision %u",
673 sci
.Level
, HIBYTE(sci
.Revision
), LOBYTE(sci
.Revision
) );
676 case PROCESSOR_ARCHITECTURE_AMD64
:
677 get_identifier( id
, ARRAY_SIZE(id
), !wcscmp(vendorid
, L
"AuthenticAMD") ? L
"AMD64" : L
"Intel64" );
680 case PROCESSOR_ARCHITECTURE_INTEL
:
682 get_identifier( id
, ARRAY_SIZE(id
), L
"x86" );
686 if (RegCreateKeyExW( HKEY_LOCAL_MACHINE
, L
"Hardware\\Description\\System", 0, NULL
,
687 REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &system_key
, NULL
))
689 HeapFree( GetProcessHeap(), 0, power_info
);
693 switch (sci
.Architecture
)
695 case PROCESSOR_ARCHITECTURE_ARM
:
696 case PROCESSOR_ARCHITECTURE_ARM64
:
697 set_reg_value( system_key
, L
"Identifier", L
"ARM processor family" );
700 case PROCESSOR_ARCHITECTURE_INTEL
:
701 case PROCESSOR_ARCHITECTURE_AMD64
:
703 set_reg_value( system_key
, L
"Identifier", L
"AT compatible" );
707 if (sci
.Architecture
== PROCESSOR_ARCHITECTURE_ARM
||
708 sci
.Architecture
== PROCESSOR_ARCHITECTURE_ARM64
||
709 RegCreateKeyExW( system_key
, L
"FloatingPointProcessor", 0, NULL
, REG_OPTION_VOLATILE
,
710 KEY_ALL_ACCESS
, NULL
, &fpu_key
, NULL
))
712 if (RegCreateKeyExW( system_key
, L
"CentralProcessor", 0, NULL
, REG_OPTION_VOLATILE
,
713 KEY_ALL_ACCESS
, NULL
, &cpu_key
, NULL
))
716 for (i
= 0; i
< NtCurrentTeb()->Peb
->NumberOfProcessors
; i
++)
720 swprintf( numW
, ARRAY_SIZE(numW
), L
"%u", i
);
721 if (!RegCreateKeyExW( cpu_key
, numW
, 0, NULL
, REG_OPTION_VOLATILE
,
722 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
724 RegSetValueExW( hkey
, L
"FeatureSet", 0, REG_DWORD
, (BYTE
*)&sci
.FeatureSet
, sizeof(DWORD
) );
725 set_reg_value( hkey
, L
"Identifier", id
);
726 /* TODO: report ARM properly */
727 set_reg_value( hkey
, L
"ProcessorNameString", namestr
);
728 set_reg_value( hkey
, L
"VendorIdentifier", vendorid
);
729 RegSetValueExW( hkey
, L
"~MHz", 0, REG_DWORD
, (BYTE
*)&power_info
[i
].MaxMhz
, sizeof(DWORD
) );
732 if (sci
.Architecture
!= PROCESSOR_ARCHITECTURE_ARM
&&
733 sci
.Architecture
!= PROCESSOR_ARCHITECTURE_ARM64
&&
734 !RegCreateKeyExW( fpu_key
, numW
, 0, NULL
, REG_OPTION_VOLATILE
,
735 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
737 set_reg_value( hkey
, L
"Identifier", id
);
742 create_bios_key( system_key
);
744 RegCloseKey( fpu_key
);
745 RegCloseKey( cpu_key
);
746 RegCloseKey( system_key
);
747 HeapFree( GetProcessHeap(), 0, power_info
);
751 /* create the DynData registry keys */
752 static void create_dynamic_registry_keys(void)
756 if (!RegCreateKeyExW( HKEY_DYN_DATA
, L
"PerfStats\\StatData", 0, NULL
, 0, KEY_WRITE
, NULL
, &key
, NULL
))
758 if (!RegCreateKeyExW( HKEY_DYN_DATA
, L
"Config Manager\\Enum", 0, NULL
, 0, KEY_WRITE
, NULL
, &key
, NULL
))
762 /* create the platform-specific environment registry keys */
763 static void create_environment_registry_keys( void )
766 SYSTEM_CPU_INFORMATION sci
;
767 WCHAR buffer
[60], vendorid
[13];
768 const WCHAR
*arch
, *parch
;
770 if (RegCreateKeyW( HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Control\\Session Manager\\Environment", &env_key
)) return;
772 get_vendorid( vendorid
);
773 NtQuerySystemInformation( SystemCpuInformation
, &sci
, sizeof(sci
), NULL
);
775 swprintf( buffer
, ARRAY_SIZE(buffer
), L
"%u", NtCurrentTeb()->Peb
->NumberOfProcessors
);
776 set_reg_value( env_key
, L
"NUMBER_OF_PROCESSORS", buffer
);
778 switch (sci
.Architecture
)
780 case PROCESSOR_ARCHITECTURE_AMD64
:
782 parch
= !wcscmp(vendorid
, L
"AuthenticAMD") ? L
"AMD64" : L
"Intel64";
785 case PROCESSOR_ARCHITECTURE_INTEL
:
787 arch
= parch
= L
"x86";
790 set_reg_value( env_key
, L
"PROCESSOR_ARCHITECTURE", arch
);
792 switch (sci
.Architecture
)
794 case PROCESSOR_ARCHITECTURE_ARM
:
795 case PROCESSOR_ARCHITECTURE_ARM64
:
796 swprintf( buffer
, ARRAY_SIZE(buffer
), L
"ARM Family %u Model %u Revision %u",
797 sci
.Level
, HIBYTE(sci
.Revision
), LOBYTE(sci
.Revision
) );
800 case PROCESSOR_ARCHITECTURE_AMD64
:
801 case PROCESSOR_ARCHITECTURE_INTEL
:
803 get_identifier( buffer
, ARRAY_SIZE(buffer
), parch
);
804 lstrcatW( buffer
, L
", " );
805 lstrcatW( buffer
, vendorid
);
808 set_reg_value( env_key
, L
"PROCESSOR_IDENTIFIER", buffer
);
810 swprintf( buffer
, ARRAY_SIZE(buffer
), L
"%u", sci
.Level
);
811 set_reg_value( env_key
, L
"PROCESSOR_LEVEL", buffer
);
813 swprintf( buffer
, ARRAY_SIZE(buffer
), L
"%04x", sci
.Revision
);
814 set_reg_value( env_key
, L
"PROCESSOR_REVISION", buffer
);
816 RegCloseKey( env_key
);
819 /* create the ComputerName registry keys */
820 static void create_computer_name_keys(void)
822 struct addrinfo hints
= {0}, *res
;
823 char *dot
, buffer
[256], *name
= buffer
;
826 if (gethostname( buffer
, sizeof(buffer
) )) return;
827 hints
.ai_flags
= AI_CANONNAME
;
828 if (!getaddrinfo( buffer
, NULL
, &hints
, &res
)) name
= res
->ai_canonname
;
829 dot
= strchr( name
, '.' );
831 else dot
= name
+ strlen(name
);
832 SetComputerNameExA( ComputerNamePhysicalDnsDomain
, dot
);
833 SetComputerNameExA( ComputerNamePhysicalDnsHostname
, name
);
834 if (name
!= buffer
) freeaddrinfo( res
);
836 if (RegOpenKeyW( HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Control\\ComputerName", &key
))
839 if (!RegOpenKeyW( key
, L
"ComputerName", &subkey
))
841 DWORD type
, size
= sizeof(buffer
);
843 if (RegQueryValueExW( subkey
, L
"ComputerName", NULL
, &type
, (BYTE
*)buffer
, &size
)) size
= 0;
844 RegCloseKey( subkey
);
845 if (size
&& !RegCreateKeyExW( key
, L
"ActiveComputerName", 0, NULL
, REG_OPTION_VOLATILE
,
846 KEY_ALL_ACCESS
, NULL
, &subkey
, NULL
))
848 RegSetValueExW( subkey
, L
"ComputerName", 0, type
, (const BYTE
*)buffer
, size
);
849 RegCloseKey( subkey
);
855 static void create_volatile_environment_registry_key(void)
857 WCHAR path
[MAX_PATH
];
858 WCHAR computername
[MAX_COMPUTERNAME_LENGTH
+ 1 + 2];
863 if (RegCreateKeyExW( HKEY_CURRENT_USER
, L
"Volatile Environment", 0, NULL
, REG_OPTION_VOLATILE
,
864 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
867 hr
= SHGetFolderPathW( NULL
, CSIDL_APPDATA
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, path
);
868 if (SUCCEEDED(hr
)) set_reg_value( hkey
, L
"APPDATA", path
);
870 set_reg_value( hkey
, L
"CLIENTNAME", L
"Console" );
872 /* Write the profile path's drive letter and directory components into
873 * HOMEDRIVE and HOMEPATH respectively. */
874 hr
= SHGetFolderPathW( NULL
, CSIDL_PROFILE
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, path
);
877 set_reg_value( hkey
, L
"USERPROFILE", path
);
878 set_reg_value( hkey
, L
"HOMEPATH", path
+ 2 );
880 set_reg_value( hkey
, L
"HOMEDRIVE", path
);
883 size
= ARRAY_SIZE(path
);
884 if (GetUserNameW( path
, &size
)) set_reg_value( hkey
, L
"USERNAME", path
);
886 set_reg_value( hkey
, L
"HOMESHARE", L
"" );
888 hr
= SHGetFolderPathW( NULL
, CSIDL_LOCAL_APPDATA
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, path
);
890 set_reg_value( hkey
, L
"LOCALAPPDATA", path
);
892 size
= ARRAY_SIZE(computername
) - 2;
893 if (GetComputerNameW(&computername
[2], &size
))
895 set_reg_value( hkey
, L
"USERDOMAIN", &computername
[2] );
896 computername
[0] = computername
[1] = '\\';
897 set_reg_value( hkey
, L
"LOGONSERVER", computername
);
900 set_reg_value( hkey
, L
"SESSIONNAME", L
"Console" );
904 /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
905 * Returns FALSE if there was an error, or otherwise if all is ok.
907 static BOOL
wininit(void)
909 WCHAR initial_buffer
[1024];
910 WCHAR
*str
, *buffer
= initial_buffer
;
911 DWORD size
= ARRAY_SIZE(initial_buffer
);
916 if (!(res
= GetPrivateProfileSectionW( L
"rename", buffer
, size
, L
"wininit.ini" ))) return TRUE
;
917 if (res
< size
- 2) break;
918 if (buffer
!= initial_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
920 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) return FALSE
;
923 for (str
= buffer
; *str
; str
+= lstrlenW(str
) + 1)
927 if (*str
== ';') continue; /* comment */
928 if (!(value
= wcschr( str
, '=' ))) continue;
930 /* split the line into key and value */
933 if (!lstrcmpiW( L
"NUL", str
))
935 WINE_TRACE("Deleting file %s\n", wine_dbgstr_w(value
) );
936 if( !DeleteFileW( value
) )
937 WINE_WARN("Error deleting file %s\n", wine_dbgstr_w(value
) );
941 WINE_TRACE("Renaming file %s to %s\n", wine_dbgstr_w(value
), wine_dbgstr_w(str
) );
943 if( !MoveFileExW(value
, str
, MOVEFILE_COPY_ALLOWED
| MOVEFILE_REPLACE_EXISTING
) )
944 WINE_WARN("Error renaming %s to %s\n", wine_dbgstr_w(value
), wine_dbgstr_w(str
) );
949 if (buffer
!= initial_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
951 if( !MoveFileExW( L
"wininit.ini", L
"wininit.bak", MOVEFILE_REPLACE_EXISTING
) )
953 WINE_ERR("Couldn't rename wininit.ini, error %d\n", GetLastError() );
961 static void pendingRename(void)
964 const WCHAR
*src
=NULL
, *dst
=NULL
;
968 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Control\\Session Manager",
969 0, KEY_ALL_ACCESS
, &hSession
))
972 if (RegQueryValueExW( hSession
, L
"PendingFileRenameOperations", NULL
, NULL
, NULL
, &dataLength
))
974 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, dataLength
))) goto end
;
976 if (RegQueryValueExW( hSession
, L
"PendingFileRenameOperations", NULL
, NULL
,
977 (LPBYTE
)buffer
, &dataLength
))
980 /* Make sure that the data is long enough and ends with two NULLs. This
981 * simplifies the code later on.
983 if( dataLength
<2*sizeof(buffer
[0]) ||
984 buffer
[dataLength
/sizeof(buffer
[0])-1]!='\0' ||
985 buffer
[dataLength
/sizeof(buffer
[0])-2]!='\0' )
988 for( src
=buffer
; (src
-buffer
)*sizeof(src
[0])<dataLength
&& *src
!='\0';
989 src
=dst
+lstrlenW(dst
)+1 )
993 dst
=src
+lstrlenW(src
)+1;
995 /* We need to skip the \??\ header */
996 if( src
[0]=='\\' && src
[1]=='?' && src
[2]=='?' && src
[3]=='\\' )
1001 dwFlags
|=MOVEFILE_REPLACE_EXISTING
;
1005 if( dst
[0]=='\\' && dst
[1]=='?' && dst
[2]=='?' && dst
[3]=='\\' )
1010 /* Rename the file */
1011 MoveFileExW( src
, dst
, dwFlags
);
1014 /* Delete the file or directory */
1015 if (!RemoveDirectoryW( src
) && GetLastError() == ERROR_DIRECTORY
) DeleteFileW( src
);
1019 RegDeleteValueW(hSession
, L
"PendingFileRenameOperations");
1022 HeapFree(GetProcessHeap(), 0, buffer
);
1023 RegCloseKey( hSession
);
1026 #define INVALID_RUNCMD_RETURN -1
1028 * This function runs the specified command in the specified dir.
1029 * [in,out] cmdline - the command line to run. The function may change the passed buffer.
1030 * [in] dir - the dir to run the command in. If it is NULL, then the current dir is used.
1031 * [in] wait - whether to wait for the run program to finish before returning.
1032 * [in] minimized - Whether to ask the program to run minimized.
1035 * If running the process failed, returns INVALID_RUNCMD_RETURN. Use GetLastError to get the error code.
1036 * If wait is FALSE - returns 0 if successful.
1037 * If wait is TRUE - returns the program's return value.
1039 static DWORD
runCmd(LPWSTR cmdline
, LPCWSTR dir
, BOOL wait
, BOOL minimized
)
1042 PROCESS_INFORMATION info
;
1045 memset(&si
, 0, sizeof(si
));
1049 si
.dwFlags
=STARTF_USESHOWWINDOW
;
1050 si
.wShowWindow
=SW_MINIMIZE
;
1052 memset(&info
, 0, sizeof(info
));
1054 if( !CreateProcessW(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, dir
, &si
, &info
) )
1056 WINE_WARN("Failed to run command %s (%d)\n", wine_dbgstr_w(cmdline
), GetLastError() );
1057 return INVALID_RUNCMD_RETURN
;
1060 WINE_TRACE("Successfully ran command %s - Created process handle %p\n",
1061 wine_dbgstr_w(cmdline
), info
.hProcess
);
1064 { /* wait for the process to exit */
1065 WaitForSingleObject(info
.hProcess
, INFINITE
);
1066 GetExitCodeProcess(info
.hProcess
, &exit_code
);
1069 CloseHandle( info
.hThread
);
1070 CloseHandle( info
.hProcess
);
1075 static void process_run_key( HKEY key
, const WCHAR
*keyname
, BOOL
delete, BOOL synchronous
)
1079 DWORD disp
, i
, max_cmdline
= 0, max_value
= 0;
1080 WCHAR
*cmdline
= NULL
, *value
= NULL
;
1082 if (RegCreateKeyExW( key
, keyname
, 0, NULL
, 0, delete ? KEY_ALL_ACCESS
: KEY_READ
, NULL
, &runkey
, &disp
))
1085 if (disp
== REG_CREATED_NEW_KEY
)
1088 if (RegQueryInfoKeyW( runkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &i
, &max_value
, &max_cmdline
, NULL
, NULL
))
1093 WINE_TRACE( "No commands to execute.\n" );
1096 if (!(cmdline
= HeapAlloc( GetProcessHeap(), 0, max_cmdline
)))
1098 WINE_ERR( "Couldn't allocate memory for the commands to be executed.\n" );
1101 if (!(value
= HeapAlloc( GetProcessHeap(), 0, ++max_value
* sizeof(*value
) )))
1103 WINE_ERR( "Couldn't allocate memory for the value names.\n" );
1109 DWORD len
= max_value
, len_data
= max_cmdline
, type
;
1111 if ((res
= RegEnumValueW( runkey
, --i
, value
, &len
, 0, &type
, (BYTE
*)cmdline
, &len_data
)))
1113 WINE_ERR( "Couldn't read value %u (%d).\n", i
, res
);
1116 if (delete && (res
= RegDeleteValueW( runkey
, value
)))
1118 WINE_ERR( "Couldn't delete value %u (%d). Running command anyways.\n", i
, res
);
1122 WINE_ERR( "Incorrect type of value %u (%u).\n", i
, type
);
1125 if (runCmd( cmdline
, NULL
, synchronous
, FALSE
) == INVALID_RUNCMD_RETURN
)
1127 WINE_ERR( "Error running cmd %s (%u).\n", wine_dbgstr_w(cmdline
), GetLastError() );
1129 WINE_TRACE( "Done processing cmd %u.\n", i
);
1133 HeapFree( GetProcessHeap(), 0, value
);
1134 HeapFree( GetProcessHeap(), 0, cmdline
);
1135 RegCloseKey( runkey
);
1136 WINE_TRACE( "Done.\n" );
1140 * Process a "Run" type registry key.
1141 * hkRoot is the HKEY from which "Software\Microsoft\Windows\CurrentVersion" is
1143 * szKeyName is the key holding the actual entries.
1144 * bDelete tells whether we should delete each value right before executing it.
1145 * bSynchronous tells whether we should wait for the prog to complete before
1146 * going on to the next prog.
1148 static void ProcessRunKeys( HKEY root
, const WCHAR
*keyname
, BOOL
delete, BOOL synchronous
)
1152 if (root
== HKEY_LOCAL_MACHINE
)
1154 WINE_TRACE( "Processing %s entries under HKLM.\n", wine_dbgstr_w(keyname
) );
1155 if (!RegCreateKeyExW( root
, L
"Software\\Microsoft\\Windows\\CurrentVersion",
1156 0, NULL
, 0, KEY_READ
, NULL
, &key
, NULL
))
1158 process_run_key( key
, keyname
, delete, synchronous
);
1161 if (is_64bit
&& !RegCreateKeyExW( root
, L
"Software\\Microsoft\\Windows\\CurrentVersion",
1162 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &key
, NULL
))
1164 process_run_key( key
, keyname
, delete, synchronous
);
1170 WINE_TRACE( "Processing %s entries under HKCU.\n", wine_dbgstr_w(keyname
) );
1171 if (!RegCreateKeyExW( root
, L
"Software\\Microsoft\\Windows\\CurrentVersion",
1172 0, NULL
, 0, KEY_READ
, NULL
, &key
, NULL
))
1174 process_run_key( key
, keyname
, delete, synchronous
);
1181 * WFP is Windows File Protection, in NT5 and Windows 2000 it maintains a cache
1182 * of known good dlls and scans through and replaces corrupted DLLs with these
1183 * known good versions. The only programs that should install into this dll
1184 * cache are Windows Updates and IE (which is treated like a Windows Update)
1186 * Implementing this allows installing ie in win2k mode to actually install the
1187 * system dlls that we expect and need
1189 static int ProcessWindowsFileProtection(void)
1191 WIN32_FIND_DATAW finddata
;
1196 LPWSTR dllcache
= NULL
;
1198 if (!RegOpenKeyW( HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", &hkey
))
1201 if (!RegQueryValueExW( hkey
, L
"SFCDllCacheDir", 0, NULL
, NULL
, &sz
))
1203 sz
+= sizeof(WCHAR
);
1204 dllcache
= HeapAlloc(GetProcessHeap(),0,sz
+ sizeof(L
"\\*"));
1205 RegQueryValueExW( hkey
, L
"SFCDllCacheDir", 0, NULL
, (LPBYTE
)dllcache
, &sz
);
1206 lstrcatW( dllcache
, L
"\\*" );
1213 DWORD sz
= GetSystemDirectoryW( NULL
, 0 );
1214 dllcache
= HeapAlloc( GetProcessHeap(), 0, sz
* sizeof(WCHAR
) + sizeof(L
"\\dllcache\\*"));
1215 GetSystemDirectoryW( dllcache
, sz
);
1216 lstrcatW( dllcache
, L
"\\dllcache\\*" );
1219 find_handle
= FindFirstFileW(dllcache
,&finddata
);
1220 dllcache
[ lstrlenW(dllcache
) - 2] = 0; /* strip off wildcard */
1221 find_rc
= find_handle
!= INVALID_HANDLE_VALUE
;
1224 WCHAR targetpath
[MAX_PATH
];
1225 WCHAR currentpath
[MAX_PATH
];
1228 WCHAR tempfile
[MAX_PATH
];
1230 if (wcscmp(finddata
.cFileName
,L
".") == 0 || wcscmp(finddata
.cFileName
,L
"..") == 0)
1232 find_rc
= FindNextFileW(find_handle
,&finddata
);
1238 VerFindFileW(VFFF_ISSHAREDFILE
, finddata
.cFileName
, windowsdir
,
1239 windowsdir
, currentpath
, &sz
, targetpath
, &sz2
);
1241 rc
= VerInstallFileW(0, finddata
.cFileName
, finddata
.cFileName
,
1242 dllcache
, targetpath
, currentpath
, tempfile
, &sz
);
1243 if (rc
!= ERROR_SUCCESS
)
1245 WINE_WARN("WFP: %s error 0x%x\n",wine_dbgstr_w(finddata
.cFileName
),rc
);
1246 DeleteFileW(tempfile
);
1249 /* now delete the source file so that we don't try to install it over and over again */
1250 lstrcpynW( targetpath
, dllcache
, MAX_PATH
- 1 );
1251 sz
= lstrlenW( targetpath
);
1252 targetpath
[sz
++] = '\\';
1253 lstrcpynW( targetpath
+ sz
, finddata
.cFileName
, MAX_PATH
- sz
);
1254 if (!DeleteFileW( targetpath
))
1255 WINE_WARN( "failed to delete %s: error %u\n", wine_dbgstr_w(targetpath
), GetLastError() );
1257 find_rc
= FindNextFileW(find_handle
,&finddata
);
1259 FindClose(find_handle
);
1260 HeapFree(GetProcessHeap(),0,dllcache
);
1264 static BOOL
start_services_process(void)
1266 static const WCHAR svcctl_started_event
[] = SVCCTL_STARTED_EVENT
;
1267 PROCESS_INFORMATION pi
;
1268 STARTUPINFOW si
= { sizeof(si
) };
1269 HANDLE wait_handles
[2];
1271 if (!CreateProcessW(L
"C:\\windows\\system32\\services.exe", NULL
,
1272 NULL
, NULL
, TRUE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
))
1274 WINE_ERR("Couldn't start services.exe: error %u\n", GetLastError());
1277 CloseHandle(pi
.hThread
);
1279 wait_handles
[0] = CreateEventW(NULL
, TRUE
, FALSE
, svcctl_started_event
);
1280 wait_handles
[1] = pi
.hProcess
;
1282 /* wait for the event to become available or the process to exit */
1283 if ((WaitForMultipleObjects(2, wait_handles
, FALSE
, INFINITE
)) == WAIT_OBJECT_0
+ 1)
1286 GetExitCodeProcess(pi
.hProcess
, &exit_code
);
1287 WINE_ERR("Unexpected termination of services.exe - exit code %d\n", exit_code
);
1288 CloseHandle(pi
.hProcess
);
1289 CloseHandle(wait_handles
[0]);
1293 CloseHandle(pi
.hProcess
);
1294 CloseHandle(wait_handles
[0]);
1298 static INT_PTR CALLBACK
wait_dlgproc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1305 WCHAR
*buffer
, text
[1024];
1306 const WCHAR
*name
= (WCHAR
*)lp
;
1307 HICON icon
= LoadImageW( 0, (LPCWSTR
)IDI_WINLOGO
, IMAGE_ICON
, 48, 48, LR_SHARED
);
1308 SendDlgItemMessageW( hwnd
, IDC_WAITICON
, STM_SETICON
, (WPARAM
)icon
, 0 );
1309 SendDlgItemMessageW( hwnd
, IDC_WAITTEXT
, WM_GETTEXT
, 1024, (LPARAM
)text
);
1310 len
= lstrlenW(text
) + lstrlenW(name
) + 1;
1311 buffer
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1312 swprintf( buffer
, len
, text
, name
);
1313 SendDlgItemMessageW( hwnd
, IDC_WAITTEXT
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
1314 HeapFree( GetProcessHeap(), 0, buffer
);
1321 static HWND
show_wait_window(void)
1323 HWND hwnd
= CreateDialogParamW( GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_WAITDLG
), 0,
1324 wait_dlgproc
, (LPARAM
)prettyprint_configdir() );
1325 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1329 static HANDLE
start_rundll32( const WCHAR
*inf_path
, BOOL wow64
)
1331 WCHAR app
[MAX_PATH
+ ARRAY_SIZE(L
"\\rundll32.exe" )];
1333 PROCESS_INFORMATION pi
;
1337 memset( &si
, 0, sizeof(si
) );
1342 if (!GetSystemWow64DirectoryW( app
, MAX_PATH
)) return 0; /* not on 64-bit */
1344 else GetSystemDirectoryW( app
, MAX_PATH
);
1346 lstrcatW( app
, L
"\\rundll32.exe" );
1348 len
= lstrlenW(app
) + ARRAY_SIZE(L
" setupapi,InstallHinfSection DefaultInstall 128 ") + lstrlenW(inf_path
);
1350 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
1352 lstrcpyW( buffer
, app
);
1353 lstrcatW( buffer
, L
" setupapi,InstallHinfSection" );
1354 lstrcatW( buffer
, wow64
? L
" Wow64Install" : L
" DefaultInstall" );
1355 lstrcatW( buffer
, L
" 128 " );
1356 lstrcatW( buffer
, inf_path
);
1358 if (CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
1359 CloseHandle( pi
.hThread
);
1363 HeapFree( GetProcessHeap(), 0, buffer
);
1367 static void install_root_pnp_devices(void)
1372 const char *hardware_id
;
1373 const char *infpath
;
1377 {"root\\wine\\winebus", "root\\winebus\0", "C:\\windows\\inf\\winebus.inf"},
1378 {"root\\wine\\wineusb", "root\\wineusb\0", "C:\\windows\\inf\\wineusb.inf"},
1380 SP_DEVINFO_DATA device
= {sizeof(device
)};
1384 if ((set
= SetupDiCreateDeviceInfoList( NULL
, NULL
)) == INVALID_HANDLE_VALUE
)
1386 WINE_ERR("Failed to create device info list, error %#x.\n", GetLastError());
1390 for (i
= 0; i
< ARRAY_SIZE(root_devices
); ++i
)
1392 if (!SetupDiCreateDeviceInfoA( set
, root_devices
[i
].name
, &GUID_NULL
, NULL
, NULL
, 0, &device
))
1394 if (GetLastError() != ERROR_DEVINST_ALREADY_EXISTS
)
1395 WINE_ERR("Failed to create device %s, error %#x.\n", debugstr_a(root_devices
[i
].name
), GetLastError());
1399 if (!SetupDiSetDeviceRegistryPropertyA(set
, &device
, SPDRP_HARDWAREID
,
1400 (const BYTE
*)root_devices
[i
].hardware_id
, (strlen(root_devices
[i
].hardware_id
) + 2) * sizeof(WCHAR
)))
1402 WINE_ERR("Failed to set hardware id for %s, error %#x.\n", debugstr_a(root_devices
[i
].name
), GetLastError());
1406 if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE
, set
, &device
))
1408 WINE_ERR("Failed to register device %s, error %#x.\n", debugstr_a(root_devices
[i
].name
), GetLastError());
1412 if (!UpdateDriverForPlugAndPlayDevicesA(NULL
, root_devices
[i
].hardware_id
, root_devices
[i
].infpath
, 0, NULL
))
1413 WINE_ERR("Failed to install drivers for %s, error %#x.\n", debugstr_a(root_devices
[i
].name
), GetLastError());
1416 SetupDiDestroyDeviceInfoList(set
);
1419 static void update_user_profile(void)
1421 char token_buf
[sizeof(TOKEN_USER
) + sizeof(SID
) + sizeof(DWORD
) * SID_MAX_SUB_AUTHORITIES
];
1423 WCHAR profile
[MAX_PATH
], *sid
;
1425 HKEY hkey
, profile_hkey
;
1427 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ
, &token
))
1430 size
= sizeof(token_buf
);
1431 GetTokenInformation(token
, TokenUser
, token_buf
, size
, &size
);
1434 ConvertSidToStringSidW(((TOKEN_USER
*)token_buf
)->User
.Sid
, &sid
);
1436 if (!RegCreateKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
1437 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
1439 if (!RegCreateKeyExW(hkey
, sid
, 0, NULL
, 0,
1440 KEY_ALL_ACCESS
, NULL
, &profile_hkey
, NULL
))
1443 if (SHGetSpecialFolderPathW(NULL
, profile
, CSIDL_PROFILE
, TRUE
))
1444 set_reg_value(profile_hkey
, L
"ProfileImagePath", profile
);
1445 RegSetValueExW( profile_hkey
, L
"Flags", 0, REG_DWORD
, (const BYTE
*)&flags
, sizeof(flags
) );
1446 RegCloseKey(profile_hkey
);
1455 /* execute rundll32 on the wine.inf file if necessary */
1456 static void update_wineprefix( BOOL force
)
1458 const WCHAR
*config_dir
= _wgetenv( L
"WINECONFIGDIR" );
1459 WCHAR
*inf_path
= get_wine_inf_path();
1465 WINE_MESSAGE( "wine: failed to update %s, wine.inf not found\n", debugstr_w( config_dir
));
1468 if ((fd
= _wopen( inf_path
, O_RDONLY
)) == -1)
1470 WINE_MESSAGE( "wine: failed to update %s with %s: %s\n",
1471 debugstr_w(config_dir
), debugstr_w(inf_path
), strerror(errno
) );
1477 if (update_timestamp( config_dir
, st
.st_mtime
) || force
)
1482 if ((process
= start_rundll32( inf_path
, FALSE
)))
1484 HWND hwnd
= show_wait_window();
1488 DWORD res
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, INFINITE
, QS_ALLINPUT
);
1489 if (res
== WAIT_OBJECT_0
)
1491 CloseHandle( process
);
1492 if (count
++ || !(process
= start_rundll32( inf_path
, TRUE
))) break;
1494 else while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageW( &msg
);
1496 DestroyWindow( hwnd
);
1498 install_root_pnp_devices();
1499 update_user_profile();
1501 WINE_MESSAGE( "wine: configuration in %s has been updated.\n", debugstr_w(prettyprint_configdir()) );
1505 HeapFree( GetProcessHeap(), 0, inf_path
);
1508 /* Process items in the StartUp group of the user's Programs under the Start Menu. Some installers put
1509 * shell links here to restart themselves after boot. */
1510 static BOOL
ProcessStartupItems(void)
1514 IShellFolder
*psfDesktop
= NULL
, *psfStartup
= NULL
;
1515 LPITEMIDLIST pidlStartup
= NULL
, pidlItem
;
1517 IEnumIDList
*iEnumList
= NULL
;
1519 WCHAR wszCommand
[MAX_PATH
];
1521 WINE_TRACE("Processing items in the StartUp folder.\n");
1523 hr
= SHGetDesktopFolder(&psfDesktop
);
1526 WINE_ERR("Couldn't get desktop folder.\n");
1530 hr
= SHGetSpecialFolderLocation(NULL
, CSIDL_STARTUP
, &pidlStartup
);
1533 WINE_TRACE("Couldn't get StartUp folder location.\n");
1537 hr
= IShellFolder_BindToObject(psfDesktop
, pidlStartup
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfStartup
);
1540 WINE_TRACE("Couldn't bind IShellFolder to StartUp folder.\n");
1544 hr
= IShellFolder_EnumObjects(psfStartup
, NULL
, SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &iEnumList
);
1547 WINE_TRACE("Unable to enumerate StartUp objects.\n");
1551 while (IEnumIDList_Next(iEnumList
, 1, &pidlItem
, &NumPIDLs
) == S_OK
&&
1554 hr
= IShellFolder_GetDisplayNameOf(psfStartup
, pidlItem
, SHGDN_FORPARSING
, &strret
);
1556 WINE_TRACE("Unable to get display name of enumeration item.\n");
1559 hr
= StrRetToBufW(&strret
, pidlItem
, wszCommand
, MAX_PATH
);
1561 WINE_TRACE("Unable to parse display name.\n");
1566 hinst
= ShellExecuteW(NULL
, NULL
, wszCommand
, NULL
, NULL
, SW_SHOWNORMAL
);
1567 if (PtrToUlong(hinst
) <= 32)
1568 WINE_WARN("Error %p executing command %s.\n", hinst
, wine_dbgstr_w(wszCommand
));
1575 /* Return success */
1579 if (iEnumList
) IEnumIDList_Release(iEnumList
);
1580 if (psfStartup
) IShellFolder_Release(psfStartup
);
1581 if (pidlStartup
) ILFree(pidlStartup
);
1586 static void usage( int status
)
1588 WINE_MESSAGE( "Usage: wineboot [options]\n" );
1589 WINE_MESSAGE( "Options;\n" );
1590 WINE_MESSAGE( " -h,--help Display this help message\n" );
1591 WINE_MESSAGE( " -e,--end-session End the current session cleanly\n" );
1592 WINE_MESSAGE( " -f,--force Force exit for processes that don't exit cleanly\n" );
1593 WINE_MESSAGE( " -i,--init Perform initialization for first Wine instance\n" );
1594 WINE_MESSAGE( " -k,--kill Kill running processes without any cleanup\n" );
1595 WINE_MESSAGE( " -r,--restart Restart only, don't do normal startup operations\n" );
1596 WINE_MESSAGE( " -s,--shutdown Shutdown only, don't reboot\n" );
1597 WINE_MESSAGE( " -u,--update Update the wineprefix directory\n" );
1601 int __cdecl
main( int argc
, char *argv
[] )
1603 /* First, set the current directory to SystemRoot */
1605 BOOL end_session
, force
, init
, kill
, restart
, shutdown
, update
;
1607 OBJECT_ATTRIBUTES attr
;
1608 UNICODE_STRING nameW
;
1611 end_session
= force
= init
= kill
= restart
= shutdown
= update
= FALSE
;
1612 GetWindowsDirectoryW( windowsdir
, MAX_PATH
);
1613 if( !SetCurrentDirectoryW( windowsdir
) )
1614 WINE_ERR("Cannot set the dir to %s (%d)\n", wine_dbgstr_w(windowsdir
), GetLastError() );
1616 if (IsWow64Process( GetCurrentProcess(), &is_wow64
) && is_wow64
)
1619 PROCESS_INFORMATION pi
;
1620 WCHAR filename
[MAX_PATH
];
1624 memset( &si
, 0, sizeof(si
) );
1626 GetModuleFileNameW( 0, filename
, MAX_PATH
);
1628 Wow64DisableWow64FsRedirection( &redir
);
1629 if (CreateProcessW( filename
, GetCommandLineW(), NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
1631 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename
) );
1632 WaitForSingleObject( pi
.hProcess
, INFINITE
);
1633 GetExitCodeProcess( pi
.hProcess
, &exit_code
);
1634 ExitProcess( exit_code
);
1636 else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename
), GetLastError() );
1637 Wow64RevertWow64FsRedirection( redir
);
1640 for (i
= 1; i
< argc
; i
++)
1642 if (argv
[i
][0] != '-') continue;
1643 if (argv
[i
][1] == '-')
1645 if (!strcmp( argv
[i
], "--help" )) usage( 0 );
1646 else if (!strcmp( argv
[i
], "--end-session" )) end_session
= TRUE
;
1647 else if (!strcmp( argv
[i
], "--force" )) force
= TRUE
;
1648 else if (!strcmp( argv
[i
], "--init" )) init
= TRUE
;
1649 else if (!strcmp( argv
[i
], "--kill" )) kill
= TRUE
;
1650 else if (!strcmp( argv
[i
], "--restart" )) restart
= TRUE
;
1651 else if (!strcmp( argv
[i
], "--shutdown" )) shutdown
= TRUE
;
1652 else if (!strcmp( argv
[i
], "--update" )) update
= TRUE
;
1656 for (j
= 1; argv
[i
][j
]; j
++)
1660 case 'e': end_session
= TRUE
; break;
1661 case 'f': force
= TRUE
; break;
1662 case 'i': init
= TRUE
; break;
1663 case 'k': kill
= TRUE
; break;
1664 case 'r': restart
= TRUE
; break;
1665 case 's': shutdown
= TRUE
; break;
1666 case 'u': update
= TRUE
; break;
1667 case 'h': usage(0); break;
1668 default: usage(1); break;
1677 if (!shutdown_all_desktops( force
)) return 1;
1679 else if (!shutdown_close_windows( force
)) return 1;
1682 if (kill
) kill_processes( shutdown
);
1684 if (shutdown
) return 0;
1686 /* create event to be inherited by services.exe */
1687 InitializeObjectAttributes( &attr
, &nameW
, OBJ_OPENIF
| OBJ_INHERIT
, 0, NULL
);
1688 RtlInitUnicodeString( &nameW
, L
"\\KernelObjects\\__wineboot_event" );
1689 NtCreateEvent( &event
, EVENT_ALL_ACCESS
, &attr
, NotificationEvent
, 0 );
1691 ResetEvent( event
); /* in case this is a restart */
1693 create_user_shared_data();
1694 create_hardware_registry_keys();
1695 create_dynamic_registry_keys();
1696 create_environment_registry_keys();
1697 create_computer_name_keys();
1701 ProcessWindowsFileProtection();
1702 ProcessRunKeys( HKEY_LOCAL_MACHINE
, L
"RunServicesOnce", TRUE
, FALSE
);
1704 if (init
|| (kill
&& !restart
))
1706 ProcessRunKeys( HKEY_LOCAL_MACHINE
, L
"RunServices", FALSE
, FALSE
);
1707 start_services_process();
1709 if (init
|| update
) update_wineprefix( update
);
1711 create_volatile_environment_registry_key();
1713 ProcessRunKeys( HKEY_LOCAL_MACHINE
, L
"RunOnce", TRUE
, TRUE
);
1715 if (!init
&& !restart
)
1717 ProcessRunKeys( HKEY_LOCAL_MACHINE
, L
"Run", FALSE
, FALSE
);
1718 ProcessRunKeys( HKEY_CURRENT_USER
, L
"Run", FALSE
, FALSE
);
1719 ProcessStartupItems();
1722 WINE_TRACE("Operation done\n");