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: %lx\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
.ProcessorArchitecture
;
290 data
->NtMajorVersion
= version
.dwMajorVersion
;
291 data
->NtMinorVersion
= version
.dwMinorVersion
;
292 data
->SuiteMask
= version
.wSuiteMask
;
293 data
->NumberOfPhysicalPages
= sbi
.MmNumberOfPhysicalPages
;
294 data
->NXSupportPolicy
= NX_SUPPORT_POLICY_OPTIN
;
295 wcscpy( data
->NtSystemRoot
, L
"C:\\windows" );
297 features
= data
->ProcessorFeatures
;
298 switch (sci
.ProcessorArchitecture
)
300 case PROCESSOR_ARCHITECTURE_INTEL
:
301 case PROCESSOR_ARCHITECTURE_AMD64
:
302 features
[PF_COMPARE_EXCHANGE_DOUBLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_CX8
);
303 features
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_MMX
);
304 features
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_SSE
);
305 features
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_3DNOW
);
306 features
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_TSC
);
307 features
[PF_PAE_ENABLED
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_PAE
);
308 features
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_SSE2
);
309 features
[PF_SSE3_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_SSE3
);
310 features
[PF_SSSE3_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_SSSE3
);
311 features
[PF_XSAVE_ENABLED
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_XSAVE
);
312 features
[PF_COMPARE_EXCHANGE128
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_CX128
);
313 features
[PF_SSE_DAZ_MODE_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_DAZ
);
314 features
[PF_NX_ENABLED
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_NX
);
315 features
[PF_SECOND_LEVEL_ADDRESS_TRANSLATION
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_2NDLEV
);
316 features
[PF_VIRT_FIRMWARE_ENABLED
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_VIRT
);
317 features
[PF_RDWRFSGSBASE_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_RDFS
);
318 features
[PF_FASTFAIL_AVAILABLE
] = TRUE
;
319 features
[PF_SSE4_1_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_SSE41
);
320 features
[PF_SSE4_2_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_SSE42
);
321 features
[PF_AVX_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_AVX
);
322 features
[PF_AVX2_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_AVX2
);
324 case PROCESSOR_ARCHITECTURE_ARM
:
325 features
[PF_ARM_VFP_32_REGISTERS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_ARM_VFP_32
);
326 features
[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_ARM_NEON
);
327 features
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = (sci
.ProcessorLevel
>= 8);
329 case PROCESSOR_ARCHITECTURE_ARM64
:
330 features
[PF_ARM_V8_INSTRUCTIONS_AVAILABLE
] = TRUE
;
331 features
[PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_ARM_V8_CRC32
);
332 features
[PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
] = !!(sci
.ProcessorFeatureBits
& CPU_FEATURE_ARM_V8_CRYPTO
);
335 data
->ActiveProcessorCount
= NtCurrentTeb()->Peb
->NumberOfProcessors
;
336 data
->ActiveGroupCount
= 1;
338 initialize_xstate_features( data
);
340 UnmapViewOfFile( data
);
343 #if defined(__i386__) || defined(__x86_64__)
345 static void regs_to_str( int *regs
, unsigned int len
, WCHAR
*buffer
)
348 unsigned char *p
= (unsigned char *)regs
;
350 for (i
= 0; i
< len
; i
++) { buffer
[i
] = *p
++; }
354 static unsigned int get_model( unsigned int reg0
, unsigned int *stepping
, unsigned int *family
)
356 unsigned int model
, family_id
= (reg0
& (0x0f << 8)) >> 8;
358 model
= (reg0
& (0x0f << 4)) >> 4;
359 if (family_id
== 6 || family_id
== 15) model
|= (reg0
& (0x0f << 16)) >> 12;
362 if (family_id
== 15) *family
+= (reg0
& (0xff << 20)) >> 20;
364 *stepping
= reg0
& 0x0f;
368 static void get_identifier( WCHAR
*buf
, size_t size
, const WCHAR
*arch
)
370 unsigned int family
, model
, stepping
;
371 int regs
[4] = {0, 0, 0, 0};
374 model
= get_model( regs
[0], &stepping
, &family
);
375 swprintf( buf
, size
, L
"%s Family %u Model %u Stepping %u", arch
, family
, model
, stepping
);
378 static void get_vendorid( WCHAR
*buf
)
380 int tmp
, regs
[4] = {0, 0, 0, 0};
383 tmp
= regs
[2]; /* swap edx and ecx */
387 regs_to_str( regs
+ 1, 12, buf
);
390 static void get_namestring( WCHAR
*buf
)
392 int regs
[4] = {0, 0, 0, 0};
395 __cpuid( regs
, 0x80000000 );
396 if (regs
[0] >= 0x80000004)
398 __cpuid( regs
, 0x80000002 );
399 regs_to_str( regs
, 16, buf
);
400 __cpuid( regs
, 0x80000003 );
401 regs_to_str( regs
, 16, buf
+ 16 );
402 __cpuid( regs
, 0x80000004 );
403 regs_to_str( regs
, 16, buf
+ 32 );
405 for (i
= lstrlenW(buf
) - 1; i
>= 0 && buf
[i
] == ' '; i
--) buf
[i
] = 0;
408 #else /* __i386__ || __x86_64__ */
410 static void get_identifier( WCHAR
*buf
, size_t size
, const WCHAR
*arch
) { }
411 static void get_vendorid( WCHAR
*buf
) { }
412 static void get_namestring( WCHAR
*buf
) { }
414 #endif /* __i386__ || __x86_64__ */
416 #include "pshpack1.h"
417 struct smbios_prologue
430 SMBIOS_TYPE_BASEBOARD
,
440 struct smbios_baseboard
442 struct smbios_header hdr
;
451 struct smbios_header hdr
;
457 UINT64 characteristics
;
458 BYTE characteristics_ext
[2];
459 BYTE system_bios_major_release
;
460 BYTE system_bios_minor_release
;
461 BYTE ec_firmware_major_release
;
462 BYTE ec_firmware_minor_release
;
467 struct smbios_header hdr
;
479 #define RSMB (('R' << 24) | ('S' << 16) | ('M' << 8) | 'B')
481 static const struct smbios_header
*find_smbios_entry( enum smbios_type type
, const char *buf
, UINT len
)
483 const char *ptr
, *start
;
484 const struct smbios_prologue
*prologue
;
485 const struct smbios_header
*hdr
;
487 if (len
< sizeof(struct smbios_prologue
)) return NULL
;
488 prologue
= (const struct smbios_prologue
*)buf
;
489 if (prologue
->length
> len
- sizeof(*prologue
) || prologue
->length
< sizeof(*hdr
)) return NULL
;
491 start
= (const char *)(prologue
+ 1);
492 hdr
= (const struct smbios_header
*)start
;
496 if ((const char *)hdr
- start
>= prologue
->length
- sizeof(*hdr
)) return NULL
;
500 WARN( "invalid entry\n" );
504 if (hdr
->type
== type
)
506 if ((const char *)hdr
- start
+ hdr
->length
> prologue
->length
) return NULL
;
509 else /* skip other entries and their strings */
511 for (ptr
= (const char *)hdr
+ hdr
->length
; ptr
- buf
< len
&& *ptr
; ptr
++)
513 for (; ptr
- buf
< len
; ptr
++) if (!*ptr
) break;
515 if (ptr
== (const char *)hdr
+ hdr
->length
) ptr
++;
516 hdr
= (const struct smbios_header
*)(ptr
+ 1);
523 static inline WCHAR
*heap_strdupAW( const char *src
)
527 if (!src
) return NULL
;
528 len
= MultiByteToWideChar( CP_ACP
, 0, src
, -1, NULL
, 0 );
529 if ((dst
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(*dst
) ))) MultiByteToWideChar( CP_ACP
, 0, src
, -1, dst
, len
);
533 static WCHAR
*get_smbios_string( BYTE id
, const char *buf
, UINT offset
, UINT buflen
)
535 const char *ptr
= buf
+ offset
;
538 if (!id
|| offset
>= buflen
) return NULL
;
539 for (ptr
= buf
+ offset
; ptr
- buf
< buflen
&& *ptr
; ptr
++)
541 if (++i
== id
) return heap_strdupAW( ptr
);
542 for (; ptr
- buf
< buflen
; ptr
++) if (!*ptr
) break;
547 static void set_value_from_smbios_string( HKEY key
, const WCHAR
*value
, BYTE id
, const char *buf
, UINT offset
, UINT buflen
)
550 str
= get_smbios_string( id
, buf
, offset
, buflen
);
551 set_reg_value( key
, value
, str
? str
: L
"" );
552 HeapFree( GetProcessHeap(), 0, str
);
555 static void create_bios_baseboard_values( HKEY bios_key
, const char *buf
, UINT len
)
557 const struct smbios_header
*hdr
;
558 const struct smbios_baseboard
*baseboard
;
561 if (!(hdr
= find_smbios_entry( SMBIOS_TYPE_BASEBOARD
, buf
, len
))) return;
562 baseboard
= (const struct smbios_baseboard
*)hdr
;
563 offset
= (const char *)baseboard
- buf
+ baseboard
->hdr
.length
;
565 set_value_from_smbios_string( bios_key
, L
"BaseBoardManufacturer", baseboard
->vendor
, buf
, offset
, len
);
566 set_value_from_smbios_string( bios_key
, L
"BaseBoardProduct", baseboard
->product
, buf
, offset
, len
);
567 set_value_from_smbios_string( bios_key
, L
"BaseBoardVersion", baseboard
->version
, buf
, offset
, len
);
570 static void create_bios_bios_values( HKEY bios_key
, const char *buf
, UINT len
)
572 const struct smbios_header
*hdr
;
573 const struct smbios_bios
*bios
;
576 if (!(hdr
= find_smbios_entry( SMBIOS_TYPE_BIOS
, buf
, len
))) return;
577 bios
= (const struct smbios_bios
*)hdr
;
578 offset
= (const char *)bios
- buf
+ bios
->hdr
.length
;
580 set_value_from_smbios_string( bios_key
, L
"BIOSVendor", bios
->vendor
, buf
, offset
, len
);
581 set_value_from_smbios_string( bios_key
, L
"BIOSVersion", bios
->version
, buf
, offset
, len
);
582 set_value_from_smbios_string( bios_key
, L
"BIOSReleaseDate", bios
->date
, buf
, offset
, len
);
584 if (bios
->hdr
.length
>= 0x18)
586 set_reg_value_dword( bios_key
, L
"BiosMajorRelease", bios
->system_bios_major_release
);
587 set_reg_value_dword( bios_key
, L
"BiosMinorRelease", bios
->system_bios_minor_release
);
588 set_reg_value_dword( bios_key
, L
"ECFirmwareMajorVersion", bios
->ec_firmware_major_release
);
589 set_reg_value_dword( bios_key
, L
"ECFirmwareMinorVersion", bios
->ec_firmware_minor_release
);
593 set_reg_value_dword( bios_key
, L
"BiosMajorRelease", 0xFF );
594 set_reg_value_dword( bios_key
, L
"BiosMinorRelease", 0xFF );
595 set_reg_value_dword( bios_key
, L
"ECFirmwareMajorVersion", 0xFF );
596 set_reg_value_dword( bios_key
, L
"ECFirmwareMinorVersion", 0xFF );
600 static void create_bios_system_values( HKEY bios_key
, const char *buf
, UINT len
)
602 const struct smbios_header
*hdr
;
603 const struct smbios_system
*system
;
606 if (!(hdr
= find_smbios_entry( SMBIOS_TYPE_SYSTEM
, buf
, len
))) return;
607 system
= (const struct smbios_system
*)hdr
;
608 offset
= (const char *)system
- buf
+ system
->hdr
.length
;
610 set_value_from_smbios_string( bios_key
, L
"SystemManufacturer", system
->vendor
, buf
, offset
, len
);
611 set_value_from_smbios_string( bios_key
, L
"SystemProductName", system
->product
, buf
, offset
, len
);
612 set_value_from_smbios_string( bios_key
, L
"SystemVersion", system
->version
, buf
, offset
, len
);
614 if (system
->hdr
.length
>= 0x1B)
616 set_value_from_smbios_string( bios_key
, L
"SystemSKU", system
->sku
, buf
, offset
, len
);
617 set_value_from_smbios_string( bios_key
, L
"SystemFamily", system
->family
, buf
, offset
, len
);
621 set_value_from_smbios_string( bios_key
, L
"SystemSKU", 0, buf
, offset
, len
);
622 set_value_from_smbios_string( bios_key
, L
"SystemFamily", 0, buf
, offset
, len
);
626 static void create_bios_key( HKEY system_key
)
632 if (RegCreateKeyExW( system_key
, L
"BIOS", 0, NULL
, REG_OPTION_VOLATILE
,
633 KEY_ALL_ACCESS
, NULL
, &bios_key
, NULL
))
636 len
= GetSystemFirmwareTable( RSMB
, 0, NULL
, 0 );
637 if (!(buf
= HeapAlloc( GetProcessHeap(), 0, len
))) goto done
;
638 len
= GetSystemFirmwareTable( RSMB
, 0, buf
, len
);
640 create_bios_baseboard_values( bios_key
, buf
, len
);
641 create_bios_bios_values( bios_key
, buf
, len
);
642 create_bios_system_values( bios_key
, buf
, len
);
645 HeapFree( GetProcessHeap(), 0, buf
);
646 RegCloseKey( bios_key
);
649 /* create the volatile hardware registry keys */
650 static void create_hardware_registry_keys(void)
653 HKEY hkey
, system_key
, cpu_key
, fpu_key
;
654 SYSTEM_CPU_INFORMATION sci
;
655 PROCESSOR_POWER_INFORMATION
* power_info
;
656 ULONG sizeof_power_info
= sizeof(PROCESSOR_POWER_INFORMATION
) * NtCurrentTeb()->Peb
->NumberOfProcessors
;
657 WCHAR id
[60], namestr
[49], vendorid
[13];
659 get_namestring( namestr
);
660 get_vendorid( vendorid
);
661 NtQuerySystemInformation( SystemCpuInformation
, &sci
, sizeof(sci
), NULL
);
663 power_info
= HeapAlloc( GetProcessHeap(), 0, sizeof_power_info
);
664 if (power_info
== NULL
)
666 if (NtPowerInformation( ProcessorInformation
, NULL
, 0, power_info
, sizeof_power_info
))
667 memset( power_info
, 0, sizeof_power_info
);
669 switch (sci
.ProcessorArchitecture
)
671 case PROCESSOR_ARCHITECTURE_ARM
:
672 case PROCESSOR_ARCHITECTURE_ARM64
:
673 swprintf( id
, ARRAY_SIZE(id
), L
"ARM Family %u Model %u Revision %u",
674 sci
.ProcessorLevel
, HIBYTE(sci
.ProcessorRevision
), LOBYTE(sci
.ProcessorRevision
) );
677 case PROCESSOR_ARCHITECTURE_AMD64
:
678 get_identifier( id
, ARRAY_SIZE(id
), !wcscmp(vendorid
, L
"AuthenticAMD") ? L
"AMD64" : L
"Intel64" );
681 case PROCESSOR_ARCHITECTURE_INTEL
:
683 get_identifier( id
, ARRAY_SIZE(id
), L
"x86" );
687 if (RegCreateKeyExW( HKEY_LOCAL_MACHINE
, L
"Hardware\\Description\\System", 0, NULL
,
688 REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &system_key
, NULL
))
690 HeapFree( GetProcessHeap(), 0, power_info
);
694 switch (sci
.ProcessorArchitecture
)
696 case PROCESSOR_ARCHITECTURE_ARM
:
697 case PROCESSOR_ARCHITECTURE_ARM64
:
698 set_reg_value( system_key
, L
"Identifier", L
"ARM processor family" );
701 case PROCESSOR_ARCHITECTURE_INTEL
:
702 case PROCESSOR_ARCHITECTURE_AMD64
:
704 set_reg_value( system_key
, L
"Identifier", L
"AT compatible" );
708 if (sci
.ProcessorArchitecture
== PROCESSOR_ARCHITECTURE_ARM
||
709 sci
.ProcessorArchitecture
== PROCESSOR_ARCHITECTURE_ARM64
||
710 RegCreateKeyExW( system_key
, L
"FloatingPointProcessor", 0, NULL
, REG_OPTION_VOLATILE
,
711 KEY_ALL_ACCESS
, NULL
, &fpu_key
, NULL
))
713 if (RegCreateKeyExW( system_key
, L
"CentralProcessor", 0, NULL
, REG_OPTION_VOLATILE
,
714 KEY_ALL_ACCESS
, NULL
, &cpu_key
, NULL
))
717 for (i
= 0; i
< NtCurrentTeb()->Peb
->NumberOfProcessors
; i
++)
721 swprintf( numW
, ARRAY_SIZE(numW
), L
"%u", i
);
722 if (!RegCreateKeyExW( cpu_key
, numW
, 0, NULL
, REG_OPTION_VOLATILE
,
723 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
725 RegSetValueExW( hkey
, L
"FeatureSet", 0, REG_DWORD
, (BYTE
*)&sci
.ProcessorFeatureBits
, sizeof(DWORD
) );
726 set_reg_value( hkey
, L
"Identifier", id
);
727 /* TODO: report ARM properly */
728 set_reg_value( hkey
, L
"ProcessorNameString", namestr
);
729 set_reg_value( hkey
, L
"VendorIdentifier", vendorid
);
730 RegSetValueExW( hkey
, L
"~MHz", 0, REG_DWORD
, (BYTE
*)&power_info
[i
].MaxMhz
, sizeof(DWORD
) );
733 if (sci
.ProcessorArchitecture
!= PROCESSOR_ARCHITECTURE_ARM
&&
734 sci
.ProcessorArchitecture
!= PROCESSOR_ARCHITECTURE_ARM64
&&
735 !RegCreateKeyExW( fpu_key
, numW
, 0, NULL
, REG_OPTION_VOLATILE
,
736 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
738 set_reg_value( hkey
, L
"Identifier", id
);
743 create_bios_key( system_key
);
745 RegCloseKey( fpu_key
);
746 RegCloseKey( cpu_key
);
747 RegCloseKey( system_key
);
748 HeapFree( GetProcessHeap(), 0, power_info
);
752 /* create the DynData registry keys */
753 static void create_dynamic_registry_keys(void)
757 if (!RegCreateKeyExW( HKEY_DYN_DATA
, L
"PerfStats\\StatData", 0, NULL
, 0, KEY_WRITE
, NULL
, &key
, NULL
))
759 if (!RegCreateKeyExW( HKEY_DYN_DATA
, L
"Config Manager\\Enum", 0, NULL
, 0, KEY_WRITE
, NULL
, &key
, NULL
))
763 /* create the platform-specific environment registry keys */
764 static void create_environment_registry_keys( void )
767 SYSTEM_CPU_INFORMATION sci
;
768 WCHAR buffer
[60], vendorid
[13];
769 const WCHAR
*arch
, *parch
;
771 if (RegCreateKeyW( HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Control\\Session Manager\\Environment", &env_key
)) return;
773 get_vendorid( vendorid
);
774 NtQuerySystemInformation( SystemCpuInformation
, &sci
, sizeof(sci
), NULL
);
776 swprintf( buffer
, ARRAY_SIZE(buffer
), L
"%u", NtCurrentTeb()->Peb
->NumberOfProcessors
);
777 set_reg_value( env_key
, L
"NUMBER_OF_PROCESSORS", buffer
);
779 switch (sci
.ProcessorArchitecture
)
781 case PROCESSOR_ARCHITECTURE_AMD64
:
783 parch
= !wcscmp(vendorid
, L
"AuthenticAMD") ? L
"AMD64" : L
"Intel64";
786 case PROCESSOR_ARCHITECTURE_INTEL
:
788 arch
= parch
= L
"x86";
791 set_reg_value( env_key
, L
"PROCESSOR_ARCHITECTURE", arch
);
793 switch (sci
.ProcessorArchitecture
)
795 case PROCESSOR_ARCHITECTURE_ARM
:
796 case PROCESSOR_ARCHITECTURE_ARM64
:
797 swprintf( buffer
, ARRAY_SIZE(buffer
), L
"ARM Family %u Model %u Revision %u",
798 sci
.ProcessorLevel
, HIBYTE(sci
.ProcessorRevision
), LOBYTE(sci
.ProcessorRevision
) );
801 case PROCESSOR_ARCHITECTURE_AMD64
:
802 case PROCESSOR_ARCHITECTURE_INTEL
:
804 get_identifier( buffer
, ARRAY_SIZE(buffer
), parch
);
805 lstrcatW( buffer
, L
", " );
806 lstrcatW( buffer
, vendorid
);
809 set_reg_value( env_key
, L
"PROCESSOR_IDENTIFIER", buffer
);
811 swprintf( buffer
, ARRAY_SIZE(buffer
), L
"%u", sci
.ProcessorLevel
);
812 set_reg_value( env_key
, L
"PROCESSOR_LEVEL", buffer
);
814 swprintf( buffer
, ARRAY_SIZE(buffer
), L
"%04x", sci
.ProcessorRevision
);
815 set_reg_value( env_key
, L
"PROCESSOR_REVISION", buffer
);
817 RegCloseKey( env_key
);
820 /* create the ComputerName registry keys */
821 static void create_computer_name_keys(void)
823 struct addrinfo hints
= {0}, *res
;
824 char *dot
, buffer
[256], *name
= buffer
;
827 if (gethostname( buffer
, sizeof(buffer
) )) return;
828 hints
.ai_flags
= AI_CANONNAME
;
829 if (!getaddrinfo( buffer
, NULL
, &hints
, &res
) &&
830 res
->ai_canonname
&& strcasecmp(res
->ai_canonname
, "localhost") != 0)
831 name
= res
->ai_canonname
;
832 dot
= strchr( name
, '.' );
834 else dot
= name
+ strlen(name
);
835 SetComputerNameExA( ComputerNamePhysicalDnsDomain
, dot
);
836 SetComputerNameExA( ComputerNamePhysicalDnsHostname
, name
);
837 if (name
!= buffer
) freeaddrinfo( res
);
839 if (RegOpenKeyW( HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Control\\ComputerName", &key
))
842 if (!RegOpenKeyW( key
, L
"ComputerName", &subkey
))
844 DWORD type
, size
= sizeof(buffer
);
846 if (RegQueryValueExW( subkey
, L
"ComputerName", NULL
, &type
, (BYTE
*)buffer
, &size
)) size
= 0;
847 RegCloseKey( subkey
);
848 if (size
&& !RegCreateKeyExW( key
, L
"ActiveComputerName", 0, NULL
, REG_OPTION_VOLATILE
,
849 KEY_ALL_ACCESS
, NULL
, &subkey
, NULL
))
851 RegSetValueExW( subkey
, L
"ComputerName", 0, type
, (const BYTE
*)buffer
, size
);
852 RegCloseKey( subkey
);
858 static void create_volatile_environment_registry_key(void)
860 WCHAR path
[MAX_PATH
];
861 WCHAR computername
[MAX_COMPUTERNAME_LENGTH
+ 1 + 2];
866 if (RegCreateKeyExW( HKEY_CURRENT_USER
, L
"Volatile Environment", 0, NULL
, REG_OPTION_VOLATILE
,
867 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
870 hr
= SHGetFolderPathW( NULL
, CSIDL_APPDATA
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, path
);
871 if (SUCCEEDED(hr
)) set_reg_value( hkey
, L
"APPDATA", path
);
873 set_reg_value( hkey
, L
"CLIENTNAME", L
"Console" );
875 /* Write the profile path's drive letter and directory components into
876 * HOMEDRIVE and HOMEPATH respectively. */
877 hr
= SHGetFolderPathW( NULL
, CSIDL_PROFILE
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, path
);
880 set_reg_value( hkey
, L
"USERPROFILE", path
);
881 set_reg_value( hkey
, L
"HOMEPATH", path
+ 2 );
883 set_reg_value( hkey
, L
"HOMEDRIVE", path
);
886 size
= ARRAY_SIZE(path
);
887 if (GetUserNameW( path
, &size
)) set_reg_value( hkey
, L
"USERNAME", path
);
889 set_reg_value( hkey
, L
"HOMESHARE", L
"" );
891 hr
= SHGetFolderPathW( NULL
, CSIDL_LOCAL_APPDATA
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, path
);
893 set_reg_value( hkey
, L
"LOCALAPPDATA", path
);
895 size
= ARRAY_SIZE(computername
) - 2;
896 if (GetComputerNameW(&computername
[2], &size
))
898 set_reg_value( hkey
, L
"USERDOMAIN", &computername
[2] );
899 computername
[0] = computername
[1] = '\\';
900 set_reg_value( hkey
, L
"LOGONSERVER", computername
);
903 set_reg_value( hkey
, L
"SESSIONNAME", L
"Console" );
907 /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
908 * Returns FALSE if there was an error, or otherwise if all is ok.
910 static BOOL
wininit(void)
912 WCHAR initial_buffer
[1024];
913 WCHAR
*str
, *buffer
= initial_buffer
;
914 DWORD size
= ARRAY_SIZE(initial_buffer
);
919 if (!(res
= GetPrivateProfileSectionW( L
"rename", buffer
, size
, L
"wininit.ini" ))) return TRUE
;
920 if (res
< size
- 2) break;
921 if (buffer
!= initial_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
923 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) return FALSE
;
926 for (str
= buffer
; *str
; str
+= lstrlenW(str
) + 1)
930 if (*str
== ';') continue; /* comment */
931 if (!(value
= wcschr( str
, '=' ))) continue;
933 /* split the line into key and value */
936 if (!lstrcmpiW( L
"NUL", str
))
938 WINE_TRACE("Deleting file %s\n", wine_dbgstr_w(value
) );
939 if( !DeleteFileW( value
) )
940 WINE_WARN("Error deleting file %s\n", wine_dbgstr_w(value
) );
944 WINE_TRACE("Renaming file %s to %s\n", wine_dbgstr_w(value
), wine_dbgstr_w(str
) );
946 if( !MoveFileExW(value
, str
, MOVEFILE_COPY_ALLOWED
| MOVEFILE_REPLACE_EXISTING
) )
947 WINE_WARN("Error renaming %s to %s\n", wine_dbgstr_w(value
), wine_dbgstr_w(str
) );
952 if (buffer
!= initial_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
954 if( !MoveFileExW( L
"wininit.ini", L
"wininit.bak", MOVEFILE_REPLACE_EXISTING
) )
956 WINE_ERR("Couldn't rename wininit.ini, error %ld\n", GetLastError() );
964 static void pendingRename(void)
967 const WCHAR
*src
=NULL
, *dst
=NULL
;
971 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, L
"System\\CurrentControlSet\\Control\\Session Manager",
972 0, KEY_ALL_ACCESS
, &hSession
))
975 if (RegQueryValueExW( hSession
, L
"PendingFileRenameOperations", NULL
, NULL
, NULL
, &dataLength
))
977 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, dataLength
))) goto end
;
979 if (RegQueryValueExW( hSession
, L
"PendingFileRenameOperations", NULL
, NULL
,
980 (LPBYTE
)buffer
, &dataLength
))
983 /* Make sure that the data is long enough and ends with two NULLs. This
984 * simplifies the code later on.
986 if( dataLength
<2*sizeof(buffer
[0]) ||
987 buffer
[dataLength
/sizeof(buffer
[0])-1]!='\0' ||
988 buffer
[dataLength
/sizeof(buffer
[0])-2]!='\0' )
991 for( src
=buffer
; (src
-buffer
)*sizeof(src
[0])<dataLength
&& *src
!='\0';
992 src
=dst
+lstrlenW(dst
)+1 )
996 dst
=src
+lstrlenW(src
)+1;
998 /* We need to skip the \??\ header */
999 if( src
[0]=='\\' && src
[1]=='?' && src
[2]=='?' && src
[3]=='\\' )
1004 dwFlags
|=MOVEFILE_REPLACE_EXISTING
;
1008 if( dst
[0]=='\\' && dst
[1]=='?' && dst
[2]=='?' && dst
[3]=='\\' )
1013 /* Rename the file */
1014 MoveFileExW( src
, dst
, dwFlags
);
1017 /* Delete the file or directory */
1018 if (!RemoveDirectoryW( src
) && GetLastError() == ERROR_DIRECTORY
) DeleteFileW( src
);
1022 RegDeleteValueW(hSession
, L
"PendingFileRenameOperations");
1025 HeapFree(GetProcessHeap(), 0, buffer
);
1026 RegCloseKey( hSession
);
1029 #define INVALID_RUNCMD_RETURN -1
1031 * This function runs the specified command in the specified dir.
1032 * [in,out] cmdline - the command line to run. The function may change the passed buffer.
1033 * [in] dir - the dir to run the command in. If it is NULL, then the current dir is used.
1034 * [in] wait - whether to wait for the run program to finish before returning.
1035 * [in] minimized - Whether to ask the program to run minimized.
1038 * If running the process failed, returns INVALID_RUNCMD_RETURN. Use GetLastError to get the error code.
1039 * If wait is FALSE - returns 0 if successful.
1040 * If wait is TRUE - returns the program's return value.
1042 static DWORD
runCmd(LPWSTR cmdline
, LPCWSTR dir
, BOOL wait
, BOOL minimized
)
1045 PROCESS_INFORMATION info
;
1048 memset(&si
, 0, sizeof(si
));
1052 si
.dwFlags
=STARTF_USESHOWWINDOW
;
1053 si
.wShowWindow
=SW_MINIMIZE
;
1055 memset(&info
, 0, sizeof(info
));
1057 if( !CreateProcessW(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, dir
, &si
, &info
) )
1059 WINE_WARN("Failed to run command %s (%ld)\n", wine_dbgstr_w(cmdline
), GetLastError() );
1060 return INVALID_RUNCMD_RETURN
;
1063 WINE_TRACE("Successfully ran command %s - Created process handle %p\n",
1064 wine_dbgstr_w(cmdline
), info
.hProcess
);
1067 { /* wait for the process to exit */
1068 WaitForSingleObject(info
.hProcess
, INFINITE
);
1069 GetExitCodeProcess(info
.hProcess
, &exit_code
);
1072 CloseHandle( info
.hThread
);
1073 CloseHandle( info
.hProcess
);
1078 static void process_run_key( HKEY key
, const WCHAR
*keyname
, BOOL
delete, BOOL synchronous
)
1082 DWORD disp
, i
, max_cmdline
= 0, max_value
= 0;
1083 WCHAR
*cmdline
= NULL
, *value
= NULL
;
1085 if (RegCreateKeyExW( key
, keyname
, 0, NULL
, 0, delete ? KEY_ALL_ACCESS
: KEY_READ
, NULL
, &runkey
, &disp
))
1088 if (disp
== REG_CREATED_NEW_KEY
)
1091 if (RegQueryInfoKeyW( runkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &i
, &max_value
, &max_cmdline
, NULL
, NULL
))
1096 WINE_TRACE( "No commands to execute.\n" );
1099 if (!(cmdline
= HeapAlloc( GetProcessHeap(), 0, max_cmdline
)))
1101 WINE_ERR( "Couldn't allocate memory for the commands to be executed.\n" );
1104 if (!(value
= HeapAlloc( GetProcessHeap(), 0, ++max_value
* sizeof(*value
) )))
1106 WINE_ERR( "Couldn't allocate memory for the value names.\n" );
1112 DWORD len
= max_value
, len_data
= max_cmdline
, type
;
1114 if ((res
= RegEnumValueW( runkey
, --i
, value
, &len
, 0, &type
, (BYTE
*)cmdline
, &len_data
)))
1116 WINE_ERR( "Couldn't read value %lu (%ld).\n", i
, res
);
1119 if (delete && (res
= RegDeleteValueW( runkey
, value
)))
1121 WINE_ERR( "Couldn't delete value %lu (%ld). Running command anyways.\n", i
, res
);
1125 WINE_ERR( "Incorrect type of value %lu (%lu).\n", i
, type
);
1128 if (runCmd( cmdline
, NULL
, synchronous
, FALSE
) == INVALID_RUNCMD_RETURN
)
1130 WINE_ERR( "Error running cmd %s (%lu).\n", wine_dbgstr_w(cmdline
), GetLastError() );
1132 WINE_TRACE( "Done processing cmd %lu.\n", i
);
1136 HeapFree( GetProcessHeap(), 0, value
);
1137 HeapFree( GetProcessHeap(), 0, cmdline
);
1138 RegCloseKey( runkey
);
1139 WINE_TRACE( "Done.\n" );
1143 * Process a "Run" type registry key.
1144 * hkRoot is the HKEY from which "Software\Microsoft\Windows\CurrentVersion" is
1146 * szKeyName is the key holding the actual entries.
1147 * bDelete tells whether we should delete each value right before executing it.
1148 * bSynchronous tells whether we should wait for the prog to complete before
1149 * going on to the next prog.
1151 static void ProcessRunKeys( HKEY root
, const WCHAR
*keyname
, BOOL
delete, BOOL synchronous
)
1155 if (root
== HKEY_LOCAL_MACHINE
)
1157 WINE_TRACE( "Processing %s entries under HKLM.\n", wine_dbgstr_w(keyname
) );
1158 if (!RegCreateKeyExW( root
, L
"Software\\Microsoft\\Windows\\CurrentVersion",
1159 0, NULL
, 0, KEY_READ
, NULL
, &key
, NULL
))
1161 process_run_key( key
, keyname
, delete, synchronous
);
1164 if (is_64bit
&& !RegCreateKeyExW( root
, L
"Software\\Microsoft\\Windows\\CurrentVersion",
1165 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &key
, NULL
))
1167 process_run_key( key
, keyname
, delete, synchronous
);
1173 WINE_TRACE( "Processing %s entries under HKCU.\n", wine_dbgstr_w(keyname
) );
1174 if (!RegCreateKeyExW( root
, L
"Software\\Microsoft\\Windows\\CurrentVersion",
1175 0, NULL
, 0, KEY_READ
, NULL
, &key
, NULL
))
1177 process_run_key( key
, keyname
, delete, synchronous
);
1184 * WFP is Windows File Protection, in NT5 and Windows 2000 it maintains a cache
1185 * of known good dlls and scans through and replaces corrupted DLLs with these
1186 * known good versions. The only programs that should install into this dll
1187 * cache are Windows Updates and IE (which is treated like a Windows Update)
1189 * Implementing this allows installing ie in win2k mode to actually install the
1190 * system dlls that we expect and need
1192 static int ProcessWindowsFileProtection(void)
1194 WIN32_FIND_DATAW finddata
;
1199 LPWSTR dllcache
= NULL
;
1201 if (!RegOpenKeyW( HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", &hkey
))
1204 if (!RegQueryValueExW( hkey
, L
"SFCDllCacheDir", 0, NULL
, NULL
, &sz
))
1206 sz
+= sizeof(WCHAR
);
1207 dllcache
= HeapAlloc(GetProcessHeap(),0,sz
+ sizeof(L
"\\*"));
1208 RegQueryValueExW( hkey
, L
"SFCDllCacheDir", 0, NULL
, (LPBYTE
)dllcache
, &sz
);
1209 lstrcatW( dllcache
, L
"\\*" );
1216 DWORD sz
= GetSystemDirectoryW( NULL
, 0 );
1217 dllcache
= HeapAlloc( GetProcessHeap(), 0, sz
* sizeof(WCHAR
) + sizeof(L
"\\dllcache\\*"));
1218 GetSystemDirectoryW( dllcache
, sz
);
1219 lstrcatW( dllcache
, L
"\\dllcache\\*" );
1222 find_handle
= FindFirstFileW(dllcache
,&finddata
);
1223 dllcache
[ lstrlenW(dllcache
) - 2] = 0; /* strip off wildcard */
1224 find_rc
= find_handle
!= INVALID_HANDLE_VALUE
;
1227 WCHAR targetpath
[MAX_PATH
];
1228 WCHAR currentpath
[MAX_PATH
];
1231 WCHAR tempfile
[MAX_PATH
];
1233 if (wcscmp(finddata
.cFileName
,L
".") == 0 || wcscmp(finddata
.cFileName
,L
"..") == 0)
1235 find_rc
= FindNextFileW(find_handle
,&finddata
);
1241 VerFindFileW(VFFF_ISSHAREDFILE
, finddata
.cFileName
, windowsdir
,
1242 windowsdir
, currentpath
, &sz
, targetpath
, &sz2
);
1244 rc
= VerInstallFileW(0, finddata
.cFileName
, finddata
.cFileName
,
1245 dllcache
, targetpath
, currentpath
, tempfile
, &sz
);
1246 if (rc
!= ERROR_SUCCESS
)
1248 WINE_WARN("WFP: %s error 0x%lx\n",wine_dbgstr_w(finddata
.cFileName
),rc
);
1249 DeleteFileW(tempfile
);
1252 /* now delete the source file so that we don't try to install it over and over again */
1253 lstrcpynW( targetpath
, dllcache
, MAX_PATH
- 1 );
1254 sz
= lstrlenW( targetpath
);
1255 targetpath
[sz
++] = '\\';
1256 lstrcpynW( targetpath
+ sz
, finddata
.cFileName
, MAX_PATH
- sz
);
1257 if (!DeleteFileW( targetpath
))
1258 WINE_WARN( "failed to delete %s: error %lu\n", wine_dbgstr_w(targetpath
), GetLastError() );
1260 find_rc
= FindNextFileW(find_handle
,&finddata
);
1262 FindClose(find_handle
);
1263 HeapFree(GetProcessHeap(),0,dllcache
);
1267 static BOOL
start_services_process(void)
1269 static const WCHAR svcctl_started_event
[] = SVCCTL_STARTED_EVENT
;
1270 PROCESS_INFORMATION pi
;
1271 STARTUPINFOW si
= { sizeof(si
) };
1272 HANDLE wait_handles
[2];
1274 if (!CreateProcessW(L
"C:\\windows\\system32\\services.exe", NULL
,
1275 NULL
, NULL
, TRUE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
))
1277 WINE_ERR("Couldn't start services.exe: error %lu\n", GetLastError());
1280 CloseHandle(pi
.hThread
);
1282 wait_handles
[0] = CreateEventW(NULL
, TRUE
, FALSE
, svcctl_started_event
);
1283 wait_handles
[1] = pi
.hProcess
;
1285 /* wait for the event to become available or the process to exit */
1286 if ((WaitForMultipleObjects(2, wait_handles
, FALSE
, INFINITE
)) == WAIT_OBJECT_0
+ 1)
1289 GetExitCodeProcess(pi
.hProcess
, &exit_code
);
1290 WINE_ERR("Unexpected termination of services.exe - exit code %ld\n", exit_code
);
1291 CloseHandle(pi
.hProcess
);
1292 CloseHandle(wait_handles
[0]);
1296 CloseHandle(pi
.hProcess
);
1297 CloseHandle(wait_handles
[0]);
1301 static INT_PTR CALLBACK
wait_dlgproc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1308 WCHAR
*buffer
, text
[1024];
1309 const WCHAR
*name
= (WCHAR
*)lp
;
1310 HICON icon
= LoadImageW( 0, (LPCWSTR
)IDI_WINLOGO
, IMAGE_ICON
, 48, 48, LR_SHARED
);
1311 SendDlgItemMessageW( hwnd
, IDC_WAITICON
, STM_SETICON
, (WPARAM
)icon
, 0 );
1312 SendDlgItemMessageW( hwnd
, IDC_WAITTEXT
, WM_GETTEXT
, 1024, (LPARAM
)text
);
1313 len
= lstrlenW(text
) + lstrlenW(name
) + 1;
1314 buffer
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1315 swprintf( buffer
, len
, text
, name
);
1316 SendDlgItemMessageW( hwnd
, IDC_WAITTEXT
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
1317 HeapFree( GetProcessHeap(), 0, buffer
);
1324 static HWND
show_wait_window(void)
1326 HWND hwnd
= CreateDialogParamW( GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_WAITDLG
), 0,
1327 wait_dlgproc
, (LPARAM
)prettyprint_configdir() );
1328 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1332 static HANDLE
start_rundll32( const WCHAR
*inf_path
, const WCHAR
*install
, WORD machine
)
1334 WCHAR app
[MAX_PATH
+ ARRAY_SIZE(L
"\\rundll32.exe" )];
1336 PROCESS_INFORMATION pi
;
1340 memset( &si
, 0, sizeof(si
) );
1343 if (!GetSystemWow64Directory2W( app
, MAX_PATH
, machine
)) return 0;
1344 lstrcatW( app
, L
"\\rundll32.exe" );
1345 TRACE( "machine %x starting %s\n", machine
, debugstr_w(app
) );
1347 len
= lstrlenW(app
) + ARRAY_SIZE(L
" setupapi,InstallHinfSection DefaultInstall 128 ") + lstrlenW(inf_path
);
1349 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
1350 swprintf( buffer
, len
, L
"%s setupapi,InstallHinfSection %s 128 %s", app
, install
, inf_path
);
1352 if (CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
1353 CloseHandle( pi
.hThread
);
1357 HeapFree( GetProcessHeap(), 0, buffer
);
1361 static void install_root_pnp_devices(void)
1366 const char *hardware_id
;
1367 const char *infpath
;
1371 {"root\\wine\\winebus", "root\\winebus\0", "C:\\windows\\inf\\winebus.inf"},
1372 {"root\\wine\\wineusb", "root\\wineusb\0", "C:\\windows\\inf\\wineusb.inf"},
1374 SP_DEVINFO_DATA device
= {sizeof(device
)};
1378 if ((set
= SetupDiCreateDeviceInfoList( NULL
, NULL
)) == INVALID_HANDLE_VALUE
)
1380 WINE_ERR("Failed to create device info list, error %#lx.\n", GetLastError());
1384 for (i
= 0; i
< ARRAY_SIZE(root_devices
); ++i
)
1386 if (!SetupDiCreateDeviceInfoA( set
, root_devices
[i
].name
, &GUID_NULL
, NULL
, NULL
, 0, &device
))
1388 if (GetLastError() != ERROR_DEVINST_ALREADY_EXISTS
)
1389 WINE_ERR("Failed to create device %s, error %#lx.\n", debugstr_a(root_devices
[i
].name
), GetLastError());
1393 if (!SetupDiSetDeviceRegistryPropertyA(set
, &device
, SPDRP_HARDWAREID
,
1394 (const BYTE
*)root_devices
[i
].hardware_id
, (strlen(root_devices
[i
].hardware_id
) + 2) * sizeof(WCHAR
)))
1396 WINE_ERR("Failed to set hardware id for %s, error %#lx.\n", debugstr_a(root_devices
[i
].name
), GetLastError());
1400 if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE
, set
, &device
))
1402 WINE_ERR("Failed to register device %s, error %#lx.\n", debugstr_a(root_devices
[i
].name
), GetLastError());
1406 if (!UpdateDriverForPlugAndPlayDevicesA(NULL
, root_devices
[i
].hardware_id
, root_devices
[i
].infpath
, 0, NULL
))
1407 WINE_ERR("Failed to install drivers for %s, error %#lx.\n", debugstr_a(root_devices
[i
].name
), GetLastError());
1410 SetupDiDestroyDeviceInfoList(set
);
1413 static void update_user_profile(void)
1415 char token_buf
[sizeof(TOKEN_USER
) + sizeof(SID
) + sizeof(DWORD
) * SID_MAX_SUB_AUTHORITIES
];
1417 WCHAR profile
[MAX_PATH
], *sid
;
1419 HKEY hkey
, profile_hkey
;
1421 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ
, &token
))
1424 size
= sizeof(token_buf
);
1425 GetTokenInformation(token
, TokenUser
, token_buf
, size
, &size
);
1428 ConvertSidToStringSidW(((TOKEN_USER
*)token_buf
)->User
.Sid
, &sid
);
1430 if (!RegCreateKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
1431 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
1433 if (!RegCreateKeyExW(hkey
, sid
, 0, NULL
, 0,
1434 KEY_ALL_ACCESS
, NULL
, &profile_hkey
, NULL
))
1437 if (SHGetSpecialFolderPathW(NULL
, profile
, CSIDL_PROFILE
, TRUE
))
1438 set_reg_value(profile_hkey
, L
"ProfileImagePath", profile
);
1439 RegSetValueExW( profile_hkey
, L
"Flags", 0, REG_DWORD
, (const BYTE
*)&flags
, sizeof(flags
) );
1440 RegCloseKey(profile_hkey
);
1449 /* execute rundll32 on the wine.inf file if necessary */
1450 static void update_wineprefix( BOOL force
)
1452 const WCHAR
*config_dir
= _wgetenv( L
"WINECONFIGDIR" );
1453 WCHAR
*inf_path
= get_wine_inf_path();
1459 WINE_MESSAGE( "wine: failed to update %s, wine.inf not found\n", debugstr_w( config_dir
));
1462 if ((fd
= _wopen( inf_path
, O_RDONLY
)) == -1)
1464 WINE_MESSAGE( "wine: failed to update %s with %s: %s\n",
1465 debugstr_w(config_dir
), debugstr_w(inf_path
), strerror(errno
) );
1471 if (update_timestamp( config_dir
, st
.st_mtime
) || force
)
1477 if (NtQuerySystemInformationEx( SystemSupportedProcessorArchitectures
, &process
, sizeof(process
),
1478 machines
, sizeof(machines
), NULL
)) machines
[0] = 0;
1480 if ((process
= start_rundll32( inf_path
, L
"PreInstall", IMAGE_FILE_MACHINE_TARGET_HOST
)))
1482 HWND hwnd
= show_wait_window();
1486 DWORD res
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, INFINITE
, QS_ALLINPUT
);
1487 if (res
== WAIT_OBJECT_0
)
1489 CloseHandle( process
);
1490 if (!machines
[count
]) break;
1491 if (HIWORD(machines
[count
]) & 4 /* native machine */)
1492 process
= start_rundll32( inf_path
, L
"DefaultInstall", IMAGE_FILE_MACHINE_TARGET_HOST
);
1494 process
= start_rundll32( inf_path
, L
"Wow64Install", LOWORD(machines
[count
]) );
1496 if (!process
) break;
1498 else while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageW( &msg
);
1500 DestroyWindow( hwnd
);
1502 install_root_pnp_devices();
1503 update_user_profile();
1505 WINE_MESSAGE( "wine: configuration in %s has been updated.\n", debugstr_w(prettyprint_configdir()) );
1509 HeapFree( GetProcessHeap(), 0, inf_path
);
1512 /* Process items in the StartUp group of the user's Programs under the Start Menu. Some installers put
1513 * shell links here to restart themselves after boot. */
1514 static BOOL
ProcessStartupItems(void)
1518 IShellFolder
*psfDesktop
= NULL
, *psfStartup
= NULL
;
1519 LPITEMIDLIST pidlStartup
= NULL
, pidlItem
;
1521 IEnumIDList
*iEnumList
= NULL
;
1523 WCHAR wszCommand
[MAX_PATH
];
1525 WINE_TRACE("Processing items in the StartUp folder.\n");
1527 hr
= SHGetDesktopFolder(&psfDesktop
);
1530 WINE_ERR("Couldn't get desktop folder.\n");
1534 hr
= SHGetSpecialFolderLocation(NULL
, CSIDL_STARTUP
, &pidlStartup
);
1537 WINE_TRACE("Couldn't get StartUp folder location.\n");
1541 hr
= IShellFolder_BindToObject(psfDesktop
, pidlStartup
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfStartup
);
1544 WINE_TRACE("Couldn't bind IShellFolder to StartUp folder.\n");
1548 hr
= IShellFolder_EnumObjects(psfStartup
, NULL
, SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &iEnumList
);
1551 WINE_TRACE("Unable to enumerate StartUp objects.\n");
1555 while (IEnumIDList_Next(iEnumList
, 1, &pidlItem
, &NumPIDLs
) == S_OK
&&
1558 hr
= IShellFolder_GetDisplayNameOf(psfStartup
, pidlItem
, SHGDN_FORPARSING
, &strret
);
1560 WINE_TRACE("Unable to get display name of enumeration item.\n");
1563 hr
= StrRetToBufW(&strret
, pidlItem
, wszCommand
, MAX_PATH
);
1565 WINE_TRACE("Unable to parse display name.\n");
1570 hinst
= ShellExecuteW(NULL
, NULL
, wszCommand
, NULL
, NULL
, SW_SHOWNORMAL
);
1571 if (PtrToUlong(hinst
) <= 32)
1572 WINE_WARN("Error %p executing command %s.\n", hinst
, wine_dbgstr_w(wszCommand
));
1579 /* Return success */
1583 if (iEnumList
) IEnumIDList_Release(iEnumList
);
1584 if (psfStartup
) IShellFolder_Release(psfStartup
);
1585 if (pidlStartup
) ILFree(pidlStartup
);
1590 static void usage( int status
)
1592 WINE_MESSAGE( "Usage: wineboot [options]\n" );
1593 WINE_MESSAGE( "Options;\n" );
1594 WINE_MESSAGE( " -h,--help Display this help message\n" );
1595 WINE_MESSAGE( " -e,--end-session End the current session cleanly\n" );
1596 WINE_MESSAGE( " -f,--force Force exit for processes that don't exit cleanly\n" );
1597 WINE_MESSAGE( " -i,--init Perform initialization for first Wine instance\n" );
1598 WINE_MESSAGE( " -k,--kill Kill running processes without any cleanup\n" );
1599 WINE_MESSAGE( " -r,--restart Restart only, don't do normal startup operations\n" );
1600 WINE_MESSAGE( " -s,--shutdown Shutdown only, don't reboot\n" );
1601 WINE_MESSAGE( " -u,--update Update the wineprefix directory\n" );
1605 int __cdecl
main( int argc
, char *argv
[] )
1607 /* First, set the current directory to SystemRoot */
1609 BOOL end_session
, force
, init
, kill
, restart
, shutdown
, update
;
1611 OBJECT_ATTRIBUTES attr
;
1612 UNICODE_STRING nameW
;
1615 end_session
= force
= init
= kill
= restart
= shutdown
= update
= FALSE
;
1616 GetWindowsDirectoryW( windowsdir
, MAX_PATH
);
1617 if( !SetCurrentDirectoryW( windowsdir
) )
1618 WINE_ERR("Cannot set the dir to %s (%ld)\n", wine_dbgstr_w(windowsdir
), GetLastError() );
1620 if (IsWow64Process( GetCurrentProcess(), &is_wow64
) && is_wow64
)
1623 PROCESS_INFORMATION pi
;
1624 WCHAR filename
[MAX_PATH
];
1628 memset( &si
, 0, sizeof(si
) );
1630 GetSystemDirectoryW( filename
, MAX_PATH
);
1631 wcscat( filename
, L
"\\wineboot.exe" );
1633 Wow64DisableWow64FsRedirection( &redir
);
1634 if (CreateProcessW( filename
, GetCommandLineW(), NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
1636 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename
) );
1637 WaitForSingleObject( pi
.hProcess
, INFINITE
);
1638 GetExitCodeProcess( pi
.hProcess
, &exit_code
);
1639 ExitProcess( exit_code
);
1641 else WINE_ERR( "failed to restart 64-bit %s, err %ld\n", wine_dbgstr_w(filename
), GetLastError() );
1642 Wow64RevertWow64FsRedirection( redir
);
1645 for (i
= 1; i
< argc
; i
++)
1647 if (argv
[i
][0] != '-') continue;
1648 if (argv
[i
][1] == '-')
1650 if (!strcmp( argv
[i
], "--help" )) usage( 0 );
1651 else if (!strcmp( argv
[i
], "--end-session" )) end_session
= TRUE
;
1652 else if (!strcmp( argv
[i
], "--force" )) force
= TRUE
;
1653 else if (!strcmp( argv
[i
], "--init" )) init
= TRUE
;
1654 else if (!strcmp( argv
[i
], "--kill" )) kill
= TRUE
;
1655 else if (!strcmp( argv
[i
], "--restart" )) restart
= TRUE
;
1656 else if (!strcmp( argv
[i
], "--shutdown" )) shutdown
= TRUE
;
1657 else if (!strcmp( argv
[i
], "--update" )) update
= TRUE
;
1661 for (j
= 1; argv
[i
][j
]; j
++)
1665 case 'e': end_session
= TRUE
; break;
1666 case 'f': force
= TRUE
; break;
1667 case 'i': init
= TRUE
; break;
1668 case 'k': kill
= TRUE
; break;
1669 case 'r': restart
= TRUE
; break;
1670 case 's': shutdown
= TRUE
; break;
1671 case 'u': update
= TRUE
; break;
1672 case 'h': usage(0); break;
1673 default: usage(1); break;
1682 if (!shutdown_all_desktops( force
)) return 1;
1684 else if (!shutdown_close_windows( force
)) return 1;
1687 if (kill
) kill_processes( shutdown
);
1689 if (shutdown
) return 0;
1691 /* create event to be inherited by services.exe */
1692 InitializeObjectAttributes( &attr
, &nameW
, OBJ_OPENIF
| OBJ_INHERIT
, 0, NULL
);
1693 RtlInitUnicodeString( &nameW
, L
"\\KernelObjects\\__wineboot_event" );
1694 NtCreateEvent( &event
, EVENT_ALL_ACCESS
, &attr
, NotificationEvent
, 0 );
1696 ResetEvent( event
); /* in case this is a restart */
1698 create_user_shared_data();
1699 create_hardware_registry_keys();
1700 create_dynamic_registry_keys();
1701 create_environment_registry_keys();
1702 create_computer_name_keys();
1706 ProcessWindowsFileProtection();
1707 ProcessRunKeys( HKEY_LOCAL_MACHINE
, L
"RunServicesOnce", TRUE
, FALSE
);
1709 if (init
|| (kill
&& !restart
))
1711 ProcessRunKeys( HKEY_LOCAL_MACHINE
, L
"RunServices", FALSE
, FALSE
);
1712 start_services_process();
1714 if (init
|| update
) update_wineprefix( update
);
1716 create_volatile_environment_registry_key();
1718 ProcessRunKeys( HKEY_LOCAL_MACHINE
, L
"RunOnce", TRUE
, TRUE
);
1720 if (!init
&& !restart
)
1722 ProcessRunKeys( HKEY_LOCAL_MACHINE
, L
"Run", FALSE
, FALSE
);
1723 ProcessRunKeys( HKEY_CURRENT_USER
, L
"Run", FALSE
, FALSE
);
1724 ProcessStartupItems();
1727 WINE_TRACE("Operation done\n");