cmd: Update Italian translation.
[wine/multimedia.git] / programs / wineboot / wineboot.c
blob28292add137f48bd23acd16137ea0ecaf323a877
1 /*
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)
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)
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)
43 * Somewhere in there is processing the RunOnceEx entries (also no imp)
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).
54 #include "config.h"
55 #include "wine/port.h"
57 #define COBJMACROS
58 #define WIN32_LEAN_AND_MEAN
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>
80 #include <shlobj.h>
81 #include <shobjidl.h>
82 #include <shlwapi.h>
83 #include <shellapi.h>
84 #include "resource.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;
100 char *name = NULL;
102 if ((data_dir = wine_get_data_dir()))
104 if (!(name = HeapAlloc( GetProcessHeap(), 0, strlen(data_dir) + sizeof("/wine.inf") )))
105 return NULL;
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("/tools/wine.inf") )))
112 return NULL;
113 strcpy( name, build_dir );
114 strcat( name, "/tools/wine.inf" );
116 return name;
119 /* update the timestamp if different from the reference time */
120 static BOOL update_timestamp( const char *config_dir, unsigned long timestamp )
122 BOOL ret = FALSE;
123 int fd, count;
124 char buffer[100];
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)
135 buffer[count] = 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 );
140 ftruncate( fd, 0 );
142 else
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 );
152 ftruncate( fd, 0 );
154 else ret = TRUE;
156 done:
157 if (fd != -1) close( fd );
158 HeapFree( GetProcessHeap(), 0, file );
159 return ret;
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 IdentifierW[] = {'I','d','e','n','t','i','f','i','e','r',0};
177 static const WCHAR SysidW[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0};
178 static const WCHAR mhzKeyW[] = {'~','M','H','z',0};
179 static const WCHAR VendorIdentifierW[] = {'V','e','n','d','o','r','I','d','e','n','t','i','f','i','e','r',0};
180 static const WCHAR VenidIntelW[] = {'G','e','n','u','i','n','e','I','n','t','e','l',0};
181 /* static const WCHAR VenidAMDW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0}; */
182 static const WCHAR PercentDW[] = {'%','d',0};
183 static const WCHAR IntelCpuDescrW[] = {'x','8','6',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
184 ' ','S','t','e','p','p','i','n','g',' ','%','d',0};
185 unsigned int i;
186 HKEY hkey, system_key, cpu_key, fpu_key;
187 SYSTEM_CPU_INFORMATION sci;
188 PROCESSOR_POWER_INFORMATION power_info;
189 WCHAR idW[60];
191 NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );
192 if (NtPowerInformation(ProcessorInformation, NULL, 0, &power_info, sizeof(power_info)))
193 power_info.MaxMhz = 0;
195 /*TODO: report 64bit processors properly*/
196 sprintfW( idW, IntelCpuDescrW, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) );
198 if (RegCreateKeyExW( HKEY_LOCAL_MACHINE, SystemW, 0, NULL, REG_OPTION_VOLATILE,
199 KEY_ALL_ACCESS, NULL, &system_key, NULL ))
200 return;
202 set_reg_value( system_key, IdentifierW, SysidW );
204 if (RegCreateKeyExW( system_key, fpuW, 0, NULL, REG_OPTION_VOLATILE,
205 KEY_ALL_ACCESS, NULL, &fpu_key, NULL ))
206 fpu_key = 0;
207 if (RegCreateKeyExW( system_key, cpuW, 0, NULL, REG_OPTION_VOLATILE,
208 KEY_ALL_ACCESS, NULL, &cpu_key, NULL ))
209 cpu_key = 0;
211 for (i = 0; i < NtCurrentTeb()->Peb->NumberOfProcessors; i++)
213 WCHAR numW[10];
215 sprintfW( numW, PercentDW, i );
216 if (!RegCreateKeyExW( cpu_key, numW, 0, NULL, REG_OPTION_VOLATILE,
217 KEY_ALL_ACCESS, NULL, &hkey, NULL ))
219 set_reg_value( hkey, IdentifierW, idW );
220 /*TODO; report amd's properly*/
221 set_reg_value( hkey, VendorIdentifierW, VenidIntelW );
222 RegSetValueExW( hkey, mhzKeyW, 0, REG_DWORD, (BYTE *)&power_info.MaxMhz, sizeof(DWORD) );
223 RegCloseKey( hkey );
225 if (!RegCreateKeyExW( fpu_key, numW, 0, NULL, REG_OPTION_VOLATILE,
226 KEY_ALL_ACCESS, NULL, &hkey, NULL ))
228 set_reg_value( hkey, IdentifierW, idW );
229 RegCloseKey( hkey );
232 RegCloseKey( fpu_key );
233 RegCloseKey( cpu_key );
234 RegCloseKey( system_key );
238 /* create the DynData registry keys */
239 static void create_dynamic_registry_keys(void)
241 static const WCHAR StatDataW[] = {'P','e','r','f','S','t','a','t','s','\\',
242 'S','t','a','t','D','a','t','a',0};
243 static const WCHAR ConfigManagerW[] = {'C','o','n','f','i','g',' ','M','a','n','a','g','e','r','\\',
244 'E','n','u','m',0};
245 HKEY key;
247 if (!RegCreateKeyExW( HKEY_DYN_DATA, StatDataW, 0, NULL, 0, KEY_WRITE, NULL, &key, NULL ))
248 RegCloseKey( key );
249 if (!RegCreateKeyExW( HKEY_DYN_DATA, ConfigManagerW, 0, NULL, 0, KEY_WRITE, NULL, &key, NULL ))
250 RegCloseKey( key );
253 /* create the platform-specific environment registry keys */
254 static void create_environment_registry_keys( void )
256 static const WCHAR EnvironW[] = {'S','y','s','t','e','m','\\',
257 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
258 'C','o','n','t','r','o','l','\\',
259 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
260 'E','n','v','i','r','o','n','m','e','n','t',0};
261 static const WCHAR NumProcW[] = {'N','U','M','B','E','R','_','O','F','_','P','R','O','C','E','S','S','O','R','S',0};
262 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};
263 static const WCHAR x86W[] = {'x','8','6',0};
264 static const WCHAR IA64W[] = {'I','A','6','4',0};
265 static const WCHAR AMD64W[] = {'A','M','D','6','4',0};
266 static const WCHAR ProcIdW[] = {'P','R','O','C','E','S','S','O','R','_','I','D','E','N','T','I','F','I','E','R',0};
267 static const WCHAR ProcLvlW[] = {'P','R','O','C','E','S','S','O','R','_','L','E','V','E','L',0};
268 static const WCHAR ProcRevW[] = {'P','R','O','C','E','S','S','O','R','_','R','E','V','I','S','I','O','N',0};
269 static const WCHAR PercentDW[] = {'%','d',0};
270 static const WCHAR Percent04XW[] = {'%','0','4','x',0};
271 static const WCHAR IntelCpuDescrW[] = {'%','s',' ','F','a','m','i','l','y',' ','%','d',' ','M','o','d','e','l',' ','%','d',
272 ' ','S','t','e','p','p','i','n','g',' ','%','d',',',' ','G','e','n','u','i','n','e','I','n','t','e','l',0};
274 HKEY env_key;
275 SYSTEM_CPU_INFORMATION sci;
276 WCHAR buffer[60];
277 const WCHAR *arch;
279 NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );
281 if (RegCreateKeyW( HKEY_LOCAL_MACHINE, EnvironW, &env_key )) return;
283 sprintfW( buffer, PercentDW, NtCurrentTeb()->Peb->NumberOfProcessors );
284 set_reg_value( env_key, NumProcW, buffer );
286 switch(sci.Architecture)
288 case PROCESSOR_ARCHITECTURE_AMD64: arch = AMD64W; break;
289 case PROCESSOR_ARCHITECTURE_IA64: arch = IA64W; break;
290 default:
291 case PROCESSOR_ARCHITECTURE_INTEL: arch = x86W; break;
293 set_reg_value( env_key, ProcArchW, arch );
295 /* TODO: currently hardcoded Intel, add different processors */
296 sprintfW( buffer, IntelCpuDescrW, arch, sci.Level, HIBYTE(sci.Revision), LOBYTE(sci.Revision) );
297 set_reg_value( env_key, ProcIdW, buffer );
299 sprintfW( buffer, PercentDW, sci.Level );
300 set_reg_value( env_key, ProcLvlW, buffer );
302 /* Properly report model/stepping */
303 sprintfW( buffer, Percent04XW, sci.Revision );
304 set_reg_value( env_key, ProcRevW, buffer );
306 RegCloseKey( env_key );
309 static void create_volatile_environment_registry_key(void)
311 static const WCHAR VolatileEnvW[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0};
312 static const WCHAR AppDataW[] = {'A','P','P','D','A','T','A',0};
313 static const WCHAR ClientNameW[] = {'C','L','I','E','N','T','N','A','M','E',0};
314 static const WCHAR HomeDriveW[] = {'H','O','M','E','D','R','I','V','E',0};
315 static const WCHAR HomePathW[] = {'H','O','M','E','P','A','T','H',0};
316 static const WCHAR HomeShareW[] = {'H','O','M','E','S','H','A','R','E',0};
317 static const WCHAR LocalAppDataW[] = {'L','O','C','A','L','A','P','P','D','A','T','A',0};
318 static const WCHAR LogonServerW[] = {'L','O','G','O','N','S','E','R','V','E','R',0};
319 static const WCHAR SessionNameW[] = {'S','E','S','S','I','O','N','N','A','M','E',0};
320 static const WCHAR UserNameW[] = {'U','S','E','R','N','A','M','E',0};
321 static const WCHAR UserDomainW[] = {'U','S','E','R','D','O','M','A','I','N',0};
322 static const WCHAR UserProfileW[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
323 static const WCHAR ConsoleW[] = {'C','o','n','s','o','l','e',0};
324 static const WCHAR EmptyW[] = {0};
325 WCHAR path[MAX_PATH];
326 WCHAR computername[MAX_COMPUTERNAME_LENGTH + 1 + 2];
327 DWORD size;
328 HKEY hkey;
329 HRESULT hr;
331 if (RegCreateKeyExW( HKEY_CURRENT_USER, VolatileEnvW, 0, NULL, REG_OPTION_VOLATILE,
332 KEY_ALL_ACCESS, NULL, &hkey, NULL ))
333 return;
335 hr = SHGetFolderPathW( NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path );
336 if (SUCCEEDED(hr)) set_reg_value( hkey, AppDataW, path );
338 set_reg_value( hkey, ClientNameW, ConsoleW );
340 /* Write the profile path's drive letter and directory components into
341 * HOMEDRIVE and HOMEPATH respectively. */
342 hr = SHGetFolderPathW( NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, path );
343 if (SUCCEEDED(hr))
345 set_reg_value( hkey, UserProfileW, path );
346 set_reg_value( hkey, HomePathW, path + 2 );
347 path[2] = '\0';
348 set_reg_value( hkey, HomeDriveW, path );
351 size = sizeof(path)/sizeof(path[0]);
352 if (GetUserNameW( path, &size )) set_reg_value( hkey, UserNameW, path );
354 set_reg_value( hkey, HomeShareW, EmptyW );
356 hr = SHGetFolderPathW( NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path );
357 if (SUCCEEDED(hr))
358 set_reg_value( hkey, LocalAppDataW, path );
360 size = (sizeof(computername)/sizeof(WCHAR)) - 2;
361 if (GetComputerNameW(&computername[2], &size))
363 set_reg_value( hkey, UserDomainW, &computername[2] );
364 computername[0] = computername[1] = '\\';
365 set_reg_value( hkey, LogonServerW, computername );
368 set_reg_value( hkey, SessionNameW, ConsoleW );
369 RegCloseKey( hkey );
372 /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
373 * Returns FALSE if there was an error, or otherwise if all is ok.
375 static BOOL wininit(void)
377 static const WCHAR nulW[] = {'N','U','L',0};
378 static const WCHAR renameW[] = {'r','e','n','a','m','e',0};
379 static const WCHAR wininitW[] = {'w','i','n','i','n','i','t','.','i','n','i',0};
380 static const WCHAR wininitbakW[] = {'w','i','n','i','n','i','t','.','b','a','k',0};
381 WCHAR initial_buffer[1024];
382 WCHAR *str, *buffer = initial_buffer;
383 DWORD size = sizeof(initial_buffer)/sizeof(WCHAR);
384 DWORD res;
386 for (;;)
388 if (!(res = GetPrivateProfileSectionW( renameW, buffer, size, wininitW ))) return TRUE;
389 if (res < size - 2) break;
390 if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer );
391 size *= 2;
392 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
395 for (str = buffer; *str; str += strlenW(str) + 1)
397 WCHAR *value;
399 if (*str == ';') continue; /* comment */
400 if (!(value = strchrW( str, '=' ))) continue;
402 /* split the line into key and value */
403 *value++ = 0;
405 if (!lstrcmpiW( nulW, str ))
407 WINE_TRACE("Deleting file %s\n", wine_dbgstr_w(value) );
408 if( !DeleteFileW( value ) )
409 WINE_WARN("Error deleting file %s\n", wine_dbgstr_w(value) );
411 else
413 WINE_TRACE("Renaming file %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) );
415 if( !MoveFileExW(value, str, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) )
416 WINE_WARN("Error renaming %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) );
418 str = value;
421 if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer );
423 if( !MoveFileExW( wininitW, wininitbakW, MOVEFILE_REPLACE_EXISTING) )
425 WINE_ERR("Couldn't rename wininit.ini, error %d\n", GetLastError() );
427 return FALSE;
430 return TRUE;
433 static BOOL pendingRename(void)
435 static const WCHAR ValueName[] = {'P','e','n','d','i','n','g',
436 'F','i','l','e','R','e','n','a','m','e',
437 'O','p','e','r','a','t','i','o','n','s',0};
438 static const WCHAR SessionW[] = { 'S','y','s','t','e','m','\\',
439 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
440 'C','o','n','t','r','o','l','\\',
441 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
442 WCHAR *buffer=NULL;
443 const WCHAR *src=NULL, *dst=NULL;
444 DWORD dataLength=0;
445 HKEY hSession=NULL;
446 DWORD res;
448 WINE_TRACE("Entered\n");
450 if( (res=RegOpenKeyExW( HKEY_LOCAL_MACHINE, SessionW, 0, KEY_ALL_ACCESS, &hSession ))
451 !=ERROR_SUCCESS )
453 WINE_TRACE("The key was not found - skipping\n");
454 return TRUE;
457 res=RegQueryValueExW( hSession, ValueName, NULL, NULL /* The value type does not really interest us, as it is not
458 truly a REG_MULTI_SZ anyways */,
459 NULL, &dataLength );
460 if( res==ERROR_FILE_NOT_FOUND )
462 /* No value - nothing to do. Great! */
463 WINE_TRACE("Value not present - nothing to rename\n");
464 res=TRUE;
465 goto end;
468 if( res!=ERROR_SUCCESS )
470 WINE_ERR("Couldn't query value's length (%d)\n", res );
471 res=FALSE;
472 goto end;
475 buffer=HeapAlloc( GetProcessHeap(),0,dataLength );
476 if( buffer==NULL )
478 WINE_ERR("Couldn't allocate %u bytes for the value\n", dataLength );
479 res=FALSE;
480 goto end;
483 res=RegQueryValueExW( hSession, ValueName, NULL, NULL, (LPBYTE)buffer, &dataLength );
484 if( res!=ERROR_SUCCESS )
486 WINE_ERR("Couldn't query value after successfully querying before (%u),\n"
487 "please report to wine-devel@winehq.org\n", res);
488 res=FALSE;
489 goto end;
492 /* Make sure that the data is long enough and ends with two NULLs. This
493 * simplifies the code later on.
495 if( dataLength<2*sizeof(buffer[0]) ||
496 buffer[dataLength/sizeof(buffer[0])-1]!='\0' ||
497 buffer[dataLength/sizeof(buffer[0])-2]!='\0' )
499 WINE_ERR("Improper value format - doesn't end with NULL\n");
500 res=FALSE;
501 goto end;
504 for( src=buffer; (src-buffer)*sizeof(src[0])<dataLength && *src!='\0';
505 src=dst+lstrlenW(dst)+1 )
507 DWORD dwFlags=0;
509 WINE_TRACE("processing next command\n");
511 dst=src+lstrlenW(src)+1;
513 /* We need to skip the \??\ header */
514 if( src[0]=='\\' && src[1]=='?' && src[2]=='?' && src[3]=='\\' )
515 src+=4;
517 if( dst[0]=='!' )
519 dwFlags|=MOVEFILE_REPLACE_EXISTING;
520 dst++;
523 if( dst[0]=='\\' && dst[1]=='?' && dst[2]=='?' && dst[3]=='\\' )
524 dst+=4;
526 if( *dst!='\0' )
528 /* Rename the file */
529 MoveFileExW( src, dst, dwFlags );
530 } else
532 /* Delete the file or directory */
533 if( (res=GetFileAttributesW(src))!=INVALID_FILE_ATTRIBUTES )
535 if( (res&FILE_ATTRIBUTE_DIRECTORY)==0 )
537 /* It's a file */
538 DeleteFileW(src);
539 } else
541 /* It's a directory */
542 RemoveDirectoryW(src);
544 } else
546 WINE_ERR("couldn't get file attributes (%d)\n", GetLastError() );
551 if((res=RegDeleteValueW(hSession, ValueName))!=ERROR_SUCCESS )
553 WINE_ERR("Error deleting the value (%u)\n", GetLastError() );
554 res=FALSE;
555 } else
556 res=TRUE;
558 end:
559 HeapFree(GetProcessHeap(), 0, buffer);
561 if( hSession!=NULL )
562 RegCloseKey( hSession );
564 return res;
567 enum runkeys {
568 RUNKEY_RUN, RUNKEY_RUNONCE, RUNKEY_RUNSERVICES, RUNKEY_RUNSERVICESONCE
571 const WCHAR runkeys_names[][30]=
573 {'R','u','n',0},
574 {'R','u','n','O','n','c','e',0},
575 {'R','u','n','S','e','r','v','i','c','e','s',0},
576 {'R','u','n','S','e','r','v','i','c','e','s','O','n','c','e',0}
579 #define INVALID_RUNCMD_RETURN -1
581 * This function runs the specified command in the specified dir.
582 * [in,out] cmdline - the command line to run. The function may change the passed buffer.
583 * [in] dir - the dir to run the command in. If it is NULL, then the current dir is used.
584 * [in] wait - whether to wait for the run program to finish before returning.
585 * [in] minimized - Whether to ask the program to run minimized.
587 * Returns:
588 * If running the process failed, returns INVALID_RUNCMD_RETURN. Use GetLastError to get the error code.
589 * If wait is FALSE - returns 0 if successful.
590 * If wait is TRUE - returns the program's return value.
592 static DWORD runCmd(LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
594 STARTUPINFOW si;
595 PROCESS_INFORMATION info;
596 DWORD exit_code=0;
598 memset(&si, 0, sizeof(si));
599 si.cb=sizeof(si);
600 if( minimized )
602 si.dwFlags=STARTF_USESHOWWINDOW;
603 si.wShowWindow=SW_MINIMIZE;
605 memset(&info, 0, sizeof(info));
607 if( !CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, dir, &si, &info) )
609 WINE_WARN("Failed to run command %s (%d)\n", wine_dbgstr_w(cmdline), GetLastError() );
610 return INVALID_RUNCMD_RETURN;
613 WINE_TRACE("Successfully ran command %s - Created process handle %p\n",
614 wine_dbgstr_w(cmdline), info.hProcess );
616 if(wait)
617 { /* wait for the process to exit */
618 WaitForSingleObject(info.hProcess, INFINITE);
619 GetExitCodeProcess(info.hProcess, &exit_code);
622 CloseHandle( info.hThread );
623 CloseHandle( info.hProcess );
625 return exit_code;
629 * Process a "Run" type registry key.
630 * hkRoot is the HKEY from which "Software\Microsoft\Windows\CurrentVersion" is
631 * opened.
632 * szKeyName is the key holding the actual entries.
633 * bDelete tells whether we should delete each value right before executing it.
634 * bSynchronous tells whether we should wait for the prog to complete before
635 * going on to the next prog.
637 static BOOL ProcessRunKeys( HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete,
638 BOOL bSynchronous )
640 static const WCHAR WINKEY_NAME[]={'S','o','f','t','w','a','r','e','\\',
641 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
642 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
643 HKEY hkWin, hkRun;
644 DWORD res, dispos;
645 DWORD i, nMaxCmdLine=0, nMaxValue=0;
646 WCHAR *szCmdLine=NULL;
647 WCHAR *szValue=NULL;
649 if (hkRoot==HKEY_LOCAL_MACHINE)
650 WINE_TRACE("processing %s entries under HKLM\n",wine_dbgstr_w(szKeyName) );
651 else
652 WINE_TRACE("processing %s entries under HKCU\n",wine_dbgstr_w(szKeyName) );
654 if (RegCreateKeyExW( hkRoot, WINKEY_NAME, 0, NULL, 0, KEY_READ, NULL, &hkWin, NULL ) != ERROR_SUCCESS)
655 return TRUE;
657 if ((res = RegCreateKeyExW( hkWin, szKeyName, 0, NULL, 0, bDelete ? KEY_ALL_ACCESS : KEY_READ,
658 NULL, &hkRun, &dispos ) != ERROR_SUCCESS))
660 RegCloseKey( hkWin );
661 return TRUE;
663 RegCloseKey( hkWin );
664 if (dispos == REG_CREATED_NEW_KEY) goto end;
666 if( (res=RegQueryInfoKeyW( hkRun, NULL, NULL, NULL, NULL, NULL, NULL, &i, &nMaxValue,
667 &nMaxCmdLine, NULL, NULL ))!=ERROR_SUCCESS )
668 goto end;
670 if( i==0 )
672 WINE_TRACE("No commands to execute.\n");
674 res=ERROR_SUCCESS;
675 goto end;
678 if( (szCmdLine=HeapAlloc(GetProcessHeap(),0,nMaxCmdLine))==NULL )
680 WINE_ERR("Couldn't allocate memory for the commands to be executed\n");
682 res=ERROR_NOT_ENOUGH_MEMORY;
683 goto end;
686 if( (szValue=HeapAlloc(GetProcessHeap(),0,(++nMaxValue)*sizeof(*szValue)))==NULL )
688 WINE_ERR("Couldn't allocate memory for the value names\n");
690 res=ERROR_NOT_ENOUGH_MEMORY;
691 goto end;
694 while( i>0 )
696 DWORD nValLength=nMaxValue, nDataLength=nMaxCmdLine;
697 DWORD type;
699 --i;
701 if( (res=RegEnumValueW( hkRun, i, szValue, &nValLength, 0, &type,
702 (LPBYTE)szCmdLine, &nDataLength ))!=ERROR_SUCCESS )
704 WINE_ERR("Couldn't read in value %d - %d\n", i, res );
706 continue;
709 if( bDelete && (res=RegDeleteValueW( hkRun, szValue ))!=ERROR_SUCCESS )
711 WINE_ERR("Couldn't delete value - %d, %d. Running command anyways.\n", i, res );
714 if( type!=REG_SZ )
716 WINE_ERR("Incorrect type of value #%d (%d)\n", i, type );
718 continue;
721 if( (res=runCmd(szCmdLine, NULL, bSynchronous, FALSE ))==INVALID_RUNCMD_RETURN )
723 WINE_ERR("Error running cmd %s (%d)\n", wine_dbgstr_w(szCmdLine), GetLastError() );
726 WINE_TRACE("Done processing cmd #%d\n", i);
729 res=ERROR_SUCCESS;
731 end:
732 HeapFree( GetProcessHeap(), 0, szValue );
733 HeapFree( GetProcessHeap(), 0, szCmdLine );
735 if( hkRun!=NULL )
736 RegCloseKey( hkRun );
738 WINE_TRACE("done\n");
740 return res==ERROR_SUCCESS;
744 * WFP is Windows File Protection, in NT5 and Windows 2000 it maintains a cache
745 * of known good dlls and scans through and replaces corrupted DLLs with these
746 * known good versions. The only programs that should install into this dll
747 * cache are Windows Updates and IE (which is treated like a Windows Update)
749 * Implementing this allows installing ie in win2k mode to actually install the
750 * system dlls that we expect and need
752 static int ProcessWindowsFileProtection(void)
754 static const WCHAR winlogonW[] = {'S','o','f','t','w','a','r','e','\\',
755 'M','i','c','r','o','s','o','f','t','\\',
756 'W','i','n','d','o','w','s',' ','N','T','\\',
757 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
758 'W','i','n','l','o','g','o','n',0};
759 static const WCHAR cachedirW[] = {'S','F','C','D','l','l','C','a','c','h','e','D','i','r',0};
760 static const WCHAR dllcacheW[] = {'\\','d','l','l','c','a','c','h','e','\\','*',0};
761 static const WCHAR wildcardW[] = {'\\','*',0};
762 WIN32_FIND_DATAW finddata;
763 HANDLE find_handle;
764 BOOL find_rc;
765 DWORD rc;
766 HKEY hkey;
767 LPWSTR dllcache = NULL;
769 if (!RegOpenKeyW( HKEY_LOCAL_MACHINE, winlogonW, &hkey ))
771 DWORD sz = 0;
772 if (!RegQueryValueExW( hkey, cachedirW, 0, NULL, NULL, &sz))
774 sz += sizeof(WCHAR);
775 dllcache = HeapAlloc(GetProcessHeap(),0,sz + sizeof(wildcardW));
776 RegQueryValueExW( hkey, cachedirW, 0, NULL, (LPBYTE)dllcache, &sz);
777 strcatW( dllcache, wildcardW );
780 RegCloseKey(hkey);
782 if (!dllcache)
784 DWORD sz = GetSystemDirectoryW( NULL, 0 );
785 dllcache = HeapAlloc( GetProcessHeap(), 0, sz * sizeof(WCHAR) + sizeof(dllcacheW));
786 GetSystemDirectoryW( dllcache, sz );
787 strcatW( dllcache, dllcacheW );
790 find_handle = FindFirstFileW(dllcache,&finddata);
791 dllcache[ strlenW(dllcache) - 2] = 0; /* strip off wildcard */
792 find_rc = find_handle != INVALID_HANDLE_VALUE;
793 while (find_rc)
795 static const WCHAR dotW[] = {'.',0};
796 static const WCHAR dotdotW[] = {'.','.',0};
797 WCHAR targetpath[MAX_PATH];
798 WCHAR currentpath[MAX_PATH];
799 UINT sz;
800 UINT sz2;
801 WCHAR tempfile[MAX_PATH];
803 if (strcmpW(finddata.cFileName,dotW) == 0 || strcmpW(finddata.cFileName,dotdotW) == 0)
805 find_rc = FindNextFileW(find_handle,&finddata);
806 continue;
809 sz = MAX_PATH;
810 sz2 = MAX_PATH;
811 VerFindFileW(VFFF_ISSHAREDFILE, finddata.cFileName, windowsdir,
812 windowsdir, currentpath, &sz, targetpath, &sz2);
813 sz = MAX_PATH;
814 rc = VerInstallFileW(0, finddata.cFileName, finddata.cFileName,
815 dllcache, targetpath, currentpath, tempfile, &sz);
816 if (rc != ERROR_SUCCESS)
818 WINE_WARN("WFP: %s error 0x%x\n",wine_dbgstr_w(finddata.cFileName),rc);
819 DeleteFileW(tempfile);
822 /* now delete the source file so that we don't try to install it over and over again */
823 lstrcpynW( targetpath, dllcache, MAX_PATH - 1 );
824 sz = strlenW( targetpath );
825 targetpath[sz++] = '\\';
826 lstrcpynW( targetpath + sz, finddata.cFileName, MAX_PATH - sz );
827 if (!DeleteFileW( targetpath ))
828 WINE_WARN( "failed to delete %s: error %u\n", wine_dbgstr_w(targetpath), GetLastError() );
830 find_rc = FindNextFileW(find_handle,&finddata);
832 FindClose(find_handle);
833 HeapFree(GetProcessHeap(),0,dllcache);
834 return 1;
837 static BOOL start_services_process(void)
839 static const WCHAR svcctl_started_event[] = SVCCTL_STARTED_EVENT;
840 static const WCHAR services[] = {'\\','s','e','r','v','i','c','e','s','.','e','x','e',0};
841 PROCESS_INFORMATION pi;
842 STARTUPINFOW si;
843 HANDLE wait_handles[2];
844 WCHAR path[MAX_PATH];
846 if (!GetSystemDirectoryW(path, MAX_PATH - strlenW(services)))
847 return FALSE;
848 strcatW(path, services);
849 ZeroMemory(&si, sizeof(si));
850 si.cb = sizeof(si);
851 if (!CreateProcessW(path, path, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
853 WINE_ERR("Couldn't start services.exe: error %u\n", GetLastError());
854 return FALSE;
856 CloseHandle(pi.hThread);
858 wait_handles[0] = CreateEventW(NULL, TRUE, FALSE, svcctl_started_event);
859 wait_handles[1] = pi.hProcess;
861 /* wait for the event to become available or the process to exit */
862 if ((WaitForMultipleObjects(2, wait_handles, FALSE, INFINITE)) == WAIT_OBJECT_0 + 1)
864 DWORD exit_code;
865 GetExitCodeProcess(pi.hProcess, &exit_code);
866 WINE_ERR("Unexpected termination of services.exe - exit code %d\n", exit_code);
867 CloseHandle(pi.hProcess);
868 CloseHandle(wait_handles[0]);
869 return FALSE;
872 CloseHandle(pi.hProcess);
873 CloseHandle(wait_handles[0]);
874 return TRUE;
877 static INT_PTR CALLBACK wait_dlgproc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
879 switch (msg)
881 case WM_INITDIALOG:
883 WCHAR *buffer, text[1024];
884 const WCHAR *name = (WCHAR *)lp;
885 HICON icon = LoadImageW( 0, (LPCWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
886 SendDlgItemMessageW( hwnd, IDC_WAITICON, STM_SETICON, (WPARAM)icon, 0 );
887 SendDlgItemMessageW( hwnd, IDC_WAITTEXT, WM_GETTEXT, 1024, (LPARAM)text );
888 buffer = HeapAlloc( GetProcessHeap(), 0, (strlenW(text) + strlenW(name) + 1) * sizeof(WCHAR) );
889 sprintfW( buffer, text, name );
890 SendDlgItemMessageW( hwnd, IDC_WAITTEXT, WM_SETTEXT, 0, (LPARAM)buffer );
891 HeapFree( GetProcessHeap(), 0, buffer );
893 break;
895 return 0;
898 static HWND show_wait_window(void)
900 const char *config_dir = wine_get_config_dir();
901 WCHAR *name;
902 HWND hwnd;
903 DWORD len;
905 len = MultiByteToWideChar( CP_UNIXCP, 0, config_dir, -1, NULL, 0 );
906 name = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
907 MultiByteToWideChar( CP_UNIXCP, 0, config_dir, -1, name, len );
908 hwnd = CreateDialogParamW( GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_WAITDLG), 0,
909 wait_dlgproc, (LPARAM)name );
910 ShowWindow( hwnd, SW_SHOWNORMAL );
911 HeapFree( GetProcessHeap(), 0, name );
912 return hwnd;
915 static HANDLE start_rundll32( const char *inf_path, BOOL wow64 )
917 static const WCHAR rundll[] = {'\\','r','u','n','d','l','l','3','2','.','e','x','e',0};
918 static const WCHAR setupapi[] = {' ','s','e','t','u','p','a','p','i',',',
919 'I','n','s','t','a','l','l','H','i','n','f','S','e','c','t','i','o','n',0};
920 static const WCHAR definstall[] = {' ','D','e','f','a','u','l','t','I','n','s','t','a','l','l',0};
921 static const WCHAR wowinstall[] = {' ','W','o','w','6','4','I','n','s','t','a','l','l',0};
922 static const WCHAR inf[] = {' ','1','2','8',' ','\\','\\','?','\\','u','n','i','x',0 };
924 WCHAR app[MAX_PATH + sizeof(rundll)/sizeof(WCHAR)];
925 STARTUPINFOW si;
926 PROCESS_INFORMATION pi;
927 WCHAR *buffer;
928 DWORD inf_len, cmd_len;
930 memset( &si, 0, sizeof(si) );
931 si.cb = sizeof(si);
933 if (wow64)
935 if (!GetSystemWow64DirectoryW( app, MAX_PATH )) return 0; /* not on 64-bit */
937 else GetSystemDirectoryW( app, MAX_PATH );
939 strcatW( app, rundll );
941 cmd_len = strlenW(app) * sizeof(WCHAR) + sizeof(setupapi) + sizeof(definstall) + sizeof(inf);
942 inf_len = MultiByteToWideChar( CP_UNIXCP, 0, inf_path, -1, NULL, 0 );
944 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, cmd_len + inf_len * sizeof(WCHAR) ))) return 0;
946 strcpyW( buffer, app );
947 strcatW( buffer, setupapi );
948 strcatW( buffer, wow64 ? wowinstall : definstall );
949 strcatW( buffer, inf );
950 MultiByteToWideChar( CP_UNIXCP, 0, inf_path, -1, buffer + strlenW(buffer), inf_len );
952 if (CreateProcessW( app, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
953 CloseHandle( pi.hThread );
954 else
955 pi.hProcess = 0;
957 HeapFree( GetProcessHeap(), 0, buffer );
958 return pi.hProcess;
961 /* execute rundll32 on the wine.inf file if necessary */
962 static void update_wineprefix( int force )
964 const char *config_dir = wine_get_config_dir();
965 char *inf_path = get_wine_inf_path();
966 int fd;
967 struct stat st;
969 if (!inf_path)
971 WINE_MESSAGE( "wine: failed to update %s, wine.inf not found\n", config_dir );
972 return;
974 if ((fd = open( inf_path, O_RDONLY )) == -1)
976 WINE_MESSAGE( "wine: failed to update %s with %s: %s\n",
977 config_dir, inf_path, strerror(errno) );
978 goto done;
980 fstat( fd, &st );
981 close( fd );
983 if (update_timestamp( config_dir, st.st_mtime ) || force)
985 HANDLE process;
986 DWORD count = 0;
988 if ((process = start_rundll32( inf_path, FALSE )))
990 HWND hwnd = show_wait_window();
991 for (;;)
993 MSG msg;
994 DWORD res = MsgWaitForMultipleObjects( 1, &process, FALSE, INFINITE, QS_ALLINPUT );
995 if (res == WAIT_OBJECT_0)
997 CloseHandle( process );
998 if (count++ || !(process = start_rundll32( inf_path, TRUE ))) break;
1000 else while (PeekMessageW( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageW( &msg );
1002 DestroyWindow( hwnd );
1004 WINE_MESSAGE( "wine: configuration in '%s' has been updated.\n", config_dir );
1007 done:
1008 HeapFree( GetProcessHeap(), 0, inf_path );
1011 /* Process items in the StartUp group of the user's Programs under the Start Menu. Some installers put
1012 * shell links here to restart themselves after boot. */
1013 static BOOL ProcessStartupItems(void)
1015 BOOL ret = FALSE;
1016 HRESULT hr;
1017 IMalloc *ppM = NULL;
1018 IShellFolder *psfDesktop = NULL, *psfStartup = NULL;
1019 LPITEMIDLIST pidlStartup = NULL, pidlItem;
1020 ULONG NumPIDLs;
1021 IEnumIDList *iEnumList = NULL;
1022 STRRET strret;
1023 WCHAR wszCommand[MAX_PATH];
1025 WINE_TRACE("Processing items in the StartUp folder.\n");
1027 hr = SHGetMalloc(&ppM);
1028 if (FAILED(hr))
1030 WINE_ERR("Couldn't get IMalloc object.\n");
1031 goto done;
1034 hr = SHGetDesktopFolder(&psfDesktop);
1035 if (FAILED(hr))
1037 WINE_ERR("Couldn't get desktop folder.\n");
1038 goto done;
1041 hr = SHGetSpecialFolderLocation(NULL, CSIDL_STARTUP, &pidlStartup);
1042 if (FAILED(hr))
1044 WINE_TRACE("Couldn't get StartUp folder location.\n");
1045 goto done;
1048 hr = IShellFolder_BindToObject(psfDesktop, pidlStartup, NULL, &IID_IShellFolder, (LPVOID*)&psfStartup);
1049 if (FAILED(hr))
1051 WINE_TRACE("Couldn't bind IShellFolder to StartUp folder.\n");
1052 goto done;
1055 hr = IShellFolder_EnumObjects(psfStartup, NULL, SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
1056 if (FAILED(hr))
1058 WINE_TRACE("Unable to enumerate StartUp objects.\n");
1059 goto done;
1062 while (IEnumIDList_Next(iEnumList, 1, &pidlItem, &NumPIDLs) == S_OK &&
1063 (NumPIDLs) == 1)
1065 hr = IShellFolder_GetDisplayNameOf(psfStartup, pidlItem, SHGDN_FORPARSING, &strret);
1066 if (FAILED(hr))
1067 WINE_TRACE("Unable to get display name of enumeration item.\n");
1068 else
1070 hr = StrRetToBufW(&strret, pidlItem, wszCommand, MAX_PATH);
1071 if (FAILED(hr))
1072 WINE_TRACE("Unable to parse display name.\n");
1073 else
1075 HINSTANCE hinst;
1077 hinst = ShellExecuteW(NULL, NULL, wszCommand, NULL, NULL, SW_SHOWNORMAL);
1078 if (PtrToUlong(hinst) <= 32)
1079 WINE_WARN("Error %p executing command %s.\n", hinst, wine_dbgstr_w(wszCommand));
1083 IMalloc_Free(ppM, pidlItem);
1086 /* Return success */
1087 ret = TRUE;
1089 done:
1090 if (iEnumList) IEnumIDList_Release(iEnumList);
1091 if (psfStartup) IShellFolder_Release(psfStartup);
1092 if (pidlStartup) IMalloc_Free(ppM, pidlStartup);
1094 return ret;
1097 static void usage(void)
1099 WINE_MESSAGE( "Usage: wineboot [options]\n" );
1100 WINE_MESSAGE( "Options;\n" );
1101 WINE_MESSAGE( " -h,--help Display this help message\n" );
1102 WINE_MESSAGE( " -e,--end-session End the current session cleanly\n" );
1103 WINE_MESSAGE( " -f,--force Force exit for processes that don't exit cleanly\n" );
1104 WINE_MESSAGE( " -i,--init Perform initialization for first Wine instance\n" );
1105 WINE_MESSAGE( " -k,--kill Kill running processes without any cleanup\n" );
1106 WINE_MESSAGE( " -r,--restart Restart only, don't do normal startup operations\n" );
1107 WINE_MESSAGE( " -s,--shutdown Shutdown only, don't reboot\n" );
1108 WINE_MESSAGE( " -u,--update Update the wineprefix directory\n" );
1111 static const char short_options[] = "efhikrsu";
1113 static const struct option long_options[] =
1115 { "help", 0, 0, 'h' },
1116 { "end-session", 0, 0, 'e' },
1117 { "force", 0, 0, 'f' },
1118 { "init" , 0, 0, 'i' },
1119 { "kill", 0, 0, 'k' },
1120 { "restart", 0, 0, 'r' },
1121 { "shutdown", 0, 0, 's' },
1122 { "update", 0, 0, 'u' },
1123 { NULL, 0, 0, 0 }
1126 int main( int argc, char *argv[] )
1128 extern HANDLE CDECL __wine_make_process_system(void);
1129 static const WCHAR wineboot_eventW[] = {'_','_','w','i','n','e','b','o','o','t','_','e','v','e','n','t',0};
1131 /* First, set the current directory to SystemRoot */
1132 int optc;
1133 int end_session = 0, force = 0, init = 0, kill = 0, restart = 0, shutdown = 0, update = 0;
1134 HANDLE event;
1135 SECURITY_ATTRIBUTES sa;
1136 BOOL is_wow64;
1138 GetWindowsDirectoryW( windowsdir, MAX_PATH );
1139 if( !SetCurrentDirectoryW( windowsdir ) )
1140 WINE_ERR("Cannot set the dir to %s (%d)\n", wine_dbgstr_w(windowsdir), GetLastError() );
1142 if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
1144 STARTUPINFOW si;
1145 PROCESS_INFORMATION pi;
1146 WCHAR filename[MAX_PATH];
1147 void *redir;
1148 DWORD exit_code;
1150 memset( &si, 0, sizeof(si) );
1151 si.cb = sizeof(si);
1152 GetModuleFileNameW( 0, filename, MAX_PATH );
1154 Wow64DisableWow64FsRedirection( &redir );
1155 if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
1157 WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
1158 WaitForSingleObject( pi.hProcess, INFINITE );
1159 GetExitCodeProcess( pi.hProcess, &exit_code );
1160 ExitProcess( exit_code );
1162 else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename), GetLastError() );
1163 Wow64RevertWow64FsRedirection( redir );
1166 while ((optc = getopt_long(argc, argv, short_options, long_options, NULL )) != -1)
1168 switch(optc)
1170 case 'e': end_session = 1; break;
1171 case 'f': force = 1; break;
1172 case 'i': init = 1; break;
1173 case 'k': kill = 1; break;
1174 case 'r': restart = 1; break;
1175 case 's': shutdown = 1; break;
1176 case 'u': update = 1; break;
1177 case 'h': usage(); return 0;
1178 case '?': usage(); return 1;
1182 if (end_session)
1184 if (kill)
1186 if (!shutdown_all_desktops( force )) return 1;
1188 else if (!shutdown_close_windows( force )) return 1;
1191 if (kill) kill_processes( shutdown );
1193 if (shutdown) return 0;
1195 sa.nLength = sizeof(sa);
1196 sa.lpSecurityDescriptor = NULL;
1197 sa.bInheritHandle = TRUE; /* so that services.exe inherits it */
1198 event = CreateEventW( &sa, TRUE, FALSE, wineboot_eventW );
1200 ResetEvent( event ); /* in case this is a restart */
1202 create_hardware_registry_keys();
1203 create_dynamic_registry_keys();
1204 create_environment_registry_keys();
1205 wininit();
1206 pendingRename();
1208 ProcessWindowsFileProtection();
1209 ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNSERVICESONCE], TRUE, FALSE );
1211 if (init || (kill && !restart))
1213 ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNSERVICES], FALSE, FALSE );
1214 start_services_process();
1216 if (init || update) update_wineprefix( update );
1218 create_volatile_environment_registry_key();
1220 ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNONCE], TRUE, TRUE );
1222 if (!init && !restart)
1224 ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUN], FALSE, FALSE );
1225 ProcessRunKeys( HKEY_CURRENT_USER, runkeys_names[RUNKEY_RUN], FALSE, FALSE );
1226 ProcessStartupItems();
1229 WINE_TRACE("Operation done\n");
1231 SetEvent( event );
1232 return 0;