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 #define MAX_LINE_LENGTH (2*MAX_PATH+2)
90 extern BOOL
shutdown_close_windows( BOOL force
);
91 extern BOOL
shutdown_all_desktops( BOOL force
);
92 extern void kill_processes( BOOL kill_desktop
);
94 static WCHAR windowsdir
[MAX_PATH
];
96 /* retrieve the (unix) path to the wine.inf file */
97 static char *get_wine_inf_path(void)
99 const char *build_dir
, *data_dir
;
102 if ((data_dir
= wine_get_data_dir()))
104 if (!(name
= HeapAlloc( GetProcessHeap(), 0, strlen(data_dir
) + sizeof("/wine.inf") )))
106 strcpy( name
, data_dir
);
107 strcat( name
, "/wine.inf" );
109 else if ((build_dir
= wine_get_build_dir()))
111 if (!(name
= HeapAlloc( GetProcessHeap(), 0, strlen(build_dir
) + sizeof("/loader/wine.inf") )))
113 strcpy( name
, build_dir
);
114 strcat( name
, "/loader/wine.inf" );
119 /* update the timestamp if different from the reference time */
120 static BOOL
update_timestamp( const char *config_dir
, unsigned long timestamp
)
125 char *file
= HeapAlloc( GetProcessHeap(), 0, strlen(config_dir
) + sizeof("/.update-timestamp") );
127 if (!file
) return FALSE
;
128 strcpy( file
, config_dir
);
129 strcat( file
, "/.update-timestamp" );
131 if ((fd
= open( file
, O_RDWR
)) != -1)
133 if ((count
= read( fd
, buffer
, sizeof(buffer
) - 1 )) >= 0)
136 if (!strncmp( buffer
, "disable", sizeof("disable")-1 )) goto done
;
137 if (timestamp
== strtoul( buffer
, NULL
, 10 )) goto done
;
139 lseek( fd
, 0, SEEK_SET
);
144 if (errno
!= ENOENT
) goto done
;
145 if ((fd
= open( file
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0666 )) == -1) goto done
;
148 count
= sprintf( buffer
, "%lu\n", timestamp
);
149 if (write( fd
, buffer
, count
) != count
)
151 WINE_WARN( "failed to update timestamp in %s\n", file
);
157 if (fd
!= -1) close( fd
);
158 HeapFree( GetProcessHeap(), 0, file
);
162 /* wrapper for RegSetValueExW */
163 static DWORD
set_reg_value( HKEY hkey
, const WCHAR
*name
, const WCHAR
*value
)
165 return RegSetValueExW( hkey
, name
, 0, REG_SZ
, (const BYTE
*)value
, (strlenW(value
) + 1) * sizeof(WCHAR
) );
168 /* create the volatile hardware registry keys */
169 static void create_hardware_registry_keys(void)
171 static const WCHAR SystemW
[] = {'H','a','r','d','w','a','r','e','\\',
172 'D','e','s','c','r','i','p','t','i','o','n','\\',
173 'S','y','s','t','e','m',0};
174 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};
175 static const WCHAR cpuW
[] = {'C','e','n','t','r','a','l','P','r','o','c','e','s','s','o','r',0};
176 static const WCHAR FeatureSetW
[] = {'F','e','a','t','u','r','e','S','e','t',0};
177 static const WCHAR IdentifierW
[] = {'I','d','e','n','t','i','f','i','e','r',0};
178 static const WCHAR ProcessorNameStringW
[] = {'P','r','o','c','e','s','s','o','r','N','a','m','e','S','t','r','i','n','g',0};
179 static const WCHAR SysidW
[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0};
180 static const WCHAR ARMSysidW
[] = {'A','R','M',' ','p','r','o','c','e','s','s','o','r',' ','f','a','m','i','l','y',0};
181 static const WCHAR mhzKeyW
[] = {'~','M','H','z',0};
182 static const WCHAR VendorIdentifierW
[] = {'V','e','n','d','o','r','I','d','e','n','t','i','f','i','e','r',0};
183 static const WCHAR VenidIntelW
[] = {'G','e','n','u','i','n','e','I','n','t','e','l',0};
184 /* static const WCHAR VenidAMDW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0}; */
185 static const WCHAR PercentDW
[] = {'%','d',0};
186 static const WCHAR IntelCpuDescrW
[] = {'x','8','6',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
187 ' ','S','t','e','p','p','i','n','g',' ','%','d',0};
188 static const WCHAR ARMCpuDescrW
[] = {'A','R','M',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
189 ' ','R','e','v','i','s','i','o','n',' ','%','d',0};
190 static const WCHAR IntelCpuStringW
[] = {'I','n','t','e','l','(','R',')',' ','P','e','n','t','i','u','m','(','R',')',' ','4',' ',
191 'C','P','U',' ','2','.','4','0','G','H','z',0};
193 HKEY hkey
, system_key
, cpu_key
, fpu_key
;
194 SYSTEM_CPU_INFORMATION sci
;
195 PROCESSOR_POWER_INFORMATION
* power_info
;
196 ULONG sizeof_power_info
= sizeof(PROCESSOR_POWER_INFORMATION
) * NtCurrentTeb()->Peb
->NumberOfProcessors
;
199 NtQuerySystemInformation( SystemCpuInformation
, &sci
, sizeof(sci
), NULL
);
201 power_info
= HeapAlloc( GetProcessHeap(), 0, sizeof_power_info
);
202 if (power_info
== NULL
)
204 if (NtPowerInformation( ProcessorInformation
, NULL
, 0, power_info
, sizeof_power_info
))
205 memset( power_info
, 0, sizeof_power_info
);
207 /*TODO: report 64bit processors properly*/
208 switch(sci
.Architecture
)
210 case PROCESSOR_ARCHITECTURE_ARM
:
211 case PROCESSOR_ARCHITECTURE_ARM64
:
212 sprintfW( idW
, ARMCpuDescrW
, sci
.Level
, HIBYTE(sci
.Revision
), LOBYTE(sci
.Revision
) );
215 case PROCESSOR_ARCHITECTURE_INTEL
:
216 sprintfW( idW
, IntelCpuDescrW
, sci
.Level
, HIBYTE(sci
.Revision
), LOBYTE(sci
.Revision
) );
220 if (RegCreateKeyExW( HKEY_LOCAL_MACHINE
, SystemW
, 0, NULL
, REG_OPTION_VOLATILE
,
221 KEY_ALL_ACCESS
, NULL
, &system_key
, NULL
))
223 HeapFree( GetProcessHeap(), 0, power_info
);
227 switch(sci
.Architecture
)
229 case PROCESSOR_ARCHITECTURE_ARM
:
230 case PROCESSOR_ARCHITECTURE_ARM64
:
231 set_reg_value( system_key
, IdentifierW
, ARMSysidW
);
234 case PROCESSOR_ARCHITECTURE_INTEL
:
235 set_reg_value( system_key
, IdentifierW
, SysidW
);
239 if (sci
.Architecture
== PROCESSOR_ARCHITECTURE_ARM
||
240 sci
.Architecture
== PROCESSOR_ARCHITECTURE_ARM64
||
241 RegCreateKeyExW( system_key
, fpuW
, 0, NULL
, REG_OPTION_VOLATILE
,
242 KEY_ALL_ACCESS
, NULL
, &fpu_key
, NULL
))
244 if (RegCreateKeyExW( system_key
, cpuW
, 0, NULL
, REG_OPTION_VOLATILE
,
245 KEY_ALL_ACCESS
, NULL
, &cpu_key
, NULL
))
248 for (i
= 0; i
< NtCurrentTeb()->Peb
->NumberOfProcessors
; i
++)
252 sprintfW( numW
, PercentDW
, i
);
253 if (!RegCreateKeyExW( cpu_key
, numW
, 0, NULL
, REG_OPTION_VOLATILE
,
254 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
256 RegSetValueExW( hkey
, FeatureSetW
, 0, REG_DWORD
, (BYTE
*)&sci
.FeatureSet
, sizeof(DWORD
) );
257 set_reg_value( hkey
, IdentifierW
, idW
);
258 /*TODO; report ARM and AMD properly*/
259 set_reg_value( hkey
, ProcessorNameStringW
, IntelCpuStringW
);
260 set_reg_value( hkey
, VendorIdentifierW
, VenidIntelW
);
261 RegSetValueExW( hkey
, mhzKeyW
, 0, REG_DWORD
, (BYTE
*)&power_info
[i
].MaxMhz
, sizeof(DWORD
) );
264 if (sci
.Architecture
!= PROCESSOR_ARCHITECTURE_ARM
&&
265 sci
.Architecture
!= PROCESSOR_ARCHITECTURE_ARM64
&&
266 !RegCreateKeyExW( fpu_key
, numW
, 0, NULL
, REG_OPTION_VOLATILE
,
267 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
269 set_reg_value( hkey
, IdentifierW
, idW
);
273 RegCloseKey( fpu_key
);
274 RegCloseKey( cpu_key
);
275 RegCloseKey( system_key
);
276 HeapFree( GetProcessHeap(), 0, power_info
);
280 /* create the DynData registry keys */
281 static void create_dynamic_registry_keys(void)
283 static const WCHAR StatDataW
[] = {'P','e','r','f','S','t','a','t','s','\\',
284 'S','t','a','t','D','a','t','a',0};
285 static const WCHAR ConfigManagerW
[] = {'C','o','n','f','i','g',' ','M','a','n','a','g','e','r','\\',
289 if (!RegCreateKeyExW( HKEY_DYN_DATA
, StatDataW
, 0, NULL
, 0, KEY_WRITE
, NULL
, &key
, NULL
))
291 if (!RegCreateKeyExW( HKEY_DYN_DATA
, ConfigManagerW
, 0, NULL
, 0, KEY_WRITE
, NULL
, &key
, NULL
))
295 /* create the platform-specific environment registry keys */
296 static void create_environment_registry_keys( void )
298 static const WCHAR EnvironW
[] = {'S','y','s','t','e','m','\\',
299 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
300 'C','o','n','t','r','o','l','\\',
301 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
302 'E','n','v','i','r','o','n','m','e','n','t',0};
303 static const WCHAR NumProcW
[] = {'N','U','M','B','E','R','_','O','F','_','P','R','O','C','E','S','S','O','R','S',0};
304 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};
305 static const WCHAR x86W
[] = {'x','8','6',0};
306 static const WCHAR armW
[] = {'A','R','M',0};
307 static const WCHAR arm64W
[] = {'A','R','M','6','4',0};
308 static const WCHAR AMD64W
[] = {'A','M','D','6','4',0};
309 static const WCHAR ProcIdW
[] = {'P','R','O','C','E','S','S','O','R','_','I','D','E','N','T','I','F','I','E','R',0};
310 static const WCHAR ProcLvlW
[] = {'P','R','O','C','E','S','S','O','R','_','L','E','V','E','L',0};
311 static const WCHAR ProcRevW
[] = {'P','R','O','C','E','S','S','O','R','_','R','E','V','I','S','I','O','N',0};
312 static const WCHAR PercentDW
[] = {'%','d',0};
313 static const WCHAR Percent04XW
[] = {'%','0','4','x',0};
314 static const WCHAR IntelCpuDescrW
[] = {'%','s',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
315 ' ','S','t','e','p','p','i','n','g',' ','%','d',',',' ','G','e','n','u','i','n','e','I','n','t','e','l',0};
316 static const WCHAR ARMCpuDescrW
[] = {'A','R','M',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
317 ' ','R','e','v','i','s','i','o','n',' ','%','d',0};
320 SYSTEM_CPU_INFORMATION sci
;
324 NtQuerySystemInformation( SystemCpuInformation
, &sci
, sizeof(sci
), NULL
);
326 if (RegCreateKeyW( HKEY_LOCAL_MACHINE
, EnvironW
, &env_key
)) return;
328 sprintfW( buffer
, PercentDW
, NtCurrentTeb()->Peb
->NumberOfProcessors
);
329 set_reg_value( env_key
, NumProcW
, buffer
);
331 switch(sci
.Architecture
)
333 case PROCESSOR_ARCHITECTURE_AMD64
: arch
= AMD64W
; break;
334 case PROCESSOR_ARCHITECTURE_ARM
: arch
= armW
; break;
335 case PROCESSOR_ARCHITECTURE_ARM64
: arch
= arm64W
; break;
337 case PROCESSOR_ARCHITECTURE_INTEL
: arch
= x86W
; break;
339 set_reg_value( env_key
, ProcArchW
, arch
);
341 switch(sci
.Architecture
)
343 case PROCESSOR_ARCHITECTURE_ARM
:
344 case PROCESSOR_ARCHITECTURE_ARM64
:
345 sprintfW( buffer
, ARMCpuDescrW
, sci
.Level
, HIBYTE(sci
.Revision
), LOBYTE(sci
.Revision
) );
348 case PROCESSOR_ARCHITECTURE_INTEL
:
349 sprintfW( buffer
, IntelCpuDescrW
, arch
, sci
.Level
, HIBYTE(sci
.Revision
), LOBYTE(sci
.Revision
) );
352 set_reg_value( env_key
, ProcIdW
, buffer
);
354 sprintfW( buffer
, PercentDW
, sci
.Level
);
355 set_reg_value( env_key
, ProcLvlW
, buffer
);
357 /* Properly report model/stepping */
358 sprintfW( buffer
, Percent04XW
, sci
.Revision
);
359 set_reg_value( env_key
, ProcRevW
, buffer
);
361 RegCloseKey( env_key
);
364 static void create_volatile_environment_registry_key(void)
366 static const WCHAR VolatileEnvW
[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0};
367 static const WCHAR AppDataW
[] = {'A','P','P','D','A','T','A',0};
368 static const WCHAR ClientNameW
[] = {'C','L','I','E','N','T','N','A','M','E',0};
369 static const WCHAR HomeDriveW
[] = {'H','O','M','E','D','R','I','V','E',0};
370 static const WCHAR HomePathW
[] = {'H','O','M','E','P','A','T','H',0};
371 static const WCHAR HomeShareW
[] = {'H','O','M','E','S','H','A','R','E',0};
372 static const WCHAR LocalAppDataW
[] = {'L','O','C','A','L','A','P','P','D','A','T','A',0};
373 static const WCHAR LogonServerW
[] = {'L','O','G','O','N','S','E','R','V','E','R',0};
374 static const WCHAR SessionNameW
[] = {'S','E','S','S','I','O','N','N','A','M','E',0};
375 static const WCHAR UserNameW
[] = {'U','S','E','R','N','A','M','E',0};
376 static const WCHAR UserDomainW
[] = {'U','S','E','R','D','O','M','A','I','N',0};
377 static const WCHAR UserProfileW
[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
378 static const WCHAR ConsoleW
[] = {'C','o','n','s','o','l','e',0};
379 static const WCHAR EmptyW
[] = {0};
380 WCHAR path
[MAX_PATH
];
381 WCHAR computername
[MAX_COMPUTERNAME_LENGTH
+ 1 + 2];
386 if (RegCreateKeyExW( HKEY_CURRENT_USER
, VolatileEnvW
, 0, NULL
, REG_OPTION_VOLATILE
,
387 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
))
390 hr
= SHGetFolderPathW( NULL
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, path
);
391 if (SUCCEEDED(hr
)) set_reg_value( hkey
, AppDataW
, path
);
393 set_reg_value( hkey
, ClientNameW
, ConsoleW
);
395 /* Write the profile path's drive letter and directory components into
396 * HOMEDRIVE and HOMEPATH respectively. */
397 hr
= SHGetFolderPathW( NULL
, CSIDL_PROFILE
, NULL
, SHGFP_TYPE_CURRENT
, path
);
400 set_reg_value( hkey
, UserProfileW
, path
);
401 set_reg_value( hkey
, HomePathW
, path
+ 2 );
403 set_reg_value( hkey
, HomeDriveW
, path
);
406 size
= sizeof(path
)/sizeof(path
[0]);
407 if (GetUserNameW( path
, &size
)) set_reg_value( hkey
, UserNameW
, path
);
409 set_reg_value( hkey
, HomeShareW
, EmptyW
);
411 hr
= SHGetFolderPathW( NULL
, CSIDL_LOCAL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, path
);
413 set_reg_value( hkey
, LocalAppDataW
, path
);
415 size
= (sizeof(computername
)/sizeof(WCHAR
)) - 2;
416 if (GetComputerNameW(&computername
[2], &size
))
418 set_reg_value( hkey
, UserDomainW
, &computername
[2] );
419 computername
[0] = computername
[1] = '\\';
420 set_reg_value( hkey
, LogonServerW
, computername
);
423 set_reg_value( hkey
, SessionNameW
, ConsoleW
);
427 /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
428 * Returns FALSE if there was an error, or otherwise if all is ok.
430 static BOOL
wininit(void)
432 static const WCHAR nulW
[] = {'N','U','L',0};
433 static const WCHAR renameW
[] = {'r','e','n','a','m','e',0};
434 static const WCHAR wininitW
[] = {'w','i','n','i','n','i','t','.','i','n','i',0};
435 static const WCHAR wininitbakW
[] = {'w','i','n','i','n','i','t','.','b','a','k',0};
436 WCHAR initial_buffer
[1024];
437 WCHAR
*str
, *buffer
= initial_buffer
;
438 DWORD size
= sizeof(initial_buffer
)/sizeof(WCHAR
);
443 if (!(res
= GetPrivateProfileSectionW( renameW
, buffer
, size
, wininitW
))) return TRUE
;
444 if (res
< size
- 2) break;
445 if (buffer
!= initial_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
447 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) return FALSE
;
450 for (str
= buffer
; *str
; str
+= strlenW(str
) + 1)
454 if (*str
== ';') continue; /* comment */
455 if (!(value
= strchrW( str
, '=' ))) continue;
457 /* split the line into key and value */
460 if (!lstrcmpiW( nulW
, str
))
462 WINE_TRACE("Deleting file %s\n", wine_dbgstr_w(value
) );
463 if( !DeleteFileW( value
) )
464 WINE_WARN("Error deleting file %s\n", wine_dbgstr_w(value
) );
468 WINE_TRACE("Renaming file %s to %s\n", wine_dbgstr_w(value
), wine_dbgstr_w(str
) );
470 if( !MoveFileExW(value
, str
, MOVEFILE_COPY_ALLOWED
| MOVEFILE_REPLACE_EXISTING
) )
471 WINE_WARN("Error renaming %s to %s\n", wine_dbgstr_w(value
), wine_dbgstr_w(str
) );
476 if (buffer
!= initial_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
478 if( !MoveFileExW( wininitW
, wininitbakW
, MOVEFILE_REPLACE_EXISTING
) )
480 WINE_ERR("Couldn't rename wininit.ini, error %d\n", GetLastError() );
488 static BOOL
pendingRename(void)
490 static const WCHAR ValueName
[] = {'P','e','n','d','i','n','g',
491 'F','i','l','e','R','e','n','a','m','e',
492 'O','p','e','r','a','t','i','o','n','s',0};
493 static const WCHAR SessionW
[] = { 'S','y','s','t','e','m','\\',
494 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
495 'C','o','n','t','r','o','l','\\',
496 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
498 const WCHAR
*src
=NULL
, *dst
=NULL
;
503 WINE_TRACE("Entered\n");
505 if( (res
=RegOpenKeyExW( HKEY_LOCAL_MACHINE
, SessionW
, 0, KEY_ALL_ACCESS
, &hSession
))
508 WINE_TRACE("The key was not found - skipping\n");
512 res
=RegQueryValueExW( hSession
, ValueName
, NULL
, NULL
/* The value type does not really interest us, as it is not
513 truly a REG_MULTI_SZ anyways */,
515 if( res
==ERROR_FILE_NOT_FOUND
)
517 /* No value - nothing to do. Great! */
518 WINE_TRACE("Value not present - nothing to rename\n");
523 if( res
!=ERROR_SUCCESS
)
525 WINE_ERR("Couldn't query value's length (%d)\n", res
);
530 buffer
=HeapAlloc( GetProcessHeap(),0,dataLength
);
533 WINE_ERR("Couldn't allocate %u bytes for the value\n", dataLength
);
538 res
=RegQueryValueExW( hSession
, ValueName
, NULL
, NULL
, (LPBYTE
)buffer
, &dataLength
);
539 if( res
!=ERROR_SUCCESS
)
541 WINE_ERR("Couldn't query value after successfully querying before (%u),\n"
542 "please report to wine-devel@winehq.org\n", res
);
547 /* Make sure that the data is long enough and ends with two NULLs. This
548 * simplifies the code later on.
550 if( dataLength
<2*sizeof(buffer
[0]) ||
551 buffer
[dataLength
/sizeof(buffer
[0])-1]!='\0' ||
552 buffer
[dataLength
/sizeof(buffer
[0])-2]!='\0' )
554 WINE_ERR("Improper value format - doesn't end with NULL\n");
559 for( src
=buffer
; (src
-buffer
)*sizeof(src
[0])<dataLength
&& *src
!='\0';
560 src
=dst
+lstrlenW(dst
)+1 )
564 WINE_TRACE("processing next command\n");
566 dst
=src
+lstrlenW(src
)+1;
568 /* We need to skip the \??\ header */
569 if( src
[0]=='\\' && src
[1]=='?' && src
[2]=='?' && src
[3]=='\\' )
574 dwFlags
|=MOVEFILE_REPLACE_EXISTING
;
578 if( dst
[0]=='\\' && dst
[1]=='?' && dst
[2]=='?' && dst
[3]=='\\' )
583 /* Rename the file */
584 MoveFileExW( src
, dst
, dwFlags
);
587 /* Delete the file or directory */
588 if (!RemoveDirectoryW( src
) && GetLastError() == ERROR_DIRECTORY
) DeleteFileW( src
);
592 if((res
=RegDeleteValueW(hSession
, ValueName
))!=ERROR_SUCCESS
)
594 WINE_ERR("Error deleting the value (%u)\n", GetLastError() );
600 HeapFree(GetProcessHeap(), 0, buffer
);
603 RegCloseKey( hSession
);
608 #define INVALID_RUNCMD_RETURN -1
610 * This function runs the specified command in the specified dir.
611 * [in,out] cmdline - the command line to run. The function may change the passed buffer.
612 * [in] dir - the dir to run the command in. If it is NULL, then the current dir is used.
613 * [in] wait - whether to wait for the run program to finish before returning.
614 * [in] minimized - Whether to ask the program to run minimized.
617 * If running the process failed, returns INVALID_RUNCMD_RETURN. Use GetLastError to get the error code.
618 * If wait is FALSE - returns 0 if successful.
619 * If wait is TRUE - returns the program's return value.
621 static DWORD
runCmd(LPWSTR cmdline
, LPCWSTR dir
, BOOL wait
, BOOL minimized
)
624 PROCESS_INFORMATION info
;
627 memset(&si
, 0, sizeof(si
));
631 si
.dwFlags
=STARTF_USESHOWWINDOW
;
632 si
.wShowWindow
=SW_MINIMIZE
;
634 memset(&info
, 0, sizeof(info
));
636 if( !CreateProcessW(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, dir
, &si
, &info
) )
638 WINE_WARN("Failed to run command %s (%d)\n", wine_dbgstr_w(cmdline
), GetLastError() );
639 return INVALID_RUNCMD_RETURN
;
642 WINE_TRACE("Successfully ran command %s - Created process handle %p\n",
643 wine_dbgstr_w(cmdline
), info
.hProcess
);
646 { /* wait for the process to exit */
647 WaitForSingleObject(info
.hProcess
, INFINITE
);
648 GetExitCodeProcess(info
.hProcess
, &exit_code
);
651 CloseHandle( info
.hThread
);
652 CloseHandle( info
.hProcess
);
658 * Process a "Run" type registry key.
659 * hkRoot is the HKEY from which "Software\Microsoft\Windows\CurrentVersion" is
661 * szKeyName is the key holding the actual entries.
662 * bDelete tells whether we should delete each value right before executing it.
663 * bSynchronous tells whether we should wait for the prog to complete before
664 * going on to the next prog.
666 static BOOL
ProcessRunKeys( HKEY hkRoot
, LPCWSTR szKeyName
, BOOL bDelete
,
669 static const WCHAR WINKEY_NAME
[]={'S','o','f','t','w','a','r','e','\\',
670 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
671 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
674 DWORD i
, nMaxCmdLine
=0, nMaxValue
=0;
675 WCHAR
*szCmdLine
=NULL
;
678 if (hkRoot
==HKEY_LOCAL_MACHINE
)
679 WINE_TRACE("processing %s entries under HKLM\n",wine_dbgstr_w(szKeyName
) );
681 WINE_TRACE("processing %s entries under HKCU\n",wine_dbgstr_w(szKeyName
) );
683 if (RegCreateKeyExW( hkRoot
, WINKEY_NAME
, 0, NULL
, 0, KEY_READ
, NULL
, &hkWin
, NULL
) != ERROR_SUCCESS
)
686 if ((res
= RegCreateKeyExW( hkWin
, szKeyName
, 0, NULL
, 0, bDelete
? KEY_ALL_ACCESS
: KEY_READ
,
687 NULL
, &hkRun
, &dispos
) != ERROR_SUCCESS
))
689 RegCloseKey( hkWin
);
692 RegCloseKey( hkWin
);
693 if (dispos
== REG_CREATED_NEW_KEY
) goto end
;
695 if( (res
=RegQueryInfoKeyW( hkRun
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &i
, &nMaxValue
,
696 &nMaxCmdLine
, NULL
, NULL
))!=ERROR_SUCCESS
)
701 WINE_TRACE("No commands to execute.\n");
707 if( (szCmdLine
=HeapAlloc(GetProcessHeap(),0,nMaxCmdLine
))==NULL
)
709 WINE_ERR("Couldn't allocate memory for the commands to be executed\n");
711 res
=ERROR_NOT_ENOUGH_MEMORY
;
715 if( (szValue
=HeapAlloc(GetProcessHeap(),0,(++nMaxValue
)*sizeof(*szValue
)))==NULL
)
717 WINE_ERR("Couldn't allocate memory for the value names\n");
719 res
=ERROR_NOT_ENOUGH_MEMORY
;
725 DWORD nValLength
=nMaxValue
, nDataLength
=nMaxCmdLine
;
730 if( (res
=RegEnumValueW( hkRun
, i
, szValue
, &nValLength
, 0, &type
,
731 (LPBYTE
)szCmdLine
, &nDataLength
))!=ERROR_SUCCESS
)
733 WINE_ERR("Couldn't read in value %d - %d\n", i
, res
);
738 if( bDelete
&& (res
=RegDeleteValueW( hkRun
, szValue
))!=ERROR_SUCCESS
)
740 WINE_ERR("Couldn't delete value - %d, %d. Running command anyways.\n", i
, res
);
745 WINE_ERR("Incorrect type of value #%d (%d)\n", i
, type
);
750 if( (res
=runCmd(szCmdLine
, NULL
, bSynchronous
, FALSE
))==INVALID_RUNCMD_RETURN
)
752 WINE_ERR("Error running cmd %s (%d)\n", wine_dbgstr_w(szCmdLine
), GetLastError() );
755 WINE_TRACE("Done processing cmd #%d\n", i
);
761 HeapFree( GetProcessHeap(), 0, szValue
);
762 HeapFree( GetProcessHeap(), 0, szCmdLine
);
765 RegCloseKey( hkRun
);
767 WINE_TRACE("done\n");
769 return res
==ERROR_SUCCESS
;
773 * WFP is Windows File Protection, in NT5 and Windows 2000 it maintains a cache
774 * of known good dlls and scans through and replaces corrupted DLLs with these
775 * known good versions. The only programs that should install into this dll
776 * cache are Windows Updates and IE (which is treated like a Windows Update)
778 * Implementing this allows installing ie in win2k mode to actually install the
779 * system dlls that we expect and need
781 static int ProcessWindowsFileProtection(void)
783 static const WCHAR winlogonW
[] = {'S','o','f','t','w','a','r','e','\\',
784 'M','i','c','r','o','s','o','f','t','\\',
785 'W','i','n','d','o','w','s',' ','N','T','\\',
786 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
787 'W','i','n','l','o','g','o','n',0};
788 static const WCHAR cachedirW
[] = {'S','F','C','D','l','l','C','a','c','h','e','D','i','r',0};
789 static const WCHAR dllcacheW
[] = {'\\','d','l','l','c','a','c','h','e','\\','*',0};
790 static const WCHAR wildcardW
[] = {'\\','*',0};
791 WIN32_FIND_DATAW finddata
;
796 LPWSTR dllcache
= NULL
;
798 if (!RegOpenKeyW( HKEY_LOCAL_MACHINE
, winlogonW
, &hkey
))
801 if (!RegQueryValueExW( hkey
, cachedirW
, 0, NULL
, NULL
, &sz
))
804 dllcache
= HeapAlloc(GetProcessHeap(),0,sz
+ sizeof(wildcardW
));
805 RegQueryValueExW( hkey
, cachedirW
, 0, NULL
, (LPBYTE
)dllcache
, &sz
);
806 strcatW( dllcache
, wildcardW
);
813 DWORD sz
= GetSystemDirectoryW( NULL
, 0 );
814 dllcache
= HeapAlloc( GetProcessHeap(), 0, sz
* sizeof(WCHAR
) + sizeof(dllcacheW
));
815 GetSystemDirectoryW( dllcache
, sz
);
816 strcatW( dllcache
, dllcacheW
);
819 find_handle
= FindFirstFileW(dllcache
,&finddata
);
820 dllcache
[ strlenW(dllcache
) - 2] = 0; /* strip off wildcard */
821 find_rc
= find_handle
!= INVALID_HANDLE_VALUE
;
824 static const WCHAR dotW
[] = {'.',0};
825 static const WCHAR dotdotW
[] = {'.','.',0};
826 WCHAR targetpath
[MAX_PATH
];
827 WCHAR currentpath
[MAX_PATH
];
830 WCHAR tempfile
[MAX_PATH
];
832 if (strcmpW(finddata
.cFileName
,dotW
) == 0 || strcmpW(finddata
.cFileName
,dotdotW
) == 0)
834 find_rc
= FindNextFileW(find_handle
,&finddata
);
840 VerFindFileW(VFFF_ISSHAREDFILE
, finddata
.cFileName
, windowsdir
,
841 windowsdir
, currentpath
, &sz
, targetpath
, &sz2
);
843 rc
= VerInstallFileW(0, finddata
.cFileName
, finddata
.cFileName
,
844 dllcache
, targetpath
, currentpath
, tempfile
, &sz
);
845 if (rc
!= ERROR_SUCCESS
)
847 WINE_WARN("WFP: %s error 0x%x\n",wine_dbgstr_w(finddata
.cFileName
),rc
);
848 DeleteFileW(tempfile
);
851 /* now delete the source file so that we don't try to install it over and over again */
852 lstrcpynW( targetpath
, dllcache
, MAX_PATH
- 1 );
853 sz
= strlenW( targetpath
);
854 targetpath
[sz
++] = '\\';
855 lstrcpynW( targetpath
+ sz
, finddata
.cFileName
, MAX_PATH
- sz
);
856 if (!DeleteFileW( targetpath
))
857 WINE_WARN( "failed to delete %s: error %u\n", wine_dbgstr_w(targetpath
), GetLastError() );
859 find_rc
= FindNextFileW(find_handle
,&finddata
);
861 FindClose(find_handle
);
862 HeapFree(GetProcessHeap(),0,dllcache
);
866 static BOOL
start_services_process(void)
868 static const WCHAR svcctl_started_event
[] = SVCCTL_STARTED_EVENT
;
869 static const WCHAR services
[] = {'\\','s','e','r','v','i','c','e','s','.','e','x','e',0};
870 PROCESS_INFORMATION pi
;
872 HANDLE wait_handles
[2];
873 WCHAR path
[MAX_PATH
];
875 if (!GetSystemDirectoryW(path
, MAX_PATH
- strlenW(services
)))
877 strcatW(path
, services
);
878 ZeroMemory(&si
, sizeof(si
));
880 if (!CreateProcessW(path
, path
, NULL
, NULL
, TRUE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
))
882 WINE_ERR("Couldn't start services.exe: error %u\n", GetLastError());
885 CloseHandle(pi
.hThread
);
887 wait_handles
[0] = CreateEventW(NULL
, TRUE
, FALSE
, svcctl_started_event
);
888 wait_handles
[1] = pi
.hProcess
;
890 /* wait for the event to become available or the process to exit */
891 if ((WaitForMultipleObjects(2, wait_handles
, FALSE
, INFINITE
)) == WAIT_OBJECT_0
+ 1)
894 GetExitCodeProcess(pi
.hProcess
, &exit_code
);
895 WINE_ERR("Unexpected termination of services.exe - exit code %d\n", exit_code
);
896 CloseHandle(pi
.hProcess
);
897 CloseHandle(wait_handles
[0]);
901 CloseHandle(pi
.hProcess
);
902 CloseHandle(wait_handles
[0]);
906 static INT_PTR CALLBACK
wait_dlgproc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
912 WCHAR
*buffer
, text
[1024];
913 const WCHAR
*name
= (WCHAR
*)lp
;
914 HICON icon
= LoadImageW( 0, (LPCWSTR
)IDI_WINLOGO
, IMAGE_ICON
, 48, 48, LR_SHARED
);
915 SendDlgItemMessageW( hwnd
, IDC_WAITICON
, STM_SETICON
, (WPARAM
)icon
, 0 );
916 SendDlgItemMessageW( hwnd
, IDC_WAITTEXT
, WM_GETTEXT
, 1024, (LPARAM
)text
);
917 buffer
= HeapAlloc( GetProcessHeap(), 0, (strlenW(text
) + strlenW(name
) + 1) * sizeof(WCHAR
) );
918 sprintfW( buffer
, text
, name
);
919 SendDlgItemMessageW( hwnd
, IDC_WAITTEXT
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
920 HeapFree( GetProcessHeap(), 0, buffer
);
927 static HWND
show_wait_window(void)
929 const char *config_dir
= wine_get_config_dir();
934 len
= MultiByteToWideChar( CP_UNIXCP
, 0, config_dir
, -1, NULL
, 0 );
935 name
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
936 MultiByteToWideChar( CP_UNIXCP
, 0, config_dir
, -1, name
, len
);
937 hwnd
= CreateDialogParamW( GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_WAITDLG
), 0,
938 wait_dlgproc
, (LPARAM
)name
);
939 ShowWindow( hwnd
, SW_SHOWNORMAL
);
940 HeapFree( GetProcessHeap(), 0, name
);
944 static HANDLE
start_rundll32( const char *inf_path
, BOOL wow64
)
946 static const WCHAR rundll
[] = {'\\','r','u','n','d','l','l','3','2','.','e','x','e',0};
947 static const WCHAR setupapi
[] = {' ','s','e','t','u','p','a','p','i',',',
948 'I','n','s','t','a','l','l','H','i','n','f','S','e','c','t','i','o','n',0};
949 static const WCHAR definstall
[] = {' ','D','e','f','a','u','l','t','I','n','s','t','a','l','l',0};
950 static const WCHAR wowinstall
[] = {' ','W','o','w','6','4','I','n','s','t','a','l','l',0};
951 static const WCHAR inf
[] = {' ','1','2','8',' ','\\','\\','?','\\','u','n','i','x',0 };
953 WCHAR app
[MAX_PATH
+ sizeof(rundll
)/sizeof(WCHAR
)];
955 PROCESS_INFORMATION pi
;
957 DWORD inf_len
, cmd_len
;
959 memset( &si
, 0, sizeof(si
) );
964 if (!GetSystemWow64DirectoryW( app
, MAX_PATH
)) return 0; /* not on 64-bit */
966 else GetSystemDirectoryW( app
, MAX_PATH
);
968 strcatW( app
, rundll
);
970 cmd_len
= strlenW(app
) * sizeof(WCHAR
) + sizeof(setupapi
) + sizeof(definstall
) + sizeof(inf
);
971 inf_len
= MultiByteToWideChar( CP_UNIXCP
, 0, inf_path
, -1, NULL
, 0 );
973 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, cmd_len
+ inf_len
* sizeof(WCHAR
) ))) return 0;
975 strcpyW( buffer
, app
);
976 strcatW( buffer
, setupapi
);
977 strcatW( buffer
, wow64
? wowinstall
: definstall
);
978 strcatW( buffer
, inf
);
979 MultiByteToWideChar( CP_UNIXCP
, 0, inf_path
, -1, buffer
+ strlenW(buffer
), inf_len
);
981 if (CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
982 CloseHandle( pi
.hThread
);
986 HeapFree( GetProcessHeap(), 0, buffer
);
990 /* execute rundll32 on the wine.inf file if necessary */
991 static void update_wineprefix( BOOL force
)
993 const char *config_dir
= wine_get_config_dir();
994 char *inf_path
= get_wine_inf_path();
1000 WINE_MESSAGE( "wine: failed to update %s, wine.inf not found\n", config_dir
);
1003 if ((fd
= open( inf_path
, O_RDONLY
)) == -1)
1005 WINE_MESSAGE( "wine: failed to update %s with %s: %s\n",
1006 config_dir
, inf_path
, strerror(errno
) );
1012 if (update_timestamp( config_dir
, st
.st_mtime
) || force
)
1017 if ((process
= start_rundll32( inf_path
, FALSE
)))
1019 HWND hwnd
= show_wait_window();
1023 DWORD res
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, INFINITE
, QS_ALLINPUT
);
1024 if (res
== WAIT_OBJECT_0
)
1026 CloseHandle( process
);
1027 if (count
++ || !(process
= start_rundll32( inf_path
, TRUE
))) break;
1029 else while (PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageW( &msg
);
1031 DestroyWindow( hwnd
);
1033 WINE_MESSAGE( "wine: configuration in '%s' has been updated.\n", config_dir
);
1037 HeapFree( GetProcessHeap(), 0, inf_path
);
1040 /* Process items in the StartUp group of the user's Programs under the Start Menu. Some installers put
1041 * shell links here to restart themselves after boot. */
1042 static BOOL
ProcessStartupItems(void)
1046 IMalloc
*ppM
= NULL
;
1047 IShellFolder
*psfDesktop
= NULL
, *psfStartup
= NULL
;
1048 LPITEMIDLIST pidlStartup
= NULL
, pidlItem
;
1050 IEnumIDList
*iEnumList
= NULL
;
1052 WCHAR wszCommand
[MAX_PATH
];
1054 WINE_TRACE("Processing items in the StartUp folder.\n");
1056 hr
= SHGetMalloc(&ppM
);
1059 WINE_ERR("Couldn't get IMalloc object.\n");
1063 hr
= SHGetDesktopFolder(&psfDesktop
);
1066 WINE_ERR("Couldn't get desktop folder.\n");
1070 hr
= SHGetSpecialFolderLocation(NULL
, CSIDL_STARTUP
, &pidlStartup
);
1073 WINE_TRACE("Couldn't get StartUp folder location.\n");
1077 hr
= IShellFolder_BindToObject(psfDesktop
, pidlStartup
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfStartup
);
1080 WINE_TRACE("Couldn't bind IShellFolder to StartUp folder.\n");
1084 hr
= IShellFolder_EnumObjects(psfStartup
, NULL
, SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &iEnumList
);
1087 WINE_TRACE("Unable to enumerate StartUp objects.\n");
1091 while (IEnumIDList_Next(iEnumList
, 1, &pidlItem
, &NumPIDLs
) == S_OK
&&
1094 hr
= IShellFolder_GetDisplayNameOf(psfStartup
, pidlItem
, SHGDN_FORPARSING
, &strret
);
1096 WINE_TRACE("Unable to get display name of enumeration item.\n");
1099 hr
= StrRetToBufW(&strret
, pidlItem
, wszCommand
, MAX_PATH
);
1101 WINE_TRACE("Unable to parse display name.\n");
1106 hinst
= ShellExecuteW(NULL
, NULL
, wszCommand
, NULL
, NULL
, SW_SHOWNORMAL
);
1107 if (PtrToUlong(hinst
) <= 32)
1108 WINE_WARN("Error %p executing command %s.\n", hinst
, wine_dbgstr_w(wszCommand
));
1112 IMalloc_Free(ppM
, pidlItem
);
1115 /* Return success */
1119 if (iEnumList
) IEnumIDList_Release(iEnumList
);
1120 if (psfStartup
) IShellFolder_Release(psfStartup
);
1121 if (pidlStartup
) IMalloc_Free(ppM
, pidlStartup
);
1126 static void usage(void)
1128 WINE_MESSAGE( "Usage: wineboot [options]\n" );
1129 WINE_MESSAGE( "Options;\n" );
1130 WINE_MESSAGE( " -h,--help Display this help message\n" );
1131 WINE_MESSAGE( " -e,--end-session End the current session cleanly\n" );
1132 WINE_MESSAGE( " -f,--force Force exit for processes that don't exit cleanly\n" );
1133 WINE_MESSAGE( " -i,--init Perform initialization for first Wine instance\n" );
1134 WINE_MESSAGE( " -k,--kill Kill running processes without any cleanup\n" );
1135 WINE_MESSAGE( " -r,--restart Restart only, don't do normal startup operations\n" );
1136 WINE_MESSAGE( " -s,--shutdown Shutdown only, don't reboot\n" );
1137 WINE_MESSAGE( " -u,--update Update the wineprefix directory\n" );
1140 static const char short_options
[] = "efhikrsu";
1142 static const struct option long_options
[] =
1144 { "help", 0, 0, 'h' },
1145 { "end-session", 0, 0, 'e' },
1146 { "force", 0, 0, 'f' },
1147 { "init" , 0, 0, 'i' },
1148 { "kill", 0, 0, 'k' },
1149 { "restart", 0, 0, 'r' },
1150 { "shutdown", 0, 0, 's' },
1151 { "update", 0, 0, 'u' },
1155 int main( int argc
, char *argv
[] )
1157 extern HANDLE CDECL
__wine_make_process_system(void);
1158 static const WCHAR RunW
[] = {'R','u','n',0};
1159 static const WCHAR RunOnceW
[] = {'R','u','n','O','n','c','e',0};
1160 static const WCHAR RunServicesW
[] = {'R','u','n','S','e','r','v','i','c','e','s',0};
1161 static const WCHAR RunServicesOnceW
[] = {'R','u','n','S','e','r','v','i','c','e','s','O','n','c','e',0};
1162 static const WCHAR wineboot_eventW
[] = {'_','_','w','i','n','e','b','o','o','t','_','e','v','e','n','t',0};
1164 /* First, set the current directory to SystemRoot */
1166 BOOL end_session
, force
, init
, kill
, restart
, shutdown
, update
;
1168 SECURITY_ATTRIBUTES sa
;
1171 end_session
= force
= init
= kill
= restart
= shutdown
= update
= FALSE
;
1172 GetWindowsDirectoryW( windowsdir
, MAX_PATH
);
1173 if( !SetCurrentDirectoryW( windowsdir
) )
1174 WINE_ERR("Cannot set the dir to %s (%d)\n", wine_dbgstr_w(windowsdir
), GetLastError() );
1176 if (IsWow64Process( GetCurrentProcess(), &is_wow64
) && is_wow64
)
1179 PROCESS_INFORMATION pi
;
1180 WCHAR filename
[MAX_PATH
];
1184 memset( &si
, 0, sizeof(si
) );
1186 GetModuleFileNameW( 0, filename
, MAX_PATH
);
1188 Wow64DisableWow64FsRedirection( &redir
);
1189 if (CreateProcessW( filename
, GetCommandLineW(), NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
1191 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename
) );
1192 WaitForSingleObject( pi
.hProcess
, INFINITE
);
1193 GetExitCodeProcess( pi
.hProcess
, &exit_code
);
1194 ExitProcess( exit_code
);
1196 else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename
), GetLastError() );
1197 Wow64RevertWow64FsRedirection( redir
);
1200 while ((optc
= getopt_long(argc
, argv
, short_options
, long_options
, NULL
)) != -1)
1204 case 'e': end_session
= TRUE
; break;
1205 case 'f': force
= TRUE
; break;
1206 case 'i': init
= TRUE
; break;
1207 case 'k': kill
= TRUE
; break;
1208 case 'r': restart
= TRUE
; break;
1209 case 's': shutdown
= TRUE
; break;
1210 case 'u': update
= TRUE
; break;
1211 case 'h': usage(); return 0;
1212 case '?': usage(); return 1;
1220 if (!shutdown_all_desktops( force
)) return 1;
1222 else if (!shutdown_close_windows( force
)) return 1;
1225 if (kill
) kill_processes( shutdown
);
1227 if (shutdown
) return 0;
1229 sa
.nLength
= sizeof(sa
);
1230 sa
.lpSecurityDescriptor
= NULL
;
1231 sa
.bInheritHandle
= TRUE
; /* so that services.exe inherits it */
1232 event
= CreateEventW( &sa
, TRUE
, FALSE
, wineboot_eventW
);
1234 ResetEvent( event
); /* in case this is a restart */
1236 create_hardware_registry_keys();
1237 create_dynamic_registry_keys();
1238 create_environment_registry_keys();
1242 ProcessWindowsFileProtection();
1243 ProcessRunKeys( HKEY_LOCAL_MACHINE
, RunServicesOnceW
, TRUE
, FALSE
);
1245 if (init
|| (kill
&& !restart
))
1247 ProcessRunKeys( HKEY_LOCAL_MACHINE
, RunServicesW
, FALSE
, FALSE
);
1248 start_services_process();
1250 if (init
|| update
) update_wineprefix( update
);
1252 create_volatile_environment_registry_key();
1254 ProcessRunKeys( HKEY_LOCAL_MACHINE
, RunOnceW
, TRUE
, TRUE
);
1256 if (!init
&& !restart
)
1258 ProcessRunKeys( HKEY_LOCAL_MACHINE
, RunW
, FALSE
, FALSE
);
1259 ProcessRunKeys( HKEY_CURRENT_USER
, RunW
, FALSE
, FALSE
);
1260 ProcessStartupItems();
1263 WINE_TRACE("Operation done\n");