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>
74 #include <wine/svcctl.h>
75 #include <wine/unicode.h>
76 #include <wine/library.h>
77 #include <wine/debug.h>
85 WINE_DEFAULT_DEBUG_CHANNEL(wineboot);
87 #define MAX_LINE_LENGTH (2*MAX_PATH+2)
89 extern BOOL shutdown_close_windows( BOOL force );
90 extern void kill_processes( BOOL kill_desktop );
92 static WCHAR windowsdir[MAX_PATH];
94 /* retrieve the (unix) path to the wine.inf file */
95 static char *get_wine_inf_path(void)
97 const char *build_dir, *data_dir;
100 if ((data_dir = wine_get_data_dir()))
102 if (!(name = HeapAlloc( GetProcessHeap(), 0, strlen(data_dir) + sizeof("/wine.inf") )))
104 strcpy( name, data_dir );
105 strcat( name, "/wine.inf" );
107 else if ((build_dir = wine_get_build_dir()))
109 if (!(name = HeapAlloc( GetProcessHeap(), 0, strlen(build_dir) + sizeof("/tools/wine.inf") )))
111 strcpy( name, build_dir );
112 strcat( name, "/tools/wine.inf" );
117 /* update the timestamp if different from the reference time */
118 static BOOL update_timestamp( const char *config_dir, unsigned long timestamp )
123 char *file = HeapAlloc( GetProcessHeap(), 0, strlen(config_dir) + sizeof("/.update-timestamp") );
125 if (!file) return FALSE;
126 strcpy( file, config_dir );
127 strcat( file, "/.update-timestamp" );
129 if ((fd = open( file, O_RDWR )) != -1)
131 if ((count = read( fd, buffer, sizeof(buffer) - 1 )) >= 0)
134 if (!strncmp( buffer, "disable", sizeof("disable")-1 )) goto done;
135 if (timestamp == strtoul( buffer, NULL, 10 )) goto done;
137 lseek( fd, 0, SEEK_SET );
142 if (errno != ENOENT) goto done;
143 if ((fd = open( file, O_WRONLY | O_CREAT | O_TRUNC, 0666 )) == -1) goto done;
146 count = sprintf( buffer, "%lu\n", timestamp );
147 if (write( fd, buffer, count ) != count)
149 WINE_WARN( "failed to update timestamp in %s\n", file );
155 if (fd != -1) close( fd );
156 HeapFree( GetProcessHeap(), 0, file );
160 /* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
161 * Returns FALSE if there was an error, or otherwise if all is ok.
163 static BOOL wininit(void)
165 static const WCHAR nulW[] = {'N','U','L',0};
166 static const WCHAR renameW[] = {'r','e','n','a','m','e',0};
167 static const WCHAR wininitW[] = {'w','i','n','i','n','i','t','.','i','n','i',0};
168 static const WCHAR wininitbakW[] = {'w','i','n','i','n','i','t','.','b','a','k',0};
169 WCHAR initial_buffer[1024];
170 WCHAR *str, *buffer = initial_buffer;
171 DWORD size = sizeof(initial_buffer)/sizeof(WCHAR);
176 if (!(res = GetPrivateProfileSectionW( renameW, buffer, size, wininitW ))) return TRUE;
177 if (res < size - 2) break;
178 if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer );
180 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
183 for (str = buffer; *str; str += strlenW(str) + 1)
187 if (*str == ';') continue; /* comment */
188 if (!(value = strchrW( str, '=' ))) continue;
190 /* split the line into key and value */
193 if (!lstrcmpiW( nulW, str ))
195 WINE_TRACE("Deleting file %s\n", wine_dbgstr_w(value) );
196 if( !DeleteFileW( value ) )
197 WINE_WARN("Error deleting file %s\n", wine_dbgstr_w(value) );
201 WINE_TRACE("Renaming file %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) );
203 if( !MoveFileExW(value, str, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) )
204 WINE_WARN("Error renaming %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) );
209 if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer );
211 if( !MoveFileExW( wininitW, wininitbakW, MOVEFILE_REPLACE_EXISTING) )
213 WINE_ERR("Couldn't rename wininit.ini, error %d\n", GetLastError() );
221 static BOOL pendingRename(void)
223 static const WCHAR ValueName[] = {'P','e','n','d','i','n','g',
224 'F','i','l','e','R','e','n','a','m','e',
225 'O','p','e','r','a','t','i','o','n','s',0};
226 static const WCHAR SessionW[] = { 'S','y','s','t','e','m','\\',
227 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
228 'C','o','n','t','r','o','l','\\',
229 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
231 const WCHAR *src=NULL, *dst=NULL;
236 WINE_TRACE("Entered\n");
238 if( (res=RegOpenKeyExW( HKEY_LOCAL_MACHINE, SessionW, 0, KEY_ALL_ACCESS, &hSession ))
241 WINE_TRACE("The key was not found - skipping\n");
245 res=RegQueryValueExW( hSession, ValueName, NULL, NULL /* The value type does not really interest us, as it is not
246 truly a REG_MULTI_SZ anyways */,
248 if( res==ERROR_FILE_NOT_FOUND )
250 /* No value - nothing to do. Great! */
251 WINE_TRACE("Value not present - nothing to rename\n");
256 if( res!=ERROR_SUCCESS )
258 WINE_ERR("Couldn't query value's length (%d)\n", res );
263 buffer=HeapAlloc( GetProcessHeap(),0,dataLength );
266 WINE_ERR("Couldn't allocate %u bytes for the value\n", dataLength );
271 res=RegQueryValueExW( hSession, ValueName, NULL, NULL, (LPBYTE)buffer, &dataLength );
272 if( res!=ERROR_SUCCESS )
274 WINE_ERR("Couldn't query value after successfully querying before (%u),\n"
275 "please report to wine-devel@winehq.org\n", res);
280 /* Make sure that the data is long enough and ends with two NULLs. This
281 * simplifies the code later on.
283 if( dataLength<2*sizeof(buffer[0]) ||
284 buffer[dataLength/sizeof(buffer[0])-1]!='\0' ||
285 buffer[dataLength/sizeof(buffer[0])-2]!='\0' )
287 WINE_ERR("Improper value format - doesn't end with NULL\n");
292 for( src=buffer; (src-buffer)*sizeof(src[0])<dataLength && *src!='\0';
293 src=dst+lstrlenW(dst)+1 )
297 WINE_TRACE("processing next command\n");
299 dst=src+lstrlenW(src)+1;
301 /* We need to skip the \??\ header */
302 if( src[0]=='\\' && src[1]=='?' && src[2]=='?' && src[3]=='\\' )
307 dwFlags|=MOVEFILE_REPLACE_EXISTING;
311 if( dst[0]=='\\' && dst[1]=='?' && dst[2]=='?' && dst[3]=='\\' )
316 /* Rename the file */
317 MoveFileExW( src, dst, dwFlags );
320 /* Delete the file or directory */
321 if( (res=GetFileAttributesW(src))!=INVALID_FILE_ATTRIBUTES )
323 if( (res&FILE_ATTRIBUTE_DIRECTORY)==0 )
329 /* It's a directory */
330 RemoveDirectoryW(src);
334 WINE_ERR("couldn't get file attributes (%d)\n", GetLastError() );
339 if((res=RegDeleteValueW(hSession, ValueName))!=ERROR_SUCCESS )
341 WINE_ERR("Error deleting the value (%u)\n", GetLastError() );
347 HeapFree(GetProcessHeap(), 0, buffer);
350 RegCloseKey( hSession );
356 RUNKEY_RUN, RUNKEY_RUNONCE, RUNKEY_RUNSERVICES, RUNKEY_RUNSERVICESONCE
359 const WCHAR runkeys_names[][30]=
362 {'R','u','n','O','n','c','e',0},
363 {'R','u','n','S','e','r','v','i','c','e','s',0},
364 {'R','u','n','S','e','r','v','i','c','e','s','O','n','c','e',0}
367 #define INVALID_RUNCMD_RETURN -1
369 * This function runs the specified command in the specified dir.
370 * [in,out] cmdline - the command line to run. The function may change the passed buffer.
371 * [in] dir - the dir to run the command in. If it is NULL, then the current dir is used.
372 * [in] wait - whether to wait for the run program to finish before returning.
373 * [in] minimized - Whether to ask the program to run minimized.
376 * If running the process failed, returns INVALID_RUNCMD_RETURN. Use GetLastError to get the error code.
377 * If wait is FALSE - returns 0 if successful.
378 * If wait is TRUE - returns the program's return value.
380 static DWORD runCmd(LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
383 PROCESS_INFORMATION info;
386 memset(&si, 0, sizeof(si));
390 si.dwFlags=STARTF_USESHOWWINDOW;
391 si.wShowWindow=SW_MINIMIZE;
393 memset(&info, 0, sizeof(info));
395 if( !CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, dir, &si, &info) )
397 WINE_WARN("Failed to run command %s (%d)\n", wine_dbgstr_w(cmdline), GetLastError() );
398 return INVALID_RUNCMD_RETURN;
401 WINE_TRACE("Successfully ran command %s - Created process handle %p\n",
402 wine_dbgstr_w(cmdline), info.hProcess );
405 { /* wait for the process to exit */
406 WaitForSingleObject(info.hProcess, INFINITE);
407 GetExitCodeProcess(info.hProcess, &exit_code);
410 CloseHandle( info.hThread );
411 CloseHandle( info.hProcess );
417 * Process a "Run" type registry key.
418 * hkRoot is the HKEY from which "Software\Microsoft\Windows\CurrentVersion" is
420 * szKeyName is the key holding the actual entries.
421 * bDelete tells whether we should delete each value right before executing it.
422 * bSynchronous tells whether we should wait for the prog to complete before
423 * going on to the next prog.
425 static BOOL ProcessRunKeys( HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete,
428 static const WCHAR WINKEY_NAME[]={'S','o','f','t','w','a','r','e','\\',
429 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
430 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
433 DWORD i, nMaxCmdLine=0, nMaxValue=0;
434 WCHAR *szCmdLine=NULL;
437 if (hkRoot==HKEY_LOCAL_MACHINE)
438 WINE_TRACE("processing %s entries under HKLM\n",wine_dbgstr_w(szKeyName) );
440 WINE_TRACE("processing %s entries under HKCU\n",wine_dbgstr_w(szKeyName) );
442 if (RegOpenKeyExW( hkRoot, WINKEY_NAME, 0, KEY_READ, &hkWin ) != ERROR_SUCCESS)
445 if (RegOpenKeyExW( hkWin, szKeyName, 0, bDelete?KEY_ALL_ACCESS:KEY_READ, &hkRun ) != ERROR_SUCCESS)
447 RegCloseKey( hkWin );
450 RegCloseKey( hkWin );
452 if( (res=RegQueryInfoKeyW( hkRun, NULL, NULL, NULL, NULL, NULL, NULL, &i, &nMaxValue,
453 &nMaxCmdLine, NULL, NULL ))!=ERROR_SUCCESS )
458 WINE_TRACE("No commands to execute.\n");
464 if( (szCmdLine=HeapAlloc(GetProcessHeap(),0,nMaxCmdLine))==NULL )
466 WINE_ERR("Couldn't allocate memory for the commands to be executed\n");
468 res=ERROR_NOT_ENOUGH_MEMORY;
472 if( (szValue=HeapAlloc(GetProcessHeap(),0,(++nMaxValue)*sizeof(*szValue)))==NULL )
474 WINE_ERR("Couldn't allocate memory for the value names\n");
476 res=ERROR_NOT_ENOUGH_MEMORY;
482 DWORD nValLength=nMaxValue, nDataLength=nMaxCmdLine;
487 if( (res=RegEnumValueW( hkRun, i, szValue, &nValLength, 0, &type,
488 (LPBYTE)szCmdLine, &nDataLength ))!=ERROR_SUCCESS )
490 WINE_ERR("Couldn't read in value %d - %d\n", i, res );
495 if( bDelete && (res=RegDeleteValueW( hkRun, szValue ))!=ERROR_SUCCESS )
497 WINE_ERR("Couldn't delete value - %d, %d. Running command anyways.\n", i, res );
502 WINE_ERR("Incorrect type of value #%d (%d)\n", i, type );
507 if( (res=runCmd(szCmdLine, NULL, bSynchronous, FALSE ))==INVALID_RUNCMD_RETURN )
509 WINE_ERR("Error running cmd %s (%d)\n", wine_dbgstr_w(szCmdLine), GetLastError() );
512 WINE_TRACE("Done processing cmd #%d\n", i);
518 HeapFree( GetProcessHeap(), 0, szValue );
519 HeapFree( GetProcessHeap(), 0, szCmdLine );
522 RegCloseKey( hkRun );
524 WINE_TRACE("done\n");
526 return res==ERROR_SUCCESS;
530 * WFP is Windows File Protection, in NT5 and Windows 2000 it maintains a cache
531 * of known good dlls and scans through and replaces corrupted DLLs with these
532 * known good versions. The only programs that should install into this dll
533 * cache are Windows Updates and IE (which is treated like a Windows Update)
535 * Implementing this allows installing ie in win2k mode to actually install the
536 * system dlls that we expect and need
538 static int ProcessWindowsFileProtection(void)
540 static const WCHAR winlogonW[] = {'S','o','f','t','w','a','r','e','\\',
541 'M','i','c','r','o','s','o','f','t','\\',
542 'W','i','n','d','o','w','s',' ','N','T','\\',
543 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
544 'W','i','n','l','o','g','o','n',0};
545 static const WCHAR cachedirW[] = {'S','F','C','D','l','l','C','a','c','h','e','D','i','r',0};
546 static const WCHAR dllcacheW[] = {'\\','d','l','l','c','a','c','h','e','\\','*',0};
547 static const WCHAR wildcardW[] = {'\\','*',0};
548 WIN32_FIND_DATAW finddata;
553 LPWSTR dllcache = NULL;
555 if (!RegOpenKeyW( HKEY_LOCAL_MACHINE, winlogonW, &hkey ))
558 if (!RegQueryValueExW( hkey, cachedirW, 0, NULL, NULL, &sz))
561 dllcache = HeapAlloc(GetProcessHeap(),0,sz + sizeof(wildcardW));
562 RegQueryValueExW( hkey, cachedirW, 0, NULL, (LPBYTE)dllcache, &sz);
563 strcatW( dllcache, wildcardW );
570 DWORD sz = GetSystemDirectoryW( NULL, 0 );
571 dllcache = HeapAlloc( GetProcessHeap(), 0, sz * sizeof(WCHAR) + sizeof(dllcacheW));
572 GetSystemDirectoryW( dllcache, sz );
573 strcatW( dllcache, dllcacheW );
576 find_handle = FindFirstFileW(dllcache,&finddata);
577 dllcache[ strlenW(dllcache) - 2] = 0; /* strip off wildcard */
578 find_rc = find_handle != INVALID_HANDLE_VALUE;
581 static const WCHAR dotW[] = {'.',0};
582 static const WCHAR dotdotW[] = {'.','.',0};
583 WCHAR targetpath[MAX_PATH];
584 WCHAR currentpath[MAX_PATH];
587 WCHAR tempfile[MAX_PATH];
589 if (strcmpW(finddata.cFileName,dotW) == 0 || strcmpW(finddata.cFileName,dotdotW) == 0)
591 find_rc = FindNextFileW(find_handle,&finddata);
597 VerFindFileW(VFFF_ISSHAREDFILE, finddata.cFileName, windowsdir,
598 windowsdir, currentpath, &sz, targetpath, &sz2);
600 rc = VerInstallFileW(0, finddata.cFileName, finddata.cFileName,
601 dllcache, targetpath, currentpath, tempfile, &sz);
602 if (rc != ERROR_SUCCESS)
604 WINE_WARN("WFP: %s error 0x%x\n",wine_dbgstr_w(finddata.cFileName),rc);
605 DeleteFileW(tempfile);
608 /* now delete the source file so that we don't try to install it over and over again */
609 lstrcpynW( targetpath, dllcache, MAX_PATH - 1 );
610 sz = strlenW( targetpath );
611 targetpath[sz++] = '\\';
612 lstrcpynW( targetpath + sz, finddata.cFileName, MAX_PATH - sz );
613 if (!DeleteFileW( targetpath ))
614 WINE_WARN( "failed to delete %s: error %u\n", wine_dbgstr_w(targetpath), GetLastError() );
616 find_rc = FindNextFileW(find_handle,&finddata);
618 FindClose(find_handle);
619 HeapFree(GetProcessHeap(),0,dllcache);
623 static BOOL start_services_process(void)
625 static const WCHAR svcctl_started_event[] = SVCCTL_STARTED_EVENT;
626 static const WCHAR services[] = {'\\','s','e','r','v','i','c','e','s','.','e','x','e',0};
627 PROCESS_INFORMATION pi;
629 HANDLE wait_handles[2];
630 WCHAR path[MAX_PATH];
632 if (!GetSystemDirectoryW(path, MAX_PATH - strlenW(services)))
634 strcatW(path, services);
635 ZeroMemory(&si, sizeof(si));
637 if (!CreateProcessW(path, path, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
639 WINE_ERR("Couldn't start services.exe: error %u\n", GetLastError());
642 CloseHandle(pi.hThread);
644 wait_handles[0] = CreateEventW(NULL, TRUE, FALSE, svcctl_started_event);
645 wait_handles[1] = pi.hProcess;
647 /* wait for the event to become available or the process to exit */
648 if ((WaitForMultipleObjects(2, wait_handles, FALSE, INFINITE)) == WAIT_OBJECT_0 + 1)
651 GetExitCodeProcess(pi.hProcess, &exit_code);
652 WINE_ERR("Unexpected termination of services.exe - exit code %d\n", exit_code);
653 CloseHandle(pi.hProcess);
654 CloseHandle(wait_handles[0]);
658 CloseHandle(pi.hProcess);
659 CloseHandle(wait_handles[0]);
663 /* execute rundll32 on the wine.inf file if necessary */
664 static void update_wineprefix( int force )
666 static const WCHAR cmdlineW[] = {'D','e','f','a','u','l','t','I','n','s','t','a','l','l',' ',
667 '1','2','8',' ','\\','\\','?','\\','u','n','i','x' };
669 const char *config_dir = wine_get_config_dir();
670 char *inf_path = get_wine_inf_path();
676 WINE_MESSAGE( "wine: failed to update %s, wine.inf not found\n", config_dir );
679 if ((fd = open( inf_path, O_RDONLY )) == -1)
681 WINE_MESSAGE( "wine: failed to update %s with %s: %s\n",
682 config_dir, inf_path, strerror(errno) );
688 if (update_timestamp( config_dir, st.st_mtime ) || force)
691 DWORD len = MultiByteToWideChar( CP_UNIXCP, 0, inf_path, -1, NULL, 0 );
692 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeof(cmdlineW) + len*sizeof(WCHAR) ))) goto done;
693 memcpy( buffer, cmdlineW, sizeof(cmdlineW) );
694 MultiByteToWideChar( CP_UNIXCP, 0, inf_path, -1, buffer + sizeof(cmdlineW)/sizeof(WCHAR), len );
696 InstallHinfSectionW( 0, 0, buffer, 0 );
697 HeapFree( GetProcessHeap(), 0, buffer );
698 WINE_MESSAGE( "wine: configuration in '%s' has been updated.\n", config_dir );
702 HeapFree( GetProcessHeap(), 0, inf_path );
705 /* Process items in the StartUp group of the user's Programs under the Start Menu. Some installers put
706 * shell links here to restart themselves after boot. */
707 static BOOL ProcessStartupItems(void)
712 IShellFolder *psfDesktop = NULL, *psfStartup = NULL;
713 LPITEMIDLIST pidlStartup = NULL, pidlItem;
715 IEnumIDList *iEnumList = NULL;
717 WCHAR wszCommand[MAX_PATH];
719 WINE_TRACE("Processing items in the StartUp folder.\n");
721 hr = SHGetMalloc(&ppM);
724 WINE_ERR("Couldn't get IMalloc object.\n");
728 hr = SHGetDesktopFolder(&psfDesktop);
731 WINE_ERR("Couldn't get desktop folder.\n");
735 hr = SHGetSpecialFolderLocation(NULL, CSIDL_STARTUP, &pidlStartup);
738 WINE_TRACE("Couldn't get StartUp folder location.\n");
742 hr = IShellFolder_BindToObject(psfDesktop, pidlStartup, NULL, &IID_IShellFolder, (LPVOID*)&psfStartup);
745 WINE_TRACE("Couldn't bind IShellFolder to StartUp folder.\n");
749 hr = IShellFolder_EnumObjects(psfStartup, NULL, SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
752 WINE_TRACE("Unable to enumerate StartUp objects.\n");
756 while (IEnumIDList_Next(iEnumList, 1, &pidlItem, &NumPIDLs) == S_OK &&
759 hr = IShellFolder_GetDisplayNameOf(psfStartup, pidlItem, SHGDN_FORPARSING, &strret);
761 WINE_TRACE("Unable to get display name of enumeration item.\n");
764 hr = StrRetToBufW(&strret, pidlItem, wszCommand, MAX_PATH);
766 WINE_TRACE("Unable to parse display name.\n");
771 hinst = ShellExecuteW(NULL, NULL, wszCommand, NULL, NULL, SW_SHOWNORMAL);
772 if (PtrToUlong(hinst) <= 32)
773 WINE_WARN("Error %p executing command %s.\n", hinst, wine_dbgstr_w(wszCommand));
777 IMalloc_Free(ppM, pidlItem);
784 if (iEnumList) IEnumIDList_Release(iEnumList);
785 if (psfStartup) IShellFolder_Release(psfStartup);
786 if (pidlStartup) IMalloc_Free(ppM, pidlStartup);
791 static void usage(void)
793 WINE_MESSAGE( "Usage: wineboot [options]\n" );
794 WINE_MESSAGE( "Options;\n" );
795 WINE_MESSAGE( " -h,--help Display this help message\n" );
796 WINE_MESSAGE( " -e,--end-session End the current session cleanly\n" );
797 WINE_MESSAGE( " -f,--force Force exit for processes that don't exit cleanly\n" );
798 WINE_MESSAGE( " -i,--init Perform initialization for first Wine instance\n" );
799 WINE_MESSAGE( " -k,--kill Kill running processes without any cleanup\n" );
800 WINE_MESSAGE( " -r,--restart Restart only, don't do normal startup operations\n" );
801 WINE_MESSAGE( " -s,--shutdown Shutdown only, don't reboot\n" );
802 WINE_MESSAGE( " -u,--update Update the wineprefix directory\n" );
805 static const char short_options[] = "efhikrsu";
807 static const struct option long_options[] =
809 { "help", 0, 0, 'h' },
810 { "end-session", 0, 0, 'e' },
811 { "force", 0, 0, 'f' },
812 { "init" , 0, 0, 'i' },
813 { "kill", 0, 0, 'k' },
814 { "restart", 0, 0, 'r' },
815 { "shutdown", 0, 0, 's' },
816 { "update", 0, 0, 'u' },
820 int main( int argc, char *argv[] )
822 extern HANDLE CDECL __wine_make_process_system(void);
823 static const WCHAR wineboot_eventW[] = {'_','_','w','i','n','e','b','o','o','t','_','e','v','e','n','t',0};
825 /* First, set the current directory to SystemRoot */
827 int end_session = 0, force = 0, init = 0, kill = 0, restart = 0, shutdown = 0, update = 0;
829 SECURITY_ATTRIBUTES sa;
831 GetWindowsDirectoryW( windowsdir, MAX_PATH );
832 if( !SetCurrentDirectoryW( windowsdir ) )
833 WINE_ERR("Cannot set the dir to %s (%d)\n", wine_dbgstr_w(windowsdir), GetLastError() );
835 while ((optc = getopt_long(argc, argv, short_options, long_options, NULL )) != -1)
839 case 'e': end_session = kill = 1; break;
840 case 'f': force = 1; break;
841 case 'i': init = 1; break;
842 case 'k': kill = 1; break;
843 case 'r': restart = 1; break;
844 case 's': shutdown = 1; break;
845 case 'u': update = 1; break;
846 case 'h': usage(); return 0;
847 case '?': usage(); return 1;
853 if (!shutdown_close_windows( force )) return 1;
856 if (kill) kill_processes( shutdown );
858 if (shutdown) return 0;
860 sa.nLength = sizeof(sa);
861 sa.lpSecurityDescriptor = NULL;
862 sa.bInheritHandle = TRUE; /* so that services.exe inherits it */
863 event = CreateEventW( &sa, TRUE, FALSE, wineboot_eventW );
865 ResetEvent( event ); /* in case this is a restart */
870 ProcessWindowsFileProtection();
871 ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNSERVICESONCE], TRUE, FALSE );
873 if (init || (kill && !restart))
875 ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNSERVICES], FALSE, FALSE );
876 start_services_process();
878 if (init || update) update_wineprefix( update );
880 ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNONCE], TRUE, TRUE );
882 if (!init && !restart)
884 ProcessRunKeys( HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUN], FALSE, FALSE );
885 ProcessRunKeys( HKEY_CURRENT_USER, runkeys_names[RUNKEY_RUN], FALSE, FALSE );
886 ProcessStartupItems();
889 WINE_TRACE("Operation done\n");