int main( int argc, char *argv[] ) { extern HANDLE CDECL __wine_make_process_system(void); static const WCHAR RunW[] = {'R','u','n',0}; static const WCHAR RunOnceW[] = {'R','u','n','O','n','c','e',0}; static const WCHAR RunServicesW[] = {'R','u','n','S','e','r','v','i','c','e','s',0}; static const WCHAR RunServicesOnceW[] = {'R','u','n','S','e','r','v','i','c','e','s','O','n','c','e',0}; static const WCHAR wineboot_eventW[] = {'_','_','w','i','n','e','b','o','o','t','_','e','v','e','n','t',0}; /* First, set the current directory to SystemRoot */ int optc; int end_session = 0, force = 0, init = 0, kill = 0, restart = 0, shutdown = 0, update = 0; HANDLE event; SECURITY_ATTRIBUTES sa; BOOL is_wow64; GetWindowsDirectoryW( windowsdir, MAX_PATH ); if( !SetCurrentDirectoryW( windowsdir ) ) WINE_ERR("Cannot set the dir to %s (%d)\n", wine_dbgstr_w(windowsdir), GetLastError() ); if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64) { STARTUPINFOW si; PROCESS_INFORMATION pi; WCHAR filename[MAX_PATH]; void *redir; DWORD exit_code; memset( &si, 0, sizeof(si) ); si.cb = sizeof(si); GetModuleFileNameW( 0, filename, MAX_PATH ); Wow64DisableWow64FsRedirection( &redir ); if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi )) { WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) ); WaitForSingleObject( pi.hProcess, INFINITE ); GetExitCodeProcess( pi.hProcess, &exit_code ); ExitProcess( exit_code ); } else WINE_ERR( "failed to restart 64-bit %s, err %d\n", wine_dbgstr_w(filename), GetLastError() ); Wow64RevertWow64FsRedirection( redir ); } while ((optc = getopt_long(argc, argv, short_options, long_options, NULL )) != -1) { switch(optc) { case 'e': end_session = 1; break; case 'f': force = 1; break; case 'i': init = 1; break; case 'k': kill = 1; break; case 'r': restart = 1; break; case 's': shutdown = 1; break; case 'u': update = 1; break; case 'h': usage(); return 0; case '?': usage(); return 1; } } if (end_session) { if (kill) { if (!shutdown_all_desktops( force )) return 1; } else if (!shutdown_close_windows( force )) return 1; } if (kill) kill_processes( shutdown ); if (shutdown) return 0; sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; /* so that services.exe inherits it */ event = CreateEventW( &sa, TRUE, FALSE, wineboot_eventW ); ResetEvent( event ); /* in case this is a restart */ create_hardware_registry_keys(); create_dynamic_registry_keys(); create_environment_registry_keys(); wininit(); pendingRename(); ProcessWindowsFileProtection(); ProcessRunKeys( HKEY_LOCAL_MACHINE, RunServicesOnceW, TRUE, FALSE ); if (init || (kill && !restart)) { ProcessRunKeys( HKEY_LOCAL_MACHINE, RunServicesW, FALSE, FALSE ); start_services_process(); } if (init || update) update_wineprefix( update ); create_volatile_environment_registry_key(); ProcessRunKeys( HKEY_LOCAL_MACHINE, RunOnceW, TRUE, TRUE ); if (!init && !restart) { ProcessRunKeys( HKEY_LOCAL_MACHINE, RunW, FALSE, FALSE ); ProcessRunKeys( HKEY_CURRENT_USER, RunW, FALSE, FALSE ); ProcessStartupItems(); } WINE_TRACE("Operation done\n"); SetEvent( event ); return 0; }
int startup(int argc, char *argv[]) { struct op_mask ops; /* Which of the ops do we want to perform? */ /* First, set the current directory to SystemRoot */ TCHAR gen_path[MAX_PATH]; DWORD res; res = GetWindowsDirectory(gen_path, sizeof(gen_path)); if (res==0) { printf("Couldn't get the windows directory - error %ld\n", GetLastError()); return 100; } if (res>=sizeof(gen_path)) { printf("Windows path too long (%ld)\n", res); return 100; } if (!SetCurrentDirectory(gen_path)) { wprintf(L"Cannot set the dir to %s (%ld)\n", gen_path, GetLastError()); return 100; } if (argc>1) { switch(argv[1][0]) { case 'r': /* Restart */ ops=SETUP; break; case 's': /* Full start */ ops=SESSION_START; break; default: ops=DEFAULT; break; } } else ops=DEFAULT; /* Perform the ops by order, stopping if one fails, skipping if necessary */ /* Shachar: Sorry for the perl syntax */ res=(ops.ntonly || !ops.preboot || wininit()) && (ops.w9xonly || !ops.preboot || pendingRename()) && (ops.ntonly || !ops.prelogin || ProcessRunKeys(HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNSERVICESONCE], TRUE, FALSE)) && (ops.ntonly || !ops.prelogin || !ops.startup || ProcessRunKeys(HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNSERVICES], FALSE, FALSE)) && (!ops.postlogin || ProcessRunKeys(HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNONCE], TRUE, TRUE)) && (!ops.postlogin || !ops.startup || ProcessRunKeys(HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUN], FALSE, FALSE)) && (!ops.postlogin || !ops.startup || ProcessRunKeys(HKEY_CURRENT_USER, runkeys_names[RUNKEY_RUN], FALSE, FALSE)); printf("Operation done\n"); return res?0:101; }
int startup(int argc, const char *argv[]) { struct op_mask ops; /* Which of the ops do we want to perform? */ /* First, set the current directory to SystemRoot */ TCHAR gen_path[MAX_PATH]; DWORD res; HKEY hSessionKey, hKey; HRESULT hr; res = GetWindowsDirectory(gen_path, sizeof(gen_path)); if (res==0) { printf("Couldn't get the windows directory - error %ld\n", GetLastError()); return 100; } if (!SetCurrentDirectory(gen_path)) { wprintf(L"Cannot set the dir to %s (%ld)\n", gen_path, GetLastError()); return 100; } hr = SHCreateSessionKey(KEY_WRITE, &hSessionKey); if (SUCCEEDED(hr)) { LONG Error; DWORD dwDisp; Error = RegCreateKeyEx(hSessionKey, L"StartupHasBeenRun", 0, NULL, REG_OPTION_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp); RegCloseKey(hSessionKey); if (Error == ERROR_SUCCESS) { RegCloseKey(hKey); if (dwDisp == REG_OPENED_EXISTING_KEY) { /* Startup programs has already been run */ return 0; } } } if (argc > 1) { switch(argv[1][0]) { case 'r': /* Restart */ ops = SETUP; break; case 's': /* Full start */ ops = SESSION_START; break; default: ops = DEFAULT; break; } } else ops = DEFAULT; /* do not run certain items in Safe Mode */ if(GetSystemMetrics(SM_CLEANBOOT)) ops.startup = FALSE; /* Perform the ops by order, stopping if one fails, skipping if necessary */ /* Shachar: Sorry for the perl syntax */ res = TRUE; if (res && !ops.ntonly && ops.preboot) res = wininit(); if (res && !ops.w9xonly && ops.preboot) res = pendingRename(); if (res && !ops.ntonly && ops.prelogin) res = ProcessRunKeys(HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNSERVICESONCE], TRUE, FALSE); if (res && !ops.ntonly && ops.prelogin && ops.startup) res = ProcessRunKeys(HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNSERVICES], FALSE, FALSE); if (res && ops.postlogin) res = ProcessRunKeys(HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUNONCE], TRUE, TRUE); if (res && ops.postlogin && ops.startup) res = ProcessRunKeys(HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUN], FALSE, FALSE); if (res && ops.postlogin && ops.startup) res = ProcessRunKeys(HKEY_CURRENT_USER, runkeys_names[RUNKEY_RUN], FALSE, FALSE); if (res && ops.postlogin && ops.startup) res = ProcessRunKeys(HKEY_CURRENT_USER, runkeys_names[RUNKEY_RUNONCE], TRUE, FALSE); printf("Operation done\n"); return res ? 0 : 101; }