wineboot: Start an additional 32-bit instance of rundll32 on 64-bit platforms to...
[wine] / programs / wineboot / wineboot.c
1 /*
2  * Copyright (C) 2002 Andreas Mohr
3  * Copyright (C) 2002 Shachar Shemesh
4  *
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.
9  *
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.
14  *
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
18  */
19 /* Wine "bootup" handler application
20  *
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):
26  *
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)
30  *
31  * Startup (before the user logs in)
32  * - Services (NT)
33  * - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce (9x, asynch)
34  * - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices (9x, asynch)
35  * 
36  * After log in
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)
42  *
43  * Somewhere in there is processing the RunOnceEx entries (also no imp)
44  * 
45  * Bugs:
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).
52  */
53
54 #include "config.h"
55 #include "wine/port.h"
56
57 #define COBJMACROS
58 #define WIN32_LEAN_AND_MEAN
59
60 #include <errno.h>
61 #include <fcntl.h>
62 #include <stdio.h>
63 #include <stdlib.h>
64 #ifdef HAVE_GETOPT_H
65 # include <getopt.h>
66 #endif
67 #ifdef HAVE_SYS_STAT_H
68 # include <sys/stat.h>
69 #endif
70 #ifdef HAVE_UNISTD_H
71 # include <unistd.h>
72 #endif
73 #include <windows.h>
74 #include <winternl.h>
75 #include <wine/svcctl.h>
76 #include <wine/unicode.h>
77 #include <wine/library.h>
78 #include <wine/debug.h>
79
80 #include <shlobj.h>
81 #include <shobjidl.h>
82 #include <shlwapi.h>
83 #include <shellapi.h>
84
85 WINE_DEFAULT_DEBUG_CHANNEL(wineboot);
86
87 #define MAX_LINE_LENGTH (2*MAX_PATH+2)
88
89 extern BOOL shutdown_close_windows( BOOL force );
90 extern void kill_processes( BOOL kill_desktop );
91
92 static WCHAR windowsdir[MAX_PATH];
93
94 /* retrieve the (unix) path to the wine.inf file */
95 static char *get_wine_inf_path(void)
96 {
97     const char *build_dir, *data_dir;
98     char *name = NULL;
99
100     if ((data_dir = wine_get_data_dir()))
101     {
102         if (!(name = HeapAlloc( GetProcessHeap(), 0, strlen(data_dir) + sizeof("/wine.inf") )))
103             return NULL;
104         strcpy( name, data_dir );
105         strcat( name, "/wine.inf" );
106     }
107     else if ((build_dir = wine_get_build_dir()))
108     {
109         if (!(name = HeapAlloc( GetProcessHeap(), 0, strlen(build_dir) + sizeof("/tools/wine.inf") )))
110             return NULL;
111         strcpy( name, build_dir );
112         strcat( name, "/tools/wine.inf" );
113     }
114     return name;
115 }
116
117 /* update the timestamp if different from the reference time */
118 static BOOL update_timestamp( const char *config_dir, unsigned long timestamp )
119 {
120     BOOL ret = FALSE;
121     int fd, count;
122     char buffer[100];
123     char *file = HeapAlloc( GetProcessHeap(), 0, strlen(config_dir) + sizeof("/.update-timestamp") );
124
125     if (!file) return FALSE;
126     strcpy( file, config_dir );
127     strcat( file, "/.update-timestamp" );
128
129     if ((fd = open( file, O_RDWR )) != -1)
130     {
131         if ((count = read( fd, buffer, sizeof(buffer) - 1 )) >= 0)
132         {
133             buffer[count] = 0;
134             if (!strncmp( buffer, "disable", sizeof("disable")-1 )) goto done;
135             if (timestamp == strtoul( buffer, NULL, 10 )) goto done;
136         }
137         lseek( fd, 0, SEEK_SET );
138         ftruncate( fd, 0 );
139     }
140     else
141     {
142         if (errno != ENOENT) goto done;
143         if ((fd = open( file, O_WRONLY | O_CREAT | O_TRUNC, 0666 )) == -1) goto done;
144     }
145
146     count = sprintf( buffer, "%lu\n", timestamp );
147     if (write( fd, buffer, count ) != count)
148     {
149         WINE_WARN( "failed to update timestamp in %s\n", file );
150         ftruncate( fd, 0 );
151     }
152     else ret = TRUE;
153
154 done:
155     if (fd != -1) close( fd );
156     HeapFree( GetProcessHeap(), 0, file );
157     return ret;
158 }
159
160 /* wrapper for RegSetValueExW */
161 static DWORD set_reg_value( HKEY hkey, const WCHAR *name, const WCHAR *value )
162 {
163     return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, (strlenW(value) + 1) * sizeof(WCHAR) );
164 }
165
166 /* create the volatile hardware registry keys */
167 static void create_hardware_registry_keys(void)
168 {
169     static const WCHAR SystemW[] = {'H','a','r','d','w','a','r','e','\\',
170                                     'D','e','s','c','r','i','p','t','i','o','n','\\',
171                                     'S','y','s','t','e','m',0};
172     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};
173     static const WCHAR cpuW[] = {'C','e','n','t','r','a','l','P','r','o','c','e','s','s','o','r',0};
174     static const WCHAR IdentifierW[] = {'I','d','e','n','t','i','f','i','e','r',0};
175     static const WCHAR SysidW[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0};
176     static const WCHAR mhzKeyW[] = {'~','M','H','z',0};
177     static const WCHAR VendorIdentifierW[] = {'V','e','n','d','o','r','I','d','e','n','t','i','f','i','e','r',0};
178     static const WCHAR VenidIntelW[] = {'G','e','n','u','i','n','e','I','n','t','e','l',0};
179     /* static const WCHAR VenidAMDW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0}; */
180     static const WCHAR PercentDW[] = {'%','d',0};
181     static const WCHAR IntelCpuDescrW[] = {'x','8','6',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
182                                            ' ','S','t','e','p','p','i','n','g',' ','%','d',0};
183     unsigned int i;
184     HKEY hkey, system_key, cpu_key, fpu_key;
185     SYSTEM_CPU_INFORMATION sci;
186     PROCESSOR_POWER_INFORMATION power_info;
187     WCHAR idW[60];
188
189     NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );
190     if (NtPowerInformation(ProcessorInformation, NULL, 0, &power_info, sizeof(power_info)))
191         power_info.MaxMhz = 0;
192
193     /*TODO: report 64bit processors properly*/
194     sprintfW( idW, IntelCpuDescrW, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) );
195
196     if (RegCreateKeyExW( HKEY_LOCAL_MACHINE, SystemW, 0, NULL, REG_OPTION_VOLATILE,
197                          KEY_ALL_ACCESS, NULL, &system_key, NULL ))
198         return;
199
200     set_reg_value( system_key, IdentifierW, SysidW );
201
202     if (RegCreateKeyExW( system_key, fpuW, 0, NULL, REG_OPTION_VOLATILE,
203                          KEY_ALL_ACCESS, NULL, &fpu_key, NULL ))
204         fpu_key = 0;
205     if (RegCreateKeyExW( system_key, cpuW, 0, NULL, REG_OPTION_VOLATILE,
206                          KEY_ALL_ACCESS, NULL, &cpu_key, NULL ))
207         cpu_key = 0;
208
209     for (i = 0; i < NtCurrentTeb()->Peb->NumberOfProcessors; i++)
210     {
211         WCHAR numW[10];
212
213         sprintfW( numW, PercentDW, i );
214         if (!RegCreateKeyExW( cpu_key, numW, 0, NULL, REG_OPTION_VOLATILE,
215                               KEY_ALL_ACCESS, NULL, &hkey, NULL ))
216         {
217             set_reg_value( hkey, IdentifierW, idW );
218             /*TODO; report amd's properly*/
219             set_reg_value( hkey, VendorIdentifierW, VenidIntelW );
220             RegSetValueExW( hkey, mhzKeyW, 0, REG_DWORD, (BYTE *)&power_info.MaxMhz, sizeof(DWORD) );
221             RegCloseKey( hkey );
222         }
223         if (!RegCreateKeyExW( fpu_key, numW, 0, NULL, REG_OPTION_VOLATILE,
224                               KEY_ALL_ACCESS, NULL, &hkey, NULL ))
225         {
226             set_reg_value( hkey, IdentifierW, idW );
227             RegCloseKey( hkey );
228         }
229     }
230     RegCloseKey( fpu_key );
231     RegCloseKey( cpu_key );
232     RegCloseKey( system_key );
233 }
234
235
236 /* create the DynData registry keys */
237 static void create_dynamic_registry_keys(void)
238 {
239     static const WCHAR StatDataW[] = {'P','e','r','f','S','t','a','t','s','\\',
240                                       'S','t','a','t','D','a','t','a',0};
241     static const WCHAR ConfigManagerW[] = {'C','o','n','f','i','g',' ','M','a','n','a','g','e','r','\\',
242                                            'E','n','u','m',0};
243     HKEY key;
244
245     if (!RegCreateKeyExW( HKEY_DYN_DATA, StatDataW, 0, NULL, 0, KEY_WRITE, NULL, &key, NULL ))
246         RegCloseKey( key );
247     if (!RegCreateKeyExW( HKEY_DYN_DATA, ConfigManagerW, 0, NULL, 0, KEY_WRITE, NULL, &key, NULL ))
248         RegCloseKey( key );
249 }
250
251 /* create the platform-specific environment registry keys */
252 static void create_environment_registry_keys( void )
253 {
254     static const WCHAR EnvironW[]  = {'S','y','s','t','e','m','\\',
255                                       'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
256                                       'C','o','n','t','r','o','l','\\',
257                                       'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
258                                       'E','n','v','i','r','o','n','m','e','n','t',0};
259     static const WCHAR NumProcW[]  = {'N','U','M','B','E','R','_','O','F','_','P','R','O','C','E','S','S','O','R','S',0};
260     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};
261     static const WCHAR x86W[]      = {'x','8','6',0};
262     static const WCHAR ProcIdW[]   = {'P','R','O','C','E','S','S','O','R','_','I','D','E','N','T','I','F','I','E','R',0};
263     static const WCHAR ProcLvlW[]  = {'P','R','O','C','E','S','S','O','R','_','L','E','V','E','L',0};
264     static const WCHAR ProcRevW[]  = {'P','R','O','C','E','S','S','O','R','_','R','E','V','I','S','I','O','N',0};
265     static const WCHAR PercentDW[] = {'%','d',0};
266     static const WCHAR Percent04XW[] = {'%','0','4','x',0};
267     static const WCHAR IntelCpuDescrW[]  = {'x','8','6',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
268                                             ' ','S','t','e','p','p','i','n','g',' ','%','d',',',' ','G','e','n','u','i','n','e','I','n','t','e','l',0};
269
270     HKEY env_key;
271     SYSTEM_CPU_INFORMATION sci;
272     WCHAR buffer[60];
273
274     NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );
275
276     if (RegCreateKeyW( HKEY_LOCAL_MACHINE, EnvironW, &env_key )) return;
277
278     sprintfW( buffer, PercentDW, NtCurrentTeb()->Peb->NumberOfProcessors );
279     set_reg_value( env_key, NumProcW, buffer );
280
281     /* TODO: currently hardcoded x86, add different processors */
282     set_reg_value( env_key, ProcArchW, x86W );
283
284     /* TODO: currently hardcoded Intel, add different processors */
285     sprintfW( buffer, IntelCpuDescrW, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) );
286     set_reg_value( env_key, ProcIdW, buffer );
287
288     sprintfW( buffer, PercentDW, sci.Level );
289     set_reg_value( env_key, ProcLvlW, buffer );
290
291     /* Properly report model/stepping */
292     sprintfW( buffer, Percent04XW, sci.Revision );
293     set_reg_value( env_key, ProcRevW, buffer );
294
295     RegCloseKey( env_key );
296 }
297
298 static void create_volatile_environment_registry_key(void)
299 {
300     static const WCHAR VolatileEnvW[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0};
301     static const WCHAR AppDataW[] = {'A','P','P','D','A','T','A',0};
302     static const WCHAR ClientNameW[] = {'C','L','I','E','N','T','N','A','M','E',0};
303     static const WCHAR HomeDriveW[] = {'H','O','M','E','D','R','I','V','E',0};
304     static const WCHAR HomePathW[] = {'H','O','M','E','P','A','T','H',0};
305     static const WCHAR HomeShareW[] = {'H','O','M','E','S','H','A','R','E',0};
306     static const WCHAR LocalAppDataW[] = {'L','O','C','A','L','A','P','P','D','A','T','A',0};
307     static const WCHAR LogonServerW[] = {'L','O','G','O','N','S','E','R','V','E','R',0};
308     static const WCHAR SessionNameW[] = {'S','E','S','S','I','O','N','N','A','M','E',0};
309     static const WCHAR UserNameW[] = {'U','S','E','R','N','A','M','E',0};
310     static const WCHAR UserProfileW[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
311     static const WCHAR ConsoleW[] = {'C','o','n','s','o','l','e',0};
312     static const WCHAR EmptyW[] = {0};
313     WCHAR path[MAX_PATH];
314     WCHAR computername[MAX_COMPUTERNAME_LENGTH + 1 + 2];
315     DWORD size;
316     HKEY hkey;
317     HRESULT hr;
318
319     if (RegCreateKeyExW( HKEY_CURRENT_USER, VolatileEnvW, 0, NULL, REG_OPTION_VOLATILE,
320                          KEY_ALL_ACCESS, NULL, &hkey, NULL ))
321         return;
322
323     hr = SHGetFolderPathW( NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path );
324     if (SUCCEEDED(hr)) set_reg_value( hkey, AppDataW, path );
325
326     set_reg_value( hkey, ClientNameW, ConsoleW );
327
328     /* Write the profile path's drive letter and directory components into
329      * HOMEDRIVE and HOMEPATH respectively. */
330     hr = SHGetFolderPathW( NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, path );
331     if (SUCCEEDED(hr))
332     {
333         set_reg_value( hkey, UserProfileW, path );
334         set_reg_value( hkey, HomePathW, path + 2 );
335         path[2] = '\0';
336         set_reg_value( hkey, HomeDriveW, path );
337     }
338
339     size = sizeof(path);
340     if (GetUserNameW( path, &size )) set_reg_value( hkey, UserNameW, path );
341
342     set_reg_value( hkey, HomeShareW, EmptyW );
343
344     hr = SHGetFolderPathW( NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path );
345     if (SUCCEEDED(hr))
346         set_reg_value( hkey, LocalAppDataW, path );
347
348     size = sizeof(computername) - 2;
349     if (GetComputerNameW(&computername[2], &size))
350     {
351         computername[0] = computername[1] = '\\';
352         set_reg_value( hkey, LogonServerW, computername );
353     }
354
355     set_reg_value( hkey, SessionNameW, ConsoleW );
356     RegCloseKey( hkey );
357 }
358
359 /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
360  * Returns FALSE if there was an error, or otherwise if all is ok.
361  */
362 static BOOL wininit(void)
363 {
364     static const WCHAR nulW[] = {'N','U','L',0};
365     static const WCHAR renameW[] = {'r','e','n','a','m','e',0};
366     static const WCHAR wininitW[] = {'w','i','n','i','n','i','t','.','i','n','i',0};
367     static const WCHAR wininitbakW[] = {'w','i','n','i','n','i','t','.','b','a','k',0};
368     WCHAR initial_buffer[1024];
369     WCHAR *str, *buffer = initial_buffer;
370     DWORD size = sizeof(initial_buffer)/sizeof(WCHAR);
371     DWORD res;
372
373     for (;;)
374     {
375         if (!(res = GetPrivateProfileSectionW( renameW, buffer, size, wininitW ))) return TRUE;
376         if (res < size - 2) break;
377         if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer );
378         size *= 2;
379         if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
380     }
381
382     for (str = buffer; *str; str += strlenW(str) + 1)
383     {
384         WCHAR *value;
385
386         if (*str == ';') continue;  /* comment */
387         if (!(value = strchrW( str, '=' ))) continue;
388
389         /* split the line into key and value */
390         *value++ = 0;
391
392         if (!lstrcmpiW( nulW, str ))
393         {
394             WINE_TRACE("Deleting file %s\n", wine_dbgstr_w(value) );
395             if( !DeleteFileW( value ) )
396                 WINE_WARN("Error deleting file %s\n", wine_dbgstr_w(value) );
397         }
398         else
399         {
400             WINE_TRACE("Renaming file %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) );
401
402             if( !MoveFileExW(value, str, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) )
403                 WINE_WARN("Error renaming %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) );
404         }
405         str = value;
406     }
407
408     if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer );
409
410     if( !MoveFileExW( wininitW, wininitbakW, MOVEFILE_REPLACE_EXISTING) )
411     {
412         WINE_ERR("Couldn't rename wininit.ini, error %d\n", GetLastError() );
413
414         return FALSE;
415     }
416
417     return TRUE;
418 }
419
420 static BOOL pendingRename(void)
421 {
422     static const WCHAR ValueName[] = {'P','e','n','d','i','n','g',
423                                       'F','i','l','e','R','e','n','a','m','e',
424                                       'O','p','e','r','a','t','i','o','n','s',0};
425     static const WCHAR SessionW[] = { 'S','y','s','t','e','m','\\',
426                                      'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
427                                      'C','o','n','t','r','o','l','\\',
428                                      'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
429     WCHAR *buffer=NULL;
430     const WCHAR *src=NULL, *dst=NULL;
431     DWORD dataLength=0;
432     HKEY hSession=NULL;
433     DWORD res;
434
435     WINE_TRACE("Entered\n");
436
437     if( (res=RegOpenKeyExW( HKEY_LOCAL_MACHINE, SessionW, 0, KEY_ALL_ACCESS, &hSession ))
438             !=ERROR_SUCCESS )
439     {
440         WINE_TRACE("The key was not found - skipping\n");
441         return TRUE;
442     }
443
444     res=RegQueryValueExW( hSession, ValueName, NULL, NULL /* The value type does not really interest us, as it is not
445                                                              truly a REG_MULTI_SZ anyways */,
446             NULL, &dataLength );
447     if( res==ERROR_FILE_NOT_FOUND )
448     {
449         /* No value - nothing to do. Great! */
450         WINE_TRACE("Value not present - nothing to rename\n");
451         res=TRUE;
452         goto end;
453     }
454
455     if( res!=ERROR_SUCCESS )
456     {
457         WINE_ERR("Couldn't query value's length (%d)\n", res );
458         res=FALSE;
459         goto end;
460     }
461
462     buffer=HeapAlloc( GetProcessHeap(),0,dataLength );
463     if( buffer==NULL )
464     {
465         WINE_ERR("Couldn't allocate %u bytes for the value\n", dataLength );
466         res=FALSE;
467         goto end;
468     }
469
470     res=RegQueryValueExW( hSession, ValueName, NULL, NULL, (LPBYTE)buffer, &dataLength );
471     if( res!=ERROR_SUCCESS )
472     {
473         WINE_ERR("Couldn't query value after successfully querying before (%u),\n"
474                 "please report to wine-devel@winehq.org\n", res);
475         res=FALSE;
476         goto end;
477     }
478
479     /* Make sure that the data is long enough and ends with two NULLs. This
480      * simplifies the code later on.
481      */
482     if( dataLength<2*sizeof(buffer[0]) ||
483             buffer[dataLength/sizeof(buffer[0])-1]!='\0' ||
484             buffer[dataLength/sizeof(buffer[0])-2]!='\0' )
485     {
486         WINE_ERR("Improper value format - doesn't end with NULL\n");
487         res=FALSE;
488         goto end;
489     }
490
491     for( src=buffer; (src-buffer)*sizeof(src[0])<dataLength && *src!='\0';
492             src=dst+lstrlenW(dst)+1 )
493     {
494         DWORD dwFlags=0;
495
496         WINE_TRACE("processing next command\n");
497
498         dst=src+lstrlenW(src)+1;
499
500         /* We need to skip the \??\ header */
501         if( src[0]=='\\' && src[1]=='?' && src[2]=='?' && src[3]=='\\' )
502             src+=4;
503
504         if( dst[0]=='!' )
505         {
506             dwFlags|=MOVEFILE_REPLACE_EXISTING;
507             dst++;
508         }
509
510         if( dst[0]=='\\' && dst[1]=='?' && dst[2]=='?' && dst[3]=='\\' )
511             dst+=4;
512
513         if( *dst!='\0' )
514         {
515             /* Rename the file */
516             MoveFileExW( src, dst, dwFlags );
517         } else
518         {
519             /* Delete the file or directory */
520             if( (res=GetFileAttributesW(src))!=INVALID_FILE_ATTRIBUTES )
521             {
522                 if( (res&FILE_ATTRIBUTE_DIRECTORY)==0 )
523                 {
524                     /* It's a file */
525                     DeleteFileW(src);
526                 } else
527                 {
528                     /* It's a directory */
529                     RemoveDirectoryW(src);
530                 }
531             } else
532             {
533                 WINE_ERR("couldn't get file attributes (%d)\n", GetLastError() );
534             }
535         }
536     }
537
538     if((res=RegDeleteValueW(hSession, ValueName))!=ERROR_SUCCESS )
539     {
540         WINE_ERR("Error deleting the value (%u)\n", GetLastError() );
541         res=FALSE;
542     } else
543         res=TRUE;
544     
545 end:
546     HeapFree(GetProcessHeap(), 0, buffer);
547
548     if( hSession!=NULL )
549         RegCloseKey( hSession );
550
551     return res;
552 }
553
554 enum runkeys {
555     RUNKEY_RUN, RUNKEY_RUNONCE, RUNKEY_RUNSERVICES, RUNKEY_RUNSERVICESONCE
556 };
557
558 const WCHAR runkeys_names[][30]=
559 {
560     {'R','u','n',0},
561     {'R','u','n','O','n','c','e',0},
562     {'R','u','n','S','e','r','v','i','c','e','s',0},
563     {'R','u','n','S','e','r','v','i','c','e','s','O','n','c','e',0}
564 };
565
566 #define INVALID_RUNCMD_RETURN -1
567 /*
568  * This function runs the specified command in the specified dir.
569  * [in,out] cmdline - the command line to run. The function may change the passed buffer.
570  * [in] dir - the dir to run the command in. If it is NULL, then the current dir is used.
571  * [in] wait - whether to wait for the run program to finish before returning.
572  * [in] minimized - Whether to ask the program to run minimized.
573  *
574  * Returns:
575  * If running the process failed, returns INVALID_RUNCMD_RETURN. Use GetLastError to get the error code.
576  * If wait is FALSE - returns 0 if successful.
577  * If wait is TRUE - returns the program's return value.
578  */
579 static DWORD runCmd(LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
580 {
581     STARTUPINFOW si;
582     PROCESS_INFORMATION info;
583     DWORD exit_code=0;
584
585     memset(&si, 0, sizeof(si));
586     si.cb=sizeof(si);
587     if( minimized )
588     {
589         si.dwFlags=STARTF_USESHOWWINDOW;
590         si.wShowWindow=SW_MINIMIZE;
591     }
592     memset(&info, 0, sizeof(info));
593
594     if( !CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, dir, &si, &info) )
595     {
596         WINE_WARN("Failed to run command %s (%d)\n", wine_dbgstr_w(cmdline), GetLastError() );
597         return INVALID_RUNCMD_RETURN;
598     }
599
600     WINE_TRACE("Successfully ran command %s - Created process handle %p\n",
601                wine_dbgstr_w(cmdline), info.hProcess );
602
603     if(wait)
604     {   /* wait for the process to exit */
605         WaitForSingleObject(info.hProcess, INFINITE);
606         GetExitCodeProcess(info.hProcess, &exit_code);
607     }
608
609     CloseHandle( info.hThread );
610     CloseHandle( info.hProcess );
611
612     return exit_code;
613 }
614
615 /*
616  * Process a "Run" type registry key.
617  * hkRoot is the HKEY from which "Software\Microsoft\Windows\CurrentVersion" is
618  *      opened.
619  * szKeyName is the key holding the actual entries.
620  * bDelete tells whether we should delete each value right before executing it.
621  * bSynchronous tells whether we should wait for the prog to complete before
622  *      going on to the next prog.
623  */
624 static BOOL ProcessRunKeys( HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete,
625         BOOL bSynchronous )
626 {
627     static const WCHAR WINKEY_NAME[]={'S','o','f','t','w','a','r','e','\\',
628         'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
629         'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
630     HKEY hkWin, hkRun;
631     DWORD res;
632     DWORD i, nMaxCmdLine=0, nMaxValue=0;
633     WCHAR *szCmdLine=NULL;
634     WCHAR *szValue=NULL;
635
636     if (hkRoot==HKEY_LOCAL_MACHINE)
637         WINE_TRACE("processing %s entries under HKLM\n",wine_dbgstr_w(szKeyName) );
638     else
639         WINE_TRACE("processing %s entries under HKCU\n",wine_dbgstr_w(szKeyName) );
640
641     if (RegOpenKeyExW( hkRoot, WINKEY_NAME, 0, KEY_READ, &hkWin ) != ERROR_SUCCESS)
642         return TRUE;
643
644     if (RegOpenKeyExW( hkWin, szKeyName, 0, bDelete?KEY_ALL_ACCESS:KEY_READ, &hkRun ) != ERROR_SUCCESS)
645     {
646         RegCloseKey( hkWin );
647         return TRUE;
648     }
649     RegCloseKey( hkWin );
650
651     if( (res=RegQueryInfoKeyW( hkRun, NULL, NULL, NULL, NULL, NULL, NULL, &i, &nMaxValue,
652                     &nMaxCmdLine, NULL, NULL ))!=ERROR_SUCCESS )
653         goto end;
654
655     if( i==0 )
656     {
657         WINE_TRACE("No commands to execute.\n");
658
659         res=ERROR_SUCCESS;
660         goto end;
661     }
662     
663     if( (szCmdLine=HeapAlloc(GetProcessHeap(),0,nMaxCmdLine))==NULL )
664     {
665         WINE_ERR("Couldn't allocate memory for the commands to be executed\n");
666
667         res=ERROR_NOT_ENOUGH_MEMORY;
668         goto end;
669     }
670
671     if( (szValue=HeapAlloc(GetProcessHeap(),0,(++nMaxValue)*sizeof(*szValue)))==NULL )
672     {
673         WINE_ERR("Couldn't allocate memory for the value names\n");
674
675         res=ERROR_NOT_ENOUGH_MEMORY;
676         goto end;
677     }
678     
679     while( i>0 )
680     {
681         DWORD nValLength=nMaxValue, nDataLength=nMaxCmdLine;
682         DWORD type;
683
684         --i;
685
686         if( (res=RegEnumValueW( hkRun, i, szValue, &nValLength, 0, &type,
687                         (LPBYTE)szCmdLine, &nDataLength ))!=ERROR_SUCCESS )
688         {
689             WINE_ERR("Couldn't read in value %d - %d\n", i, res );
690
691             continue;
692         }
693
694         if( bDelete && (res=RegDeleteValueW( hkRun, szValue ))!=ERROR_SUCCESS )
695         {
696             WINE_ERR("Couldn't delete value - %d, %d. Running command anyways.\n", i, res );
697         }
698         
699         if( type!=REG_SZ )
700         {
701             WINE_ERR("Incorrect type of value #%d (%d)\n", i, type );
702
703             continue;
704         }
705
706         if( (res=runCmd(szCmdLine, NULL, bSynchronous, FALSE ))==INVALID_RUNCMD_RETURN )
707         {
708             WINE_ERR("Error running cmd %s (%d)\n", wine_dbgstr_w(szCmdLine), GetLastError() );
709         }
710
711         WINE_TRACE("Done processing cmd #%d\n", i);
712     }
713
714     res=ERROR_SUCCESS;
715
716 end:
717     HeapFree( GetProcessHeap(), 0, szValue );
718     HeapFree( GetProcessHeap(), 0, szCmdLine );
719
720     if( hkRun!=NULL )
721         RegCloseKey( hkRun );
722
723     WINE_TRACE("done\n");
724
725     return res==ERROR_SUCCESS;
726 }
727
728 /*
729  * WFP is Windows File Protection, in NT5 and Windows 2000 it maintains a cache
730  * of known good dlls and scans through and replaces corrupted DLLs with these
731  * known good versions. The only programs that should install into this dll
732  * cache are Windows Updates and IE (which is treated like a Windows Update)
733  *
734  * Implementing this allows installing ie in win2k mode to actually install the
735  * system dlls that we expect and need
736  */
737 static int ProcessWindowsFileProtection(void)
738 {
739     static const WCHAR winlogonW[] = {'S','o','f','t','w','a','r','e','\\',
740                                       'M','i','c','r','o','s','o','f','t','\\',
741                                       'W','i','n','d','o','w','s',' ','N','T','\\',
742                                       'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
743                                       'W','i','n','l','o','g','o','n',0};
744     static const WCHAR cachedirW[] = {'S','F','C','D','l','l','C','a','c','h','e','D','i','r',0};
745     static const WCHAR dllcacheW[] = {'\\','d','l','l','c','a','c','h','e','\\','*',0};
746     static const WCHAR wildcardW[] = {'\\','*',0};
747     WIN32_FIND_DATAW finddata;
748     HANDLE find_handle;
749     BOOL find_rc;
750     DWORD rc;
751     HKEY hkey;
752     LPWSTR dllcache = NULL;
753
754     if (!RegOpenKeyW( HKEY_LOCAL_MACHINE, winlogonW, &hkey ))
755     {
756         DWORD sz = 0;
757         if (!RegQueryValueExW( hkey, cachedirW, 0, NULL, NULL, &sz))
758         {
759             sz += sizeof(WCHAR);
760             dllcache = HeapAlloc(GetProcessHeap(),0,sz + sizeof(wildcardW));
761             RegQueryValueExW( hkey, cachedirW, 0, NULL, (LPBYTE)dllcache, &sz);
762             strcatW( dllcache, wildcardW );
763         }
764     }
765     RegCloseKey(hkey);
766
767     if (!dllcache)
768     {
769         DWORD sz = GetSystemDirectoryW( NULL, 0 );
770         dllcache = HeapAlloc( GetProcessHeap(), 0, sz * sizeof(WCHAR) + sizeof(dllcacheW));
771         GetSystemDirectoryW( dllcache, sz );
772         strcatW( dllcache, dllcacheW );
773     }
774
775     find_handle = FindFirstFileW(dllcache,&finddata);
776     dllcache[ strlenW(dllcache) - 2] = 0; /* strip off wildcard */
777     find_rc = find_handle != INVALID_HANDLE_VALUE;
778     while (find_rc)
779     {
780         static const WCHAR dotW[] = {'.',0};
781         static const WCHAR dotdotW[] = {'.','.',0};
782         WCHAR targetpath[MAX_PATH];
783         WCHAR currentpath[MAX_PATH];
784         UINT sz;
785         UINT sz2;
786         WCHAR tempfile[MAX_PATH];
787
788         if (strcmpW(finddata.cFileName,dotW) == 0 || strcmpW(finddata.cFileName,dotdotW) == 0)
789         {
790             find_rc = FindNextFileW(find_handle,&finddata);
791             continue;
792         }
793
794         sz = MAX_PATH;
795         sz2 = MAX_PATH;
796         VerFindFileW(VFFF_ISSHAREDFILE, finddata.cFileName, windowsdir,
797                      windowsdir, currentpath, &sz, targetpath, &sz2);
798         sz = MAX_PATH;
799         rc = VerInstallFileW(0, finddata.cFileName, finddata.cFileName,
800                              dllcache, targetpath, currentpath, tempfile, &sz);
801         if (rc != ERROR_SUCCESS)
802         {
803             WINE_WARN("WFP: %s error 0x%x\n",wine_dbgstr_w(finddata.cFileName),rc);
804             DeleteFileW(tempfile);
805         }
806
807         /* now delete the source file so that we don't try to install it over and over again */
808         lstrcpynW( targetpath, dllcache, MAX_PATH - 1 );
809         sz = strlenW( targetpath );
810         targetpath[sz++] = '\\';
811         lstrcpynW( targetpath + sz, finddata.cFileName, MAX_PATH - sz );
812         if (!DeleteFileW( targetpath ))
813             WINE_WARN( "failed to delete %s: error %u\n", wine_dbgstr_w(targetpath), GetLastError() );
814
815         find_rc = FindNextFileW(find_handle,&finddata);
816     }
817     FindClose(find_handle);
818     HeapFree(GetProcessHeap(),0,dllcache);
819     return 1;
820 }
821
822 static BOOL start_services_process(void)
823 {
824     static const WCHAR svcctl_started_event[] = SVCCTL_STARTED_EVENT;
825     static const WCHAR services[] = {'\\','s','e','r','v','i','c','e','s','.','e','x','e',0};
826     PROCESS_INFORMATION pi;
827     STARTUPINFOW si;
828     HANDLE wait_handles[2];
829     WCHAR path[MAX_PATH];
830
831     if (!GetSystemDirectoryW(path, MAX_PATH - strlenW(services)))
832         return FALSE;
833     strcatW(path, services);
834     ZeroMemory(&si, sizeof(si));
835     si.cb = sizeof(si);
836     if (!CreateProcessW(path, path, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
837     {
838         WINE_ERR("Couldn't start services.exe: error %u\n", GetLastError());
839         return FALSE;
840     }
841     CloseHandle(pi.hThread);
842
843     wait_handles[0] = CreateEventW(NULL, TRUE, FALSE, svcctl_started_event);
844     wait_handles[1] = pi.hProcess;
845
846     /* wait for the event to become available or the process to exit */
847     if ((WaitForMultipleObjects(2, wait_handles, FALSE, INFINITE)) == WAIT_OBJECT_0 + 1)
848     {
849         DWORD exit_code;
850         GetExitCodeProcess(pi.hProcess, &exit_code);
851         WINE_ERR("Unexpected termination of services.exe - exit code %d\n", exit_code);
852         CloseHandle(pi.hProcess);
853         CloseHandle(wait_handles[0]);
854         return FALSE;
855     }
856
857     CloseHandle(pi.hProcess);
858     CloseHandle(wait_handles[0]);
859     return TRUE;
860 }
861
862 static HANDLE start_rundll32( const char *inf_path, BOOL wow64 )
863 {
864     static const WCHAR rundll[] = {'\\','r','u','n','d','l','l','3','2','.','e','x','e',0};
865     static const WCHAR setupapi[] = {' ','s','e','t','u','p','a','p','i',',',
866                                      'I','n','s','t','a','l','l','H','i','n','f','S','e','c','t','i','o','n',0};
867     static const WCHAR definstall[] = {' ','D','e','f','a','u','l','t','I','n','s','t','a','l','l',0};
868     static const WCHAR wowinstall[] = {' ','W','o','w','6','4','I','n','s','t','a','l','l',0};
869     static const WCHAR inf[] = {' ','1','2','8',' ','\\','\\','?','\\','u','n','i','x',0 };
870
871     WCHAR app[MAX_PATH + sizeof(rundll)/sizeof(WCHAR)];
872     STARTUPINFOW si;
873     PROCESS_INFORMATION pi;
874     WCHAR *buffer;
875     DWORD inf_len, cmd_len;
876
877     memset( &si, 0, sizeof(si) );
878     si.cb = sizeof(si);
879
880     if (wow64)
881     {
882         if (!GetSystemWow64DirectoryW( app, MAX_PATH )) return 0;  /* not on 64-bit */
883     }
884     else GetSystemDirectoryW( app, MAX_PATH );
885
886     strcatW( app, rundll );
887
888     cmd_len = strlenW(app) * sizeof(WCHAR) + sizeof(setupapi) + sizeof(definstall) + sizeof(inf);
889     inf_len = MultiByteToWideChar( CP_UNIXCP, 0, inf_path, -1, NULL, 0 );
890
891     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, cmd_len + inf_len * sizeof(WCHAR) ))) return 0;
892
893     strcpyW( buffer, app );
894     strcatW( buffer, setupapi );
895     strcatW( buffer, wow64 ? wowinstall : definstall );
896     strcatW( buffer, inf );
897     MultiByteToWideChar( CP_UNIXCP, 0, inf_path, -1, buffer + strlenW(buffer), inf_len );
898
899     if (CreateProcessW( app, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
900         CloseHandle( pi.hThread );
901     else
902         pi.hProcess = 0;
903
904     HeapFree( GetProcessHeap(), 0, buffer );
905     return pi.hProcess;
906 }
907
908 /* execute rundll32 on the wine.inf file if necessary */
909 static void update_wineprefix( int force )
910 {
911     const char *config_dir = wine_get_config_dir();
912     char *inf_path = get_wine_inf_path();
913     int fd;
914     struct stat st;
915
916     if (!inf_path)
917     {
918         WINE_MESSAGE( "wine: failed to update %s, wine.inf not found\n", config_dir );
919         return;
920     }
921     if ((fd = open( inf_path, O_RDONLY )) == -1)
922     {
923         WINE_MESSAGE( "wine: failed to update %s with %s: %s\n",
924                       config_dir, inf_path, strerror(errno) );
925         goto done;
926     }
927     fstat( fd, &st );
928     close( fd );
929
930     if (update_timestamp( config_dir, st.st_mtime ) || force)
931     {
932         HANDLE process;
933
934         if ((process = start_rundll32( inf_path, FALSE )))
935         {
936             WaitForSingleObject( process, INFINITE );
937             CloseHandle( process );
938         }
939         if ((process = start_rundll32( inf_path, TRUE )))
940         {
941             WaitForSingleObject( process, INFINITE );
942             CloseHandle( process );
943         }
944         WINE_MESSAGE( "wine: configuration in '%s' has been updated.\n", config_dir );
945     }
946
947 done:
948     HeapFree( GetProcessHeap(), 0, inf_path );
949 }
950
951 /* Process items in the StartUp group of the user's Programs under the Start Menu. Some installers put
952  * shell links here to restart themselves after boot. */
953 static BOOL ProcessStartupItems(void)
954 {
955     BOOL ret = FALSE;
956     HRESULT hr;
957     IMalloc *ppM = NULL;
958     IShellFolder *psfDesktop = NULL, *psfStartup = NULL;
959     LPITEMIDLIST pidlStartup = NULL, pidlItem;
960     ULONG NumPIDLs;
961     IEnumIDList *iEnumList = NULL;
962     STRRET strret;
963     WCHAR wszCommand[MAX_PATH];
964
965     WINE_TRACE("Processing items in the StartUp folder.\n");
966
967     hr = SHGetMalloc(&ppM);
968     if (FAILED(hr))
969     {
970         WINE_ERR("Couldn't get IMalloc object.\n");
971         goto done;
972     }
973
974     hr = SHGetDesktopFolder(&psfDesktop);
975     if (FAILED(hr))
976     {
977         WINE_ERR("Couldn't get desktop folder.\n");
978         goto done;
979     }
980
981     hr = SHGetSpecialFolderLocation(NULL, CSIDL_STARTUP, &pidlStartup);
982     if (FAILED(hr))
983     {
984         WINE_TRACE("Couldn't get StartUp folder location.\n");
985         goto done;
986     }
987
988     hr = IShellFolder_BindToObject(psfDesktop, pidlStartup, NULL, &IID_IShellFolder, (LPVOID*)&psfStartup);
989     if (FAILED(hr))
990     {
991         WINE_TRACE("Couldn't bind IShellFolder to StartUp folder.\n");
992         goto done;
993     }
994
995     hr = IShellFolder_EnumObjects(psfStartup, NULL, SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
996     if (FAILED(hr))
997     {
998         WINE_TRACE("Unable to enumerate StartUp objects.\n");
999         goto done;
1000     }
1001
1002     while (IEnumIDList_Next(iEnumList, 1, &pidlItem, &NumPIDLs) == S_OK &&
1003            (NumPIDLs) == 1)
1004     {
1005         hr = IShellFolder_GetDisplayNameOf(psfStartup, pidlItem, SHGDN_FORPARSING, &strret);
1006         if (FAILED(hr))
1007             WINE_TRACE("Unable to get display name of enumeration item.\n");
1008         else
1009         {
1010             hr = StrRetToBufW(&strret, pidlItem, wszCommand, MAX_PATH);
1011             if (FAILED(hr))
1012                 WINE_TRACE("Unable to parse display name.\n");
1013             else
1014             {
1015                 HINSTANCE hinst;
1016
1017                 hinst = ShellExecuteW(NULL, NULL, wszCommand, NULL, NULL, SW_SHOWNORMAL);
1018                 if (PtrToUlong(hinst) <= 32)
1019                     WINE_WARN("Error %p executing command %s.\n", hinst, wine_dbgstr_w(wszCommand));
1020             }
1021         }
1022
1023         IMalloc_Free(ppM, pidlItem);
1024     }
1025
1026     /* Return success */
1027     ret = TRUE;
1028
1029 done:
1030     if (iEnumList) IEnumIDList_Release(iEnumList);
1031     if (psfStartup) IShellFolder_Release(psfStartup);
1032     if (pidlStartup) IMalloc_Free(ppM, pidlStartup);
1033
1034     return ret;
1035 }
1036
1037 static void usage(void)
1038 {
1039     WINE_MESSAGE( "Usage: wineboot [options]\n" );
1040     WINE_MESSAGE( "Options;\n" );
1041     WINE_MESSAGE( "    -h,--help         Display this help message\n" );
1042     WINE_MESSAGE( "    -e,--end-session  End the current session cleanly\n" );
1043     WINE_MESSAGE( "    -f,--force        Force exit for processes that don't exit cleanly\n" );
1044     WINE_MESSAGE( "    -i,--init         Perform initialization for first Wine instance\n" );
1045     WINE_MESSAGE( "    -k,--kill         Kill running processes without any cleanup\n" );
1046     WINE_MESSAGE( "    -r,--restart      Restart only, don't do normal startup operations\n" );
1047     WINE_MESSAGE( "    -s,--shutdown     Shutdown only, don't reboot\n" );
1048     WINE_MESSAGE( "    -u,--update       Update the wineprefix directory\n" );
1049 }
1050
1051 static const char short_options[] = "efhikrsu";
1052
1053 static const struct option long_options[] =
1054 {
1055     { "help",        0, 0, 'h' },
1056     { "end-session", 0, 0, 'e' },
1057     { "force",       0, 0, 'f' },
1058     { "init" ,       0, 0, 'i' },
1059     { "kill",        0, 0, 'k' },
1060     { "restart",     0, 0, 'r' },
1061     { "shutdown",    0, 0, 's' },
1062     { "update",      0, 0, 'u' },
1063     { NULL,          0, 0, 0 }
1064 };
1065
1066 int main( int argc, char *argv[] )
1067 {
1068     extern HANDLE CDECL __wine_make_process_system(void);
1069     static const WCHAR wineboot_eventW[] = {'_','_','w','i','n','e','b','o','o','t','_','e','v','e','n','t',0};
1070
1071     /* First, set the current directory to SystemRoot */
1072     int optc;
1073     int end_session = 0, force = 0, init = 0, kill = 0, restart = 0, shutdown = 0, update = 0;
1074     HANDLE event;
1075     SECURITY_ATTRIBUTES sa;
1076
1077     GetWindowsDirectoryW( windowsdir, MAX_PATH );
1078     if( !SetCurrentDirectoryW( windowsdir ) )
1079         WINE_ERR("Cannot set the dir to %s (%d)\n", wine_dbgstr_w(windowsdir), GetLastError() );
1080
1081     while ((optc = getopt_long(argc, argv, short_options, long_options, NULL )) != -1)
1082     {
1083         switch(optc)
1084         {
1085         case 'e': end_session = 1; break;
1086         case 'f': force = 1; break;
1087         case 'i': init = 1; break;
1088         case 'k': kill = 1; break;
1089         case 'r': restart = 1; break;
1090         case 's': shutdown = 1; break;
1091         case 'u': update = 1; break;
1092         case 'h': usage(); return 0;
1093         case '?': usage(); return 1;
1094         }
1095     }
1096
1097     if (end_session)
1098     {
1099         if (!shutdown_close_windows( force )) return 1;
1100     }
1101
1102     if (kill) kill_processes( shutdown );
1103
1104     if (shutdown) return 0;
1105
1106     sa.nLength = sizeof(sa);
1107     sa.lpSecurityDescriptor = NULL;
1108     sa.bInheritHandle = TRUE;  /* so that services.exe inherits it */
1109     event = CreateEventW( &sa, TRUE, FALSE, wineboot_eventW );
1110
1111     ResetEvent( event );  /* in case this is a restart */
1112
1113     create_hardware_registry_keys();
1114     create_dynamic_registry_keys();
1115     create_environment_registry_keys();
1116     wininit();
1117     pendingRename();
1118
1119     ProcessWindowsFileProtection();
1120     ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNSERVICESONCE], TRUE, FALSE );
1121
1122     if (init || (kill && !restart))
1123     {
1124         ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNSERVICES], FALSE, FALSE );
1125         start_services_process();
1126     }
1127     if (init || update) update_wineprefix( update );
1128
1129     create_volatile_environment_registry_key();
1130
1131     ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNONCE], TRUE, TRUE );
1132
1133     if (!init && !restart)
1134     {
1135         ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUN], FALSE, FALSE );
1136         ProcessRunKeys( HKEY_CURRENT_USER, runkeys_names[RUNKEY_RUN], FALSE, FALSE );
1137         ProcessStartupItems();
1138     }
1139
1140     WINE_TRACE("Operation done\n");
1141
1142     SetEvent( event );
1143     return 0;
1144 }