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).
55 #include "wine/port.h"
58 #define WIN32_LEAN_AND_MEAN
67 #ifdef HAVE_SYS_STAT_H
68 # include <sys/stat.h>
75 #include <wine/svcctl.h>
76 #include <wine/unicode.h>
77 #include <wine/library.h>
78 #include <wine/debug.h>
86 WINE_DEFAULT_DEBUG_CHANNEL(wineboot
);
88 extern BOOL
shutdown_close_windows( BOOL force
);
89 extern BOOL
shutdown_all_desktops( BOOL force
);
90 extern void kill_processes( BOOL kill_desktop
);
92 static WCHAR windowsdir
[MAX_PATH
];
94 /* retrieve the (unix) path to the wine.inf file */
95 static char *get_wine_inf_path(void)
97 const char *build_dir
, *data_dir
;
100 if ((data_dir
= wine_get_data_dir()))
102 if (!(name
= HeapAlloc( GetProcessHeap(), 0, strlen(data_dir
) + sizeof("/wine.inf") )))
104 strcpy( name
, data_dir
);
105 strcat( name
, "/wine.inf" );
107 else if ((build_dir
= wine_get_build_dir()))
109 if (!(name
= HeapAlloc( GetProcessHeap(), 0, strlen(build_dir
) + sizeof("/loader/wine.inf") )))
111 strcpy( name
, build_dir
);
112 strcat( name
, "/loader/wine.inf" );
117 /* update the timestamp if different from the reference time */
118 static BOOL
update_timestamp( const char *config_dir
, unsigned long timestamp
)
123 char *file
= HeapAlloc( GetProcessHeap(), 0, strlen(config_dir
) + sizeof("/.update-timestamp") );
125 if (!file
) return FALSE
;
126 strcpy( file
, config_dir
);
127 strcat( file
, "/.update-timestamp" );
129 if ((fd
= open( file
, O_RDWR
)) != -1)
131 if ((count
= read( fd
, buffer
, sizeof(buffer
) - 1 )) >= 0)
134 if (!strncmp( buffer
, "disable", sizeof("disable")-1 )) goto done
;
135 if (timestamp
== strtoul( buffer
, NULL
, 10 )) goto done
;
137 lseek( fd
, 0, SEEK_SET
);
142 if (errno
!= ENOENT
) goto done
;
143 if ((fd
= open( file
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0666 )) == -1) goto done
;
146 count
= sprintf( buffer
, "%lu\n", timestamp
);
147 if (write( fd
, buffer
, count
) != count
)
149 WINE_WARN( "failed to update timestamp in %s\n", file
);
155 if (fd
!= -1) close( fd
);
156 HeapFree( GetProcessHeap(), 0, file
);
160 /* wrapper for RegSetValueExW */
161 static DWORD
set_reg_value( HKEY hkey
, const WCHAR
*name
, const WCHAR
*value
)
163 return RegSetValueExW( hkey
, name
, 0, REG_SZ
, (const BYTE
*)value
, (strlenW(value
) + 1) * sizeof(WCHAR
) );
166 extern void do_cpuid( unsigned int ax
, unsigned int *p
);
167 #if defined(_MSC_VER)
168 void do_cpuid( unsigned int ax
, unsigned int *p
)
172 #elif defined(__i386__)
173 __ASM_GLOBAL_FUNC( do_cpuid
,
176 "movl 12(%esp),%eax\n\t"
177 "movl 16(%esp),%esi\n\t"
179 "movl %eax,(%esi)\n\t"
180 "movl %ebx,4(%esi)\n\t"
181 "movl %ecx,8(%esi)\n\t"
182 "movl %edx,12(%esi)\n\t"
186 #elif defined(__x86_64__)
187 __ASM_GLOBAL_FUNC( do_cpuid
,
191 "movl %eax,(%rsi)\n\t"
192 "movl %ebx,4(%rsi)\n\t"
193 "movl %ecx,8(%rsi)\n\t"
194 "movl %edx,12(%rsi)\n\t"
198 void do_cpuid( unsigned int ax
, unsigned int *p
)
204 static void regs_to_str( unsigned int *regs
, unsigned int len
, WCHAR
*buffer
)
207 unsigned char *p
= (unsigned char *)regs
;
209 for (i
= 0; i
< len
; i
++) { buffer
[i
] = *p
++; }
213 static unsigned int get_model( unsigned int reg0
, unsigned int *stepping
, unsigned int *family
)
215 unsigned int model
, family_id
= (reg0
& (0x0f << 8)) >> 8;
217 model
= (reg0
& (0x0f << 4)) >> 4;
218 if (family_id
== 6 || family_id
== 15) model
|= (reg0
& (0x0f << 16)) >> 12;
221 if (family_id
== 15) *family
+= (reg0
& (0xff << 20)) >> 20;
223 *stepping
= reg0
& 0x0f;
227 static void get_identifier( WCHAR
*buf
, const WCHAR
*arch
)
229 static const WCHAR fmtW
[] = {'%','s',' ','F','a','m','i','l','y',' ','%','u',' ','M','o','d','e','l',
230 ' ','%','u',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
231 unsigned int regs
[4] = {0, 0, 0, 0}, family
, model
, stepping
;
234 model
= get_model( regs
[0], &stepping
, &family
);
235 sprintfW( buf
, fmtW
, arch
, family
, model
, stepping
);
238 static void get_vendorid( WCHAR
*buf
)
240 unsigned int tmp
, regs
[4] = {0, 0, 0, 0};
243 tmp
= regs
[2]; /* swap edx and ecx */
247 regs_to_str( regs
+ 1, 12, buf
);
250 static void get_namestring( WCHAR
*buf
)
252 unsigned int regs
[4] = {0, 0, 0, 0};
255 do_cpuid( 0x80000000, regs
);
256 if (regs
[0] >= 0x80000004)
258 do_cpuid( 0x80000002, regs
);
259 regs_to_str( regs
, 16, buf
);
260 do_cpuid( 0x80000003, regs
);
261 regs_to_str( regs
, 16, buf
+ 16 );
262 do_cpuid( 0x80000004, regs
);
263 regs_to_str( regs
, 16, buf
+ 32 );
265 for (i
= strlenW(buf
) - 1; i
>= 0 && buf
[i
] == ' '; i
--) buf
[i
] = 0;
268 /* create the volatile hardware registry keys */
269 static void create_hardware_registry_keys(void)
271 static const WCHAR SystemW
[] = {'H','a','r','d','w','a','r','e','\\','D','e','s','c','r','i','p','t','i','o','n','\\',
272 'S','y','s','t','e','m',0};
273 static const WCHAR fpuW
[] = {'F','l','o','a','t','i','n','g','P','o','i','n','t','P','r','o','c','e','s','s','o','r',0};
274 static const WCHAR cpuW
[] = {'C','e','n','t','r','a','l','P','r','o','c','e','s','s','o','r',0};
275 static const WCHAR FeatureSetW
[] = {'F','e','a','t','u','r','e','S','e','t',0};
276 static const WCHAR IdentifierW
[] = {'I','d','e','n','t','i','f','i','e','r',0};
277 static const WCHAR ProcessorNameStringW
[] = {'P','r','o','c','e','s','s','o','r','N','a','m','e','S','t','r','i','n','g',0};
278 static const WCHAR SysidW
[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0};
279 static const WCHAR ARMSysidW
[] = {'A','R','M',' ','p','r','o','c','e','s','s','o','r',' ','f','a','m','i','l','y',0};
280 static const WCHAR mhzKeyW
[] = {'~','M','H','z',0};
281 static const WCHAR VendorIdentifierW
[] = {'V','e','n','d','o','r','I','d','e','n','t','i','f','i','e','r',0};
282 static const WCHAR PercentDW
[] = {'%','d',0};
283 static const WCHAR ARMCpuDescrW
[] = {'A','R','M',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
284 ' ','R','e','v','i','s','i','o','n',' ','%','d',0};
285 static const WCHAR x86W
[] = {'x','8','6',0};
286 static const WCHAR intel64W
[] = {'I','n','t','e','l','6','4',0};
287 static const WCHAR amd64W
[] = {'A','M','D','6','4',0};
288 static const WCHAR authenticamdW
[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0};
290 HKEY hkey
, system_key
, cpu_key
, fpu_key
;
291 SYSTEM_CPU_INFORMATION sci
;
292 PROCESSOR_POWER_INFORMATION
* power_info
;
293 ULONG sizeof_power_info
= sizeof(PROCESSOR_POWER_INFORMATION
) * NtCurrentTeb()->Peb
->NumberOfProcessors
;
294 WCHAR id
[60], namestr
[49], vendorid
[13];
296 get_namestring( namestr
);
297 get_vendorid( vendorid
);
298 NtQuerySystemInformation( SystemCpuInformation
, &sci
, sizeof(sci
), NULL
);
300 power_info
= HeapAlloc( GetProcessHeap(), 0, sizeof_power_info
);
301 if (power_info
== NULL
)
303 if (NtPowerInformation( ProcessorInformation
, NULL
, 0, power_info
, sizeof_power_info
))
304 memset( power_info
, 0, sizeof_power_info
);
306 switch (sci
.Architecture
)
308 case PROCESSOR_ARCHITECTURE_ARM
:
309 case PROCESSOR_ARCHITECTURE_ARM64
:
310 sprintfW( id
, ARMCpuDescrW
, sci
.Level
, HIBYTE(sci
.Revision
), LOBYTE(sci
.Revision
) );
313 case PROCESSOR_ARCHITECTURE_AMD64
:
314 get_identifier( id
, !strcmpW(vendorid
, authenticamdW
) ? amd64W
: intel64W
);
317 case PROCESSOR_ARCHITECTURE_INTEL
:
319 get_identifier( id
, x86W
);
323 if (RegCreateKeyExW( HKEY_LOCAL_MACHINE
, SystemW
, 0, NULL
, REG_OPTION_VOLATILE
,
324 KEY_ALL_ACCESS
, NULL
, &system_key
, NULL
))
326 HeapFree( GetProcessHeap(), 0, power_info
);
330 switch (sci
.Architecture
)
332 case PROCESSOR_ARCHITECTURE_ARM
:
333 case PROCESSOR_ARCHITECTURE_ARM64
:
334 set_reg_value( system_key
, IdentifierW
, ARMSysidW
);
337 case PROCESSOR_ARCHITECTURE_INTEL
:
338 case PROCESSOR_ARCHITECTURE_AMD64
:
340 set_reg_value( system_key
, IdentifierW
, SysidW
);
344 if (sci
.Architecture
== PROCESSOR_ARCHITECTURE_ARM
||
345 sci
.Architecture
== PROCESSOR_ARCHITECTURE_ARM64
||
346 RegCreateKeyExW( system_key
, fpuW
, 0, NULL
, REG_OPTION_VOLATILE
,
347 KEY_ALL_ACCESS
, NULL
, &fpu_key
, NULL
))
349 if (RegCreateKeyExW( system_key
, cpuW
, 0, NULL
, REG_OPTION_VOLATILE
,
350 KEY_ALL_ACCESS
, NULL
, &cpu_key
, NULL
))
353 for (i
= 0; i
< NtCurrentTeb()->Peb
->NumberOfProcessors
; i
++)
357 sprintfW( numW
, PercentDW
, i
);
358 if (!RegCreateKeyExW( cpu_key
, numW
, 0, NULL
, REG_OPTION_VOLATILE
,
359 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
361 RegSetValueExW( hkey
, FeatureSetW
, 0, REG_DWORD
, (BYTE
*)&sci
.FeatureSet
, sizeof(DWORD
) );
362 set_reg_value( hkey
, IdentifierW
, id
);
363 /* TODO: report ARM properly */
364 set_reg_value( hkey
, ProcessorNameStringW
, namestr
);
365 set_reg_value( hkey
, VendorIdentifierW
, vendorid
);
366 RegSetValueExW( hkey
, mhzKeyW
, 0, REG_DWORD
, (BYTE
*)&power_info
[i
].MaxMhz
, sizeof(DWORD
) );
369 if (sci
.Architecture
!= PROCESSOR_ARCHITECTURE_ARM
&&
370 sci
.Architecture
!= PROCESSOR_ARCHITECTURE_ARM64
&&
371 !RegCreateKeyExW( fpu_key
, numW
, 0, NULL
, REG_OPTION_VOLATILE
,
372 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
374 set_reg_value( hkey
, IdentifierW
, id
);
378 RegCloseKey( fpu_key
);
379 RegCloseKey( cpu_key
);
380 RegCloseKey( system_key
);
381 HeapFree( GetProcessHeap(), 0, power_info
);
385 /* create the DynData registry keys */
386 static void create_dynamic_registry_keys(void)
388 static const WCHAR StatDataW
[] = {'P','e','r','f','S','t','a','t','s','\\',
389 'S','t','a','t','D','a','t','a',0};
390 static const WCHAR ConfigManagerW
[] = {'C','o','n','f','i','g',' ','M','a','n','a','g','e','r','\\',
394 if (!RegCreateKeyExW( HKEY_DYN_DATA
, StatDataW
, 0, NULL
, 0, KEY_WRITE
, NULL
, &key
, NULL
))
396 if (!RegCreateKeyExW( HKEY_DYN_DATA
, ConfigManagerW
, 0, NULL
, 0, KEY_WRITE
, NULL
, &key
, NULL
))
400 /* create the platform-specific environment registry keys */
401 static void create_environment_registry_keys( void )
403 static const WCHAR EnvironW
[] = {'S','y','s','t','e','m','\\',
404 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
405 'C','o','n','t','r','o','l','\\',
406 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
407 'E','n','v','i','r','o','n','m','e','n','t',0};
408 static const WCHAR NumProcW
[] = {'N','U','M','B','E','R','_','O','F','_','P','R','O','C','E','S','S','O','R','S',0};
409 static const WCHAR ProcArchW
[] = {'P','R','O','C','E','S','S','O','R','_','A','R','C','H','I','T','E','C','T','U','R','E',0};
410 static const WCHAR x86W
[] = {'x','8','6',0};
411 static const WCHAR intel64W
[] = {'I','n','t','e','l','6','4',0};
412 static const WCHAR amd64W
[] = {'A','M','D','6','4',0};
413 static const WCHAR authenticamdW
[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0};
414 static const WCHAR commaW
[] = {',',' ',0};
415 static const WCHAR ProcIdW
[] = {'P','R','O','C','E','S','S','O','R','_','I','D','E','N','T','I','F','I','E','R',0};
416 static const WCHAR ProcLvlW
[] = {'P','R','O','C','E','S','S','O','R','_','L','E','V','E','L',0};
417 static const WCHAR ProcRevW
[] = {'P','R','O','C','E','S','S','O','R','_','R','E','V','I','S','I','O','N',0};
418 static const WCHAR PercentDW
[] = {'%','d',0};
419 static const WCHAR Percent04XW
[] = {'%','0','4','x',0};
420 static const WCHAR ARMCpuDescrW
[] = {'A','R','M',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
421 ' ','R','e','v','i','s','i','o','n',' ','%','d',0};
423 SYSTEM_CPU_INFORMATION sci
;
424 WCHAR buffer
[60], vendorid
[13];
425 const WCHAR
*arch
, *parch
;
427 if (RegCreateKeyW( HKEY_LOCAL_MACHINE
, EnvironW
, &env_key
)) return;
429 get_vendorid( vendorid
);
430 NtQuerySystemInformation( SystemCpuInformation
, &sci
, sizeof(sci
), NULL
);
432 sprintfW( buffer
, PercentDW
, NtCurrentTeb()->Peb
->NumberOfProcessors
);
433 set_reg_value( env_key
, NumProcW
, buffer
);
435 switch (sci
.Architecture
)
437 case PROCESSOR_ARCHITECTURE_AMD64
:
439 parch
= !strcmpW(vendorid
, authenticamdW
) ? amd64W
: intel64W
;
442 case PROCESSOR_ARCHITECTURE_INTEL
:
447 set_reg_value( env_key
, ProcArchW
, arch
);
449 switch (sci
.Architecture
)
451 case PROCESSOR_ARCHITECTURE_ARM
:
452 case PROCESSOR_ARCHITECTURE_ARM64
:
453 sprintfW( buffer
, ARMCpuDescrW
, sci
.Level
, HIBYTE(sci
.Revision
), LOBYTE(sci
.Revision
) );
456 case PROCESSOR_ARCHITECTURE_AMD64
:
457 case PROCESSOR_ARCHITECTURE_INTEL
:
459 get_identifier( buffer
, parch
);
460 strcatW( buffer
, commaW
);
461 strcatW( buffer
, vendorid
);
464 set_reg_value( env_key
, ProcIdW
, buffer
);
466 sprintfW( buffer
, PercentDW
, sci
.Level
);
467 set_reg_value( env_key
, ProcLvlW
, buffer
);
469 sprintfW( buffer
, Percent04XW
, sci
.Revision
);
470 set_reg_value( env_key
, ProcRevW
, buffer
);
472 RegCloseKey( env_key
);
475 static void create_volatile_environment_registry_key(void)
477 static const WCHAR VolatileEnvW
[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0};
478 static const WCHAR AppDataW
[] = {'A','P','P','D','A','T','A',0};
479 static const WCHAR ClientNameW
[] = {'C','L','I','E','N','T','N','A','M','E',0};
480 static const WCHAR HomeDriveW
[] = {'H','O','M','E','D','R','I','V','E',0};
481 static const WCHAR HomePathW
[] = {'H','O','M','E','P','A','T','H',0};
482 static const WCHAR HomeShareW
[] = {'H','O','M','E','S','H','A','R','E',0};
483 static const WCHAR LocalAppDataW
[] = {'L','O','C','A','L','A','P','P','D','A','T','A',0};
484 static const WCHAR LogonServerW
[] = {'L','O','G','O','N','S','E','R','V','E','R',0};
485 static const WCHAR SessionNameW
[] = {'S','E','S','S','I','O','N','N','A','M','E',0};
486 static const WCHAR UserNameW
[] = {'U','S','E','R','N','A','M','E',0};
487 static const WCHAR UserDomainW
[] = {'U','S','E','R','D','O','M','A','I','N',0};
488 static const WCHAR UserProfileW
[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
489 static const WCHAR ConsoleW
[] = {'C','o','n','s','o','l','e',0};
490 static const WCHAR EmptyW
[] = {0};
491 WCHAR path
[MAX_PATH
];
492 WCHAR computername
[MAX_COMPUTERNAME_LENGTH
+ 1 + 2];
497 if (RegCreateKeyExW( HKEY_CURRENT_USER
, VolatileEnvW
, 0, NULL
, REG_OPTION_VOLATILE
,
498 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
501 hr
= SHGetFolderPathW( NULL
, CSIDL_APPDATA
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, path
);
502 if (SUCCEEDED(hr
)) set_reg_value( hkey
, AppDataW
, path
);
504 set_reg_value( hkey
, ClientNameW
, ConsoleW
);
506 /* Write the profile path's drive letter and directory components into
507 * HOMEDRIVE and HOMEPATH respectively. */
508 hr
= SHGetFolderPathW( NULL
, CSIDL_PROFILE
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, path
);
511 set_reg_value( hkey
, UserProfileW
, path
);
512 set_reg_value( hkey
, HomePathW
, path
+ 2 );
514 set_reg_value( hkey
, HomeDriveW
, path
);
517 size
= ARRAY_SIZE(path
);
518 if (GetUserNameW( path
, &size
)) set_reg_value( hkey
, UserNameW
, path
);
520 set_reg_value( hkey
, HomeShareW
, EmptyW
);
522 hr
= SHGetFolderPathW( NULL
, CSIDL_LOCAL_APPDATA
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, path
);
524 set_reg_value( hkey
, LocalAppDataW
, path
);
526 size
= ARRAY_SIZE(computername
) - 2;
527 if (GetComputerNameW(&computername
[2], &size
))
529 set_reg_value( hkey
, UserDomainW
, &computername
[2] );
530 computername
[0] = computername
[1] = '\\';
531 set_reg_value( hkey
, LogonServerW
, computername
);
534 set_reg_value( hkey
, SessionNameW
, ConsoleW
);
538 /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
539 * Returns FALSE if there was an error, or otherwise if all is ok.
541 static BOOL
wininit(void)
543 static const WCHAR nulW
[] = {'N','U','L',0};
544 static const WCHAR renameW
[] = {'r','e','n','a','m','e',0};
545 static const WCHAR wininitW
[] = {'w','i','n','i','n','i','t','.','i','n','i',0};
546 static const WCHAR wininitbakW
[] = {'w','i','n','i','n','i','t','.','b','a','k',0};
547 WCHAR initial_buffer
[1024];
548 WCHAR
*str
, *buffer
= initial_buffer
;
549 DWORD size
= ARRAY_SIZE(initial_buffer
);
554 if (!(res
= GetPrivateProfileSectionW( renameW
, buffer
, size
, wininitW
))) return TRUE
;
555 if (res
< size
- 2) break;
556 if (buffer
!= initial_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
558 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) return FALSE
;
561 for (str
= buffer
; *str
; str
+= strlenW(str
) + 1)
565 if (*str
== ';') continue; /* comment */
566 if (!(value
= strchrW( str
, '=' ))) continue;
568 /* split the line into key and value */
571 if (!lstrcmpiW( nulW
, str
))
573 WINE_TRACE("Deleting file %s\n", wine_dbgstr_w(value
) );
574 if( !DeleteFileW( value
) )
575 WINE_WARN("Error deleting file %s\n", wine_dbgstr_w(value
) );
579 WINE_TRACE("Renaming file %s to %s\n", wine_dbgstr_w(value
), wine_dbgstr_w(str
) );
581 if( !MoveFileExW(value
, str
, MOVEFILE_COPY_ALLOWED
| MOVEFILE_REPLACE_EXISTING
) )
582 WINE_WARN("Error renaming %s to %s\n", wine_dbgstr_w(value
), wine_dbgstr_w(str
) );
587 if (buffer
!= initial_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
589 if( !MoveFileExW( wininitW
, wininitbakW
, MOVEFILE_REPLACE_EXISTING
) )
591 WINE_ERR("Couldn't rename wininit.ini, error %d\n", GetLastError() );
599 static BOOL
pendingRename(void)
601 static const WCHAR ValueName
[] = {'P','e','n','d','i','n','g',
602 'F','i','l','e','R','e','n','a','m','e',
603 'O','p','e','r','a','t','i','o','n','s',0};
604 static const WCHAR SessionW
[] = { 'S','y','s','t','e','m','\\',
605 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
606 'C','o','n','t','r','o','l','\\',
607 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
609 const WCHAR
*src
=NULL
, *dst
=NULL
;
614 WINE_TRACE("Entered\n");
616 if( (res
=RegOpenKeyExW( HKEY_LOCAL_MACHINE
, SessionW
, 0, KEY_ALL_ACCESS
, &hSession
))
619 WINE_TRACE("The key was not found - skipping\n");
623 res
=RegQueryValueExW( hSession
, ValueName
, NULL
, NULL
/* The value type does not really interest us, as it is not
624 truly a REG_MULTI_SZ anyways */,
626 if( res
==ERROR_FILE_NOT_FOUND
)
628 /* No value - nothing to do. Great! */
629 WINE_TRACE("Value not present - nothing to rename\n");
634 if( res
!=ERROR_SUCCESS
)
636 WINE_ERR("Couldn't query value's length (%d)\n", res
);
641 buffer
=HeapAlloc( GetProcessHeap(),0,dataLength
);
644 WINE_ERR("Couldn't allocate %u bytes for the value\n", dataLength
);
649 res
=RegQueryValueExW( hSession
, ValueName
, NULL
, NULL
, (LPBYTE
)buffer
, &dataLength
);
650 if( res
!=ERROR_SUCCESS
)
652 WINE_ERR("Couldn't query value after successfully querying before (%u),\n"
653 "please report to wine-devel@winehq.org\n", res
);
658 /* Make sure that the data is long enough and ends with two NULLs. This
659 * simplifies the code later on.
661 if( dataLength
<2*sizeof(buffer
[0]) ||
662 buffer
[dataLength
/sizeof(buffer
[0])-1]!='\0' ||
663 buffer
[dataLength
/sizeof(buffer
[0])-2]!='\0' )
665 WINE_ERR("Improper value format - doesn't end with NULL\n");
670 for( src
=buffer
; (src
-buffer
)*sizeof(src
[0])<dataLength
&& *src
!='\0';
671 src
=dst
+lstrlenW(dst
)+1 )
675 WINE_TRACE("processing next command\n");
677 dst
=src
+lstrlenW(src
)+1;
679 /* We need to skip the \??\ header */
680 if( src
[0]=='\\' && src
[1]=='?' && src
[2]=='?' && src
[3]=='\\' )
685 dwFlags
|=MOVEFILE_REPLACE_EXISTING
;
689 if( dst
[0]=='\\' && dst
[1]=='?' && dst
[2]=='?' && dst
[3]=='\\' )
694 /* Rename the file */
695 MoveFileExW( src
, dst
, dwFlags
);
698 /* Delete the file or directory */
699 if (!RemoveDirectoryW( src
) && GetLastError() == ERROR_DIRECTORY
) DeleteFileW( src
);
703 if((res
=RegDeleteValueW(hSession
, ValueName
))!=ERROR_SUCCESS
)
705 WINE_ERR("Error deleting the value (%u)\n", GetLastError() );
711 HeapFree(GetProcessHeap(), 0, buffer
);
714 RegCloseKey( hSession
);
719 #define INVALID_RUNCMD_RETURN -1
721 * This function runs the specified command in the specified dir.
722 * [in,out] cmdline - the command line to run. The function may change the passed buffer.
723 * [in] dir - the dir to run the command in. If it is NULL, then the current dir is used.
724 * [in] wait - whether to wait for the run program to finish before returning.
725 * [in] minimized - Whether to ask the program to run minimized.
728 * If running the process failed, returns INVALID_RUNCMD_RETURN. Use GetLastError to get the error code.
729 * If wait is FALSE - returns 0 if successful.
730 * If wait is TRUE - returns the program's return value.
732 static DWORD
runCmd(LPWSTR cmdline
, LPCWSTR dir
, BOOL wait
, BOOL minimized
)
735 PROCESS_INFORMATION info
;
738 memset(&si
, 0, sizeof(si
));
742 si
.dwFlags
=STARTF_USESHOWWINDOW
;
743 si
.wShowWindow
=SW_MINIMIZE
;
745 memset(&info
, 0, sizeof(info
));
747 if( !CreateProcessW(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, dir
, &si
, &info
) )
749 WINE_WARN("Failed to run command %s (%d)\n", wine_dbgstr_w(cmdline
), GetLastError() );
750 return INVALID_RUNCMD_RETURN
;
753 WINE_TRACE("Successfully ran command %s - Created process handle %p\n",
754 wine_dbgstr_w(cmdline
), info
.hProcess
);
757 { /* wait for the process to exit */
758 WaitForSingleObject(info
.hProcess
, INFINITE
);
759 GetExitCodeProcess(info
.hProcess
, &exit_code
);
762 CloseHandle( info
.hThread
);
763 CloseHandle( info
.hProcess
);
769 * Process a "Run" type registry key.
770 * hkRoot is the HKEY from which "Software\Microsoft\Windows\CurrentVersion" is
772 * szKeyName is the key holding the actual entries.
773 * bDelete tells whether we should delete each value right before executing it.
774 * bSynchronous tells whether we should wait for the prog to complete before
775 * going on to the next prog.
777 static BOOL
ProcessRunKeys( HKEY hkRoot
, LPCWSTR szKeyName
, BOOL bDelete
,
780 static const WCHAR WINKEY_NAME
[]={'S','o','f','t','w','a','r','e','\\',
781 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
782 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
785 DWORD i
, nMaxCmdLine
=0, nMaxValue
=0;
786 WCHAR
*szCmdLine
=NULL
;
789 if (hkRoot
==HKEY_LOCAL_MACHINE
)
790 WINE_TRACE("processing %s entries under HKLM\n",wine_dbgstr_w(szKeyName
) );
792 WINE_TRACE("processing %s entries under HKCU\n",wine_dbgstr_w(szKeyName
) );
794 if (RegCreateKeyExW( hkRoot
, WINKEY_NAME
, 0, NULL
, 0, KEY_READ
, NULL
, &hkWin
, NULL
) != ERROR_SUCCESS
)
797 if ((res
= RegCreateKeyExW( hkWin
, szKeyName
, 0, NULL
, 0, bDelete
? KEY_ALL_ACCESS
: KEY_READ
,
798 NULL
, &hkRun
, &dispos
)) != ERROR_SUCCESS
)
800 RegCloseKey( hkWin
);
803 RegCloseKey( hkWin
);
804 if (dispos
== REG_CREATED_NEW_KEY
) goto end
;
806 if( (res
=RegQueryInfoKeyW( hkRun
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &i
, &nMaxValue
,
807 &nMaxCmdLine
, NULL
, NULL
))!=ERROR_SUCCESS
)
812 WINE_TRACE("No commands to execute.\n");
818 if( (szCmdLine
=HeapAlloc(GetProcessHeap(),0,nMaxCmdLine
))==NULL
)
820 WINE_ERR("Couldn't allocate memory for the commands to be executed\n");
822 res
=ERROR_NOT_ENOUGH_MEMORY
;
826 if( (szValue
=HeapAlloc(GetProcessHeap(),0,(++nMaxValue
)*sizeof(*szValue
)))==NULL
)
828 WINE_ERR("Couldn't allocate memory for the value names\n");
830 res
=ERROR_NOT_ENOUGH_MEMORY
;
836 DWORD nValLength
=nMaxValue
, nDataLength
=nMaxCmdLine
;
841 if( (res
=RegEnumValueW( hkRun
, i
, szValue
, &nValLength
, 0, &type
,
842 (LPBYTE
)szCmdLine
, &nDataLength
))!=ERROR_SUCCESS
)
844 WINE_ERR("Couldn't read in value %d - %d\n", i
, res
);
849 if( bDelete
&& (res
=RegDeleteValueW( hkRun
, szValue
))!=ERROR_SUCCESS
)
851 WINE_ERR("Couldn't delete value - %d, %d. Running command anyways.\n", i
, res
);
856 WINE_ERR("Incorrect type of value #%d (%d)\n", i
, type
);
861 if( (res
=runCmd(szCmdLine
, NULL
, bSynchronous
, FALSE
))==INVALID_RUNCMD_RETURN
)
863 WINE_ERR("Error running cmd %s (%d)\n", wine_dbgstr_w(szCmdLine
), GetLastError() );
866 WINE_TRACE("Done processing cmd #%d\n", i
);
872 HeapFree( GetProcessHeap(), 0, szValue
);
873 HeapFree( GetProcessHeap(), 0, szCmdLine
);
876 RegCloseKey( hkRun
);
878 WINE_TRACE("done\n");
880 return res
==ERROR_SUCCESS
;
884 * WFP is Windows File Protection, in NT5 and Windows 2000 it maintains a cache
885 * of known good dlls and scans through and replaces corrupted DLLs with these
886 * known good versions. The only programs that should install into this dll
887 * cache are Windows Updates and IE (which is treated like a Windows Update)
889 * Implementing this allows installing ie in win2k mode to actually install the
890 * system dlls that we expect and need
892 static int ProcessWindowsFileProtection(void)
894 static const WCHAR winlogonW
[] = {'S','o','f','t','w','a','r','e','\\',
895 'M','i','c','r','o','s','o','f','t','\\',
896 'W','i','n','d','o','w','s',' ','N','T','\\',
897 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
898 'W','i','n','l','o','g','o','n',0};
899 static const WCHAR cachedirW
[] = {'S','F','C','D','l','l','C','a','c','h','e','D','i','r',0};
900 static const WCHAR dllcacheW
[] = {'\\','d','l','l','c','a','c','h','e','\\','*',0};
901 static const WCHAR wildcardW
[] = {'\\','*',0};
902 WIN32_FIND_DATAW finddata
;
907 LPWSTR dllcache
= NULL
;
909 if (!RegOpenKeyW( HKEY_LOCAL_MACHINE
, winlogonW
, &hkey
))
912 if (!RegQueryValueExW( hkey
, cachedirW
, 0, NULL
, NULL
, &sz
))
915 dllcache
= HeapAlloc(GetProcessHeap(),0,sz
+ sizeof(wildcardW
));
916 RegQueryValueExW( hkey
, cachedirW
, 0, NULL
, (LPBYTE
)dllcache
, &sz
);
917 strcatW( dllcache
, wildcardW
);
924 DWORD sz
= GetSystemDirectoryW( NULL
, 0 );
925 dllcache
= HeapAlloc( GetProcessHeap(), 0, sz
* sizeof(WCHAR
) + sizeof(dllcacheW
));
926 GetSystemDirectoryW( dllcache
, sz
);
927 strcatW( dllcache
, dllcacheW
);
930 find_handle
= FindFirstFileW(dllcache
,&finddata
);
931 dllcache
[ strlenW(dllcache
) - 2] = 0; /* strip off wildcard */
932 find_rc
= find_handle
!= INVALID_HANDLE_VALUE
;
935 static const WCHAR dotW
[] = {'.',0};
936 static const WCHAR dotdotW
[] = {'.','.',0};
937 WCHAR targetpath
[MAX_PATH
];
938 WCHAR currentpath
[MAX_PATH
];
941 WCHAR tempfile
[MAX_PATH
];
943 if (strcmpW(finddata
.cFileName
,dotW
) == 0 || strcmpW(finddata
.cFileName
,dotdotW
) == 0)
945 find_rc
= FindNextFileW(find_handle
,&finddata
);
951 VerFindFileW(VFFF_ISSHAREDFILE
, finddata
.cFileName
, windowsdir
,
952 windowsdir
, currentpath
, &sz
, targetpath
, &sz2
);
954 rc
= VerInstallFileW(0, finddata
.cFileName
, finddata
.cFileName
,
955 dllcache
, targetpath
, currentpath
, tempfile
, &sz
);
956 if (rc
!= ERROR_SUCCESS
)
958 WINE_WARN("WFP: %s error 0x%x\n",wine_dbgstr_w(finddata
.cFileName
),rc
);
959 DeleteFileW(tempfile
);
962 /* now delete the source file so that we don't try to install it over and over again */
963 lstrcpynW( targetpath
, dllcache
, MAX_PATH
- 1 );
964 sz
= strlenW( targetpath
);
965 targetpath
[sz
++] = '\\';
966 lstrcpynW( targetpath
+ sz
, finddata
.cFileName
, MAX_PATH
- sz
);
967 if (!DeleteFileW( targetpath
))
968 WINE_WARN( "failed to delete %s: error %u\n", wine_dbgstr_w(targetpath
), GetLastError() );
970 find_rc
= FindNextFileW(find_handle
,&finddata
);
972 FindClose(find_handle
);
973 HeapFree(GetProcessHeap(),0,dllcache
);
977 static BOOL
start_services_process(void)
979 static const WCHAR svcctl_started_event
[] = SVCCTL_STARTED_EVENT
;
980 static const WCHAR services
[] = {'\\','s','e','r','v','i','c','e','s','.','e','x','e',0};
981 PROCESS_INFORMATION pi
;
983 HANDLE wait_handles
[2];
984 WCHAR path
[MAX_PATH
];
986 if (!GetSystemDirectoryW(path
, MAX_PATH
- strlenW(services
)))
988 strcatW(path
, services
);
989 ZeroMemory(&si
, sizeof(si
));
991 if (!CreateProcessW(path
, path
, NULL
, NULL
, TRUE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
))
993 WINE_ERR("Couldn't start services.exe: error %u\n", GetLastError());
996 CloseHandle(pi
.hThread
);
998 wait_handles
[0] = CreateEventW(NULL
, TRUE
, FALSE
, svcctl_started_event
);
999 wait_handles
[1] = pi
.hProcess
;
1001 /* wait for the event to become available or the process to exit */
1002 if ((WaitForMultipleObjects(2, wait_handles
, FALSE
, INFINITE
)) == WAIT_OBJECT_0
+ 1)
1005 GetExitCodeProcess(pi
.hProcess
, &exit_code
);
1006 WINE_ERR("Unexpected termination of services.exe - exit code %d\n", exit_code
);
1007 CloseHandle(pi
.hProcess
);
1008 CloseHandle(wait_handles
[0]);
1012 CloseHandle(pi
.hProcess
);
1013 CloseHandle(wait_handles
[0]);
1017 static INT_PTR CALLBACK
wait_dlgproc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
1023 WCHAR
*buffer
, text
[1024];
1024 const WCHAR
*name
= (WCHAR
*)lp
;
1025 HICON icon
= LoadImageW( 0, (LPCWSTR
)IDI_WINLOGO
, IMAGE_ICON
, 48, 48, LR_SHARED
);
1026 SendDlgItemMessageW( hwnd
, IDC_WAITICON
, STM_SETICON
, (WPARAM
)icon
, 0 );
1027 SendDlgItemMessageW( hwnd
, IDC_WAITTEXT
, WM_GETTEXT
, 1024, (LPARAM
)text
);
1028 buffer
= HeapAlloc( GetProcessHeap(), 0, (strlenW(text
) + strlenW(name
) + 1) * sizeof(WCHAR
) );
1029 sprintfW( buffer
, text
, name
);
1030 SendDlgItemMessageW( hwnd
, IDC_WAITTEXT
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
1031 HeapFree( GetProcessHeap(), 0, buffer
);
1038 static HWND
show_wait_window(void)
1040 const char *config_dir
= wine_get_config_dir();
1045 len
= MultiByteToWideChar( CP_UNIXCP
, 0, config_dir
, -1, NULL
, 0 );
1046 name
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1047 MultiByteToWideChar( CP_UNIXCP
, 0, config_dir
, -1, name
, len
);
1048 hwnd
= CreateDialogParamW( GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_WAITDLG
), 0,
1049 wait_dlgproc
, (LPARAM
)name
);
1050 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1051 HeapFree( GetProcessHeap(), 0, name
);
1055 static HANDLE
start_rundll32( const char *inf_path
, BOOL wow64
)
1057 static const WCHAR rundll
[] = {'\\','r','u','n','d','l','l','3','2','.','e','x','e',0};
1058 static const WCHAR setupapi
[] = {' ','s','e','t','u','p','a','p','i',',',
1059 'I','n','s','t','a','l','l','H','i','n','f','S','e','c','t','i','o','n',0};
1060 static const WCHAR definstall
[] = {' ','D','e','f','a','u','l','t','I','n','s','t','a','l','l',0};
1061 static const WCHAR wowinstall
[] = {' ','W','o','w','6','4','I','n','s','t','a','l','l',0};
1062 static const WCHAR inf
[] = {' ','1','2','8',' ','\\','\\','?','\\','u','n','i','x',0 };
1064 WCHAR app
[MAX_PATH
+ ARRAY_SIZE(rundll
)];
1066 PROCESS_INFORMATION pi
;
1068 DWORD inf_len
, cmd_len
;
1070 memset( &si
, 0, sizeof(si
) );
1075 if (!GetSystemWow64DirectoryW( app
, MAX_PATH
)) return 0; /* not on 64-bit */
1077 else GetSystemDirectoryW( app
, MAX_PATH
);
1079 strcatW( app
, rundll
);
1081 cmd_len
= strlenW(app
) * sizeof(WCHAR
) + sizeof(setupapi
) + sizeof(definstall
) + sizeof(inf
);
1082 inf_len
= MultiByteToWideChar( CP_UNIXCP
, 0, inf_path
, -1, NULL
, 0 );
1084 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, cmd_len
+ inf_len
* sizeof(WCHAR
) ))) return 0;
1086 strcpyW( buffer
, app
);
1087 strcatW( buffer
, setupapi
);
1088 strcatW( buffer
, wow64
? wowinstall
: definstall
);
1089 strcatW( buffer
, inf
);
1090 MultiByteToWideChar( CP_UNIXCP
, 0, inf_path
, -1, buffer
+ strlenW(buffer
), inf_len
);
1092 if (CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
1093 CloseHandle( pi
.hThread
);
1097 HeapFree( GetProcessHeap(), 0, buffer
);
1101 /* execute rundll32 on the wine.inf file if necessary */
1102 static void update_wineprefix( BOOL force
)
1104 const char *config_dir
= wine_get_config_dir();
1105 char *inf_path
= get_wine_inf_path();
1111 WINE_MESSAGE( "wine: failed to update %s, wine.inf not found\n", config_dir
);
1114 if ((fd
= open( inf_path
, O_RDONLY
)) == -1)
1116 WINE_MESSAGE( "wine: failed to update %s with %s: %s\n",
1117 config_dir
, inf_path
, strerror(errno
) );
1123 if (update_timestamp( config_dir
, st
.st_mtime
) || force
)
1128 if ((process
= start_rundll32( inf_path
, FALSE
)))
1130 HWND hwnd
= show_wait_window();
1134 DWORD res
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, INFINITE
, QS_ALLINPUT
);
1135 if (res
== WAIT_OBJECT_0
)
1137 CloseHandle( process
);
1138 if (count
++ || !(process
= start_rundll32( inf_path
, TRUE
))) break;
1140 else while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageW( &msg
);
1142 DestroyWindow( hwnd
);
1144 WINE_MESSAGE( "wine: configuration in '%s' has been updated.\n", config_dir
);
1148 HeapFree( GetProcessHeap(), 0, inf_path
);
1151 /* Process items in the StartUp group of the user's Programs under the Start Menu. Some installers put
1152 * shell links here to restart themselves after boot. */
1153 static BOOL
ProcessStartupItems(void)
1157 IMalloc
*ppM
= NULL
;
1158 IShellFolder
*psfDesktop
= NULL
, *psfStartup
= NULL
;
1159 LPITEMIDLIST pidlStartup
= NULL
, pidlItem
;
1161 IEnumIDList
*iEnumList
= NULL
;
1163 WCHAR wszCommand
[MAX_PATH
];
1165 WINE_TRACE("Processing items in the StartUp folder.\n");
1167 hr
= SHGetMalloc(&ppM
);
1170 WINE_ERR("Couldn't get IMalloc object.\n");
1174 hr
= SHGetDesktopFolder(&psfDesktop
);
1177 WINE_ERR("Couldn't get desktop folder.\n");
1181 hr
= SHGetSpecialFolderLocation(NULL
, CSIDL_STARTUP
, &pidlStartup
);
1184 WINE_TRACE("Couldn't get StartUp folder location.\n");
1188 hr
= IShellFolder_BindToObject(psfDesktop
, pidlStartup
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfStartup
);
1191 WINE_TRACE("Couldn't bind IShellFolder to StartUp folder.\n");
1195 hr
= IShellFolder_EnumObjects(psfStartup
, NULL
, SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &iEnumList
);
1198 WINE_TRACE("Unable to enumerate StartUp objects.\n");
1202 while (IEnumIDList_Next(iEnumList
, 1, &pidlItem
, &NumPIDLs
) == S_OK
&&
1205 hr
= IShellFolder_GetDisplayNameOf(psfStartup
, pidlItem
, SHGDN_FORPARSING
, &strret
);
1207 WINE_TRACE("Unable to get display name of enumeration item.\n");
1210 hr
= StrRetToBufW(&strret
, pidlItem
, wszCommand
, MAX_PATH
);
1212 WINE_TRACE("Unable to parse display name.\n");
1217 hinst
= ShellExecuteW(NULL
, NULL
, wszCommand
, NULL
, NULL
, SW_SHOWNORMAL
);
1218 if (PtrToUlong(hinst
) <= 32)
1219 WINE_WARN("Error %p executing command %s.\n", hinst
, wine_dbgstr_w(wszCommand
));
1223 IMalloc_Free(ppM
, pidlItem
);
1226 /* Return success */
1230 if (iEnumList
) IEnumIDList_Release(iEnumList
);
1231 if (psfStartup
) IShellFolder_Release(psfStartup
);
1232 if (pidlStartup
) IMalloc_Free(ppM
, pidlStartup
);
1237 static void usage(void)
1239 WINE_MESSAGE( "Usage: wineboot [options]\n" );
1240 WINE_MESSAGE( "Options;\n" );
1241 WINE_MESSAGE( " -h,--help Display this help message\n" );
1242 WINE_MESSAGE( " -e,--end-session End the current session cleanly\n" );
1243 WINE_MESSAGE( " -f,--force Force exit for processes that don't exit cleanly\n" );
1244 WINE_MESSAGE( " -i,--init Perform initialization for first Wine instance\n" );
1245 WINE_MESSAGE( " -k,--kill Kill running processes without any cleanup\n" );
1246 WINE_MESSAGE( " -r,--restart Restart only, don't do normal startup operations\n" );
1247 WINE_MESSAGE( " -s,--shutdown Shutdown only, don't reboot\n" );
1248 WINE_MESSAGE( " -u,--update Update the wineprefix directory\n" );
1251 static const char short_options
[] = "efhikrsu";
1253 static const struct option long_options
[] =
1255 { "help", 0, 0, 'h' },
1256 { "end-session", 0, 0, 'e' },
1257 { "force", 0, 0, 'f' },
1258 { "init" , 0, 0, 'i' },
1259 { "kill", 0, 0, 'k' },
1260 { "restart", 0, 0, 'r' },
1261 { "shutdown", 0, 0, 's' },
1262 { "update", 0, 0, 'u' },
1266 int main( int argc
, char *argv
[] )
1268 static const WCHAR RunW
[] = {'R','u','n',0};
1269 static const WCHAR RunOnceW
[] = {'R','u','n','O','n','c','e',0};
1270 static const WCHAR RunServicesW
[] = {'R','u','n','S','e','r','v','i','c','e','s',0};
1271 static const WCHAR RunServicesOnceW
[] = {'R','u','n','S','e','r','v','i','c','e','s','O','n','c','e',0};
1272 static const WCHAR wineboot_eventW
[] = {'_','_','w','i','n','e','b','o','o','t','_','e','v','e','n','t',0};
1274 /* First, set the current directory to SystemRoot */
1276 BOOL end_session
, force
, init
, kill
, restart
, shutdown
, update
;
1278 SECURITY_ATTRIBUTES sa
;
1281 end_session
= force
= init
= kill
= restart
= shutdown
= update
= FALSE
;
1282 GetWindowsDirectoryW( windowsdir
, MAX_PATH
);
1283 if( !SetCurrentDirectoryW( windowsdir
) )
1284 WINE_ERR("Cannot set the dir to %s (%d)\n", wine_dbgstr_w(windowsdir
), GetLastError() );
1286 if (IsWow64Process( GetCurrentProcess(), &is_wow64
) && is_wow64
)
1289 PROCESS_INFORMATION pi
;
1290 WCHAR filename
[MAX_PATH
];
1294 memset( &si
, 0, sizeof(si
) );
1296 GetModuleFileNameW( 0, filename
, MAX_PATH
);
1298 Wow64DisableWow64FsRedirection( &redir
);
1299 if (CreateProcessW( filename
, GetCommandLineW(), NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
1301 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename
) );
1302 WaitForSingleObject( pi
.hProcess
, INFINITE
);
1303 GetExitCodeProcess( pi
.hProcess
, &exit_code
);
1304 ExitProcess( exit_code
);
1306 else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename
), GetLastError() );
1307 Wow64RevertWow64FsRedirection( redir
);
1310 while ((optc
= getopt_long(argc
, argv
, short_options
, long_options
, NULL
)) != -1)
1314 case 'e': end_session
= TRUE
; break;
1315 case 'f': force
= TRUE
; break;
1316 case 'i': init
= TRUE
; break;
1317 case 'k': kill
= TRUE
; break;
1318 case 'r': restart
= TRUE
; break;
1319 case 's': shutdown
= TRUE
; break;
1320 case 'u': update
= TRUE
; break;
1321 case 'h': usage(); return 0;
1322 case '?': usage(); return 1;
1330 if (!shutdown_all_desktops( force
)) return 1;
1332 else if (!shutdown_close_windows( force
)) return 1;
1335 if (kill
) kill_processes( shutdown
);
1337 if (shutdown
) return 0;
1339 sa
.nLength
= sizeof(sa
);
1340 sa
.lpSecurityDescriptor
= NULL
;
1341 sa
.bInheritHandle
= TRUE
; /* so that services.exe inherits it */
1342 event
= CreateEventW( &sa
, TRUE
, FALSE
, wineboot_eventW
);
1344 ResetEvent( event
); /* in case this is a restart */
1346 create_hardware_registry_keys();
1347 create_dynamic_registry_keys();
1348 create_environment_registry_keys();
1352 ProcessWindowsFileProtection();
1353 ProcessRunKeys( HKEY_LOCAL_MACHINE
, RunServicesOnceW
, TRUE
, FALSE
);
1355 if (init
|| (kill
&& !restart
))
1357 ProcessRunKeys( HKEY_LOCAL_MACHINE
, RunServicesW
, FALSE
, FALSE
);
1358 start_services_process();
1360 if (init
|| update
) update_wineprefix( update
);
1362 create_volatile_environment_registry_key();
1364 ProcessRunKeys( HKEY_LOCAL_MACHINE
, RunOnceW
, TRUE
, TRUE
);
1366 if (!init
&& !restart
)
1368 ProcessRunKeys( HKEY_LOCAL_MACHINE
, RunW
, FALSE
, FALSE
);
1369 ProcessRunKeys( HKEY_CURRENT_USER
, RunW
, FALSE
, FALSE
);
1370 ProcessStartupItems();
1373 WINE_TRACE("Operation done\n");