ReactOS 0.4.15-dev-7834-g00c4b3d
startup.cpp File Reference
#include "precomp.h"
Include dependency graph for startup.cpp:

Go to the source code of this file.

Macros

#define INVALID_RUNCMD_RETURN   -1
 

Functions

static int runCmd (LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
 
static BOOL ProcessRunKeys (HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete, BOOL bSynchronous)
 
static BOOL ProcessRunOnceEx (HKEY hkRoot)
 
static BOOL AutoStartupApplications (INT nCSIDL_Folder)
 
INT ProcessStartupItems (VOID)
 
BOOL DoFinishStartupItems (VOID)
 
BOOL DoStartStartupItems (ITrayWindow *Tray)
 

Variables

static HANDLE s_hStartupMutex = NULL
 

Macro Definition Documentation

◆ INVALID_RUNCMD_RETURN

#define INVALID_RUNCMD_RETURN   -1

Definition at line 48 of file startup.cpp.

Function Documentation

◆ AutoStartupApplications()

static BOOL AutoStartupApplications ( INT  nCSIDL_Folder)
static

Definition at line 384 of file startup.cpp.

385{
386 WCHAR szPath[MAX_PATH] = { 0 };
387 HRESULT hResult;
388 HANDLE hFind;
389 WIN32_FIND_DATAW FoundData;
390 size_t cchPathLen;
391
392 TRACE("(%d)\n", nCSIDL_Folder);
393
394 // Get the special folder path
395 hResult = SHGetFolderPathW(NULL, nCSIDL_Folder, NULL, SHGFP_TYPE_CURRENT, szPath);
396 cchPathLen = wcslen(szPath);
397 if (!SUCCEEDED(hResult) || cchPathLen == 0)
398 {
399 WARN("SHGetFolderPath() failed with error %lu\n", GetLastError());
400 return FALSE;
401 }
402
403 // Build a path with wildcard
404 StringCbCatW(szPath, sizeof(szPath), L"\\*");
405
406 // Start enumeration of files
407 hFind = FindFirstFileW(szPath, &FoundData);
408 if (hFind == INVALID_HANDLE_VALUE)
409 {
410 WARN("FindFirstFile(%s) failed with error %lu\n", debugstr_w(szPath), GetLastError());
411 return FALSE;
412 }
413
414 // Enumerate the files
415 do
416 {
417 // Ignore "." and ".."
418 if (wcscmp(FoundData.cFileName, L".") == 0 ||
419 wcscmp(FoundData.cFileName, L"..") == 0)
420 {
421 continue;
422 }
423
424 // Don't run hidden files
425 if (FoundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
426 continue;
427
428 // Build the path
429 szPath[cchPathLen + 1] = UNICODE_NULL;
430 StringCbCatW(szPath, sizeof(szPath), FoundData.cFileName);
431
432 TRACE("Executing %s in directory %s\n", debugstr_w(FoundData.cFileName), debugstr_w(szPath));
433
434 DWORD dwType;
435 if (GetBinaryTypeW(szPath, &dwType))
436 {
438 }
439 else
440 {
441 SHELLEXECUTEINFOW ExecInfo;
442 ZeroMemory(&ExecInfo, sizeof(ExecInfo));
443 ExecInfo.cbSize = sizeof(ExecInfo);
444 ExecInfo.lpFile = szPath;
445 ShellExecuteExW(&ExecInfo);
446 }
447 } while (FindNextFileW(hFind, &FoundData));
448
449 FindClose(hFind);
450 return TRUE;
451}
#define WARN(fmt,...)
Definition: debug.h:112
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
BOOL WINAPI GetBinaryTypeW(LPCWSTR lpApplicationName, LPDWORD lpBinaryType)
Definition: vdm.c:1243
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2558
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define debugstr_w
Definition: kernel32.h:32
LPCWSTR szPath
Definition: env.c:37
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2368
@ SHGFP_TYPE_CURRENT
Definition: shlobj.h:2134
#define TRACE(s)
Definition: solgame.cpp:4
static int runCmd(LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
Definition: startup.cpp:61
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ProcessStartupItems().

◆ DoFinishStartupItems()

BOOL DoFinishStartupItems ( VOID  )

Definition at line 508 of file startup.cpp.

509{
510 if (s_hStartupMutex)
511 {
515 }
516 return TRUE;
517}
#define CloseHandle
Definition: compat.h:739
static HANDLE s_hStartupMutex
Definition: startup.cpp:46
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618

Referenced by DoStartStartupItems(), and StartWithDesktop().

◆ DoStartStartupItems()

BOOL DoStartStartupItems ( ITrayWindow *  Tray)

Definition at line 519 of file startup.cpp.

520{
521 DWORD dwWait;
522
523 if (!bExplorerIsShell)
524 return FALSE;
525
526 if (!s_hStartupMutex)
527 {
528 // Accidentally, there is possibility that the system starts multiple Explorers
529 // before startup of shell. We use a mutex to match the timing of shell initialization.
530 s_hStartupMutex = CreateMutexW(NULL, FALSE, L"ExplorerIsShellMutex");
531 if (s_hStartupMutex == NULL)
532 return FALSE;
533 }
534
536 TRACE("dwWait: 0x%08lX\n", dwWait);
537 if (dwWait != WAIT_OBJECT_0)
538 {
539 TRACE("LastError: %ld\n", GetLastError());
540
542 return FALSE;
543 }
544
545 const DWORD dwWaitTotal = 3000; // in milliseconds
546 DWORD dwTick = GetTickCount();
547 while (GetShellWindow() == NULL && GetTickCount() - dwTick < dwWaitTotal)
548 {
550 }
551
552 if (GetShellWindow() == NULL)
553 {
555 return FALSE;
556 }
557
558 // Check the volatile "StartupHasBeenRun" key
559 HKEY hSessionKey, hKey;
560 HRESULT hr = SHCreateSessionKey(KEY_WRITE, &hSessionKey);
561 if (SUCCEEDED(hr))
562 {
563 ASSERT(hSessionKey);
564
565 DWORD dwDisp;
566 LONG Error = RegCreateKeyExW(hSessionKey, L"StartupHasBeenRun", 0, NULL,
568 RegCloseKey(hSessionKey);
570 if (Error == ERROR_SUCCESS && dwDisp == REG_OPENED_EXISTING_KEY)
571 {
572 return FALSE; // Startup programs has already been run
573 }
574 }
575
576 return TRUE;
577}
BOOL bExplorerIsShell
Definition: explorer.cpp:27
VOID TrayProcessMessages(IN OUT ITrayWindow *Tray)
BOOL Error
Definition: chkdsk.c:66
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
#define INFINITE
Definition: serial.h:102
FxAutoRegKey hKey
#define ASSERT(a)
Definition: mode.c:44
#define KEY_WRITE
Definition: nt_native.h:1031
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
long LONG
Definition: pedump.c:60
HRESULT WINAPI SHCreateSessionKey(REGSAM samDesired, PHKEY phKey)
Definition: shellreg.c:147
HRESULT hr
Definition: shlfolder.c:183
BOOL DoFinishStartupItems(VOID)
Definition: startup.cpp:508
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
HWND WINAPI GetShellWindow(VOID)
Definition: desktop.c:651
#define WAIT_OBJECT_0
Definition: winbase.h:406

Referenced by StartWithDesktop().

◆ ProcessRunKeys()

static BOOL ProcessRunKeys ( HKEY  hkRoot,
LPCWSTR  szKeyName,
BOOL  bDelete,
BOOL  bSynchronous 
)
static

Process a "Run" type registry key. hkRoot is the HKEY from which "Software\Microsoft\Windows\CurrentVersion" is opened. szKeyName is the key holding the actual entries. bDelete tells whether we should delete each value right before executing it. bSynchronous tells whether we should wait for the prog to complete before going on to the next prog.

Definition at line 136 of file startup.cpp.

138{
139 HKEY hkWin = NULL, hkRun = NULL;
141 DWORD i, cbMaxCmdLine = 0, cchMaxValue = 0;
142 WCHAR *szCmdLine = NULL;
143 WCHAR *szValue = NULL;
144
145 if (hkRoot == HKEY_LOCAL_MACHINE)
146 TRACE("processing %ls entries under HKLM\n", szKeyName);
147 else
148 TRACE("processing %ls entries under HKCU\n", szKeyName);
149
150 res = RegOpenKeyExW(hkRoot,
151 L"Software\\Microsoft\\Windows\\CurrentVersion",
152 0,
153 KEY_READ,
154 &hkWin);
155 if (res != ERROR_SUCCESS)
156 {
157 TRACE("RegOpenKeyW failed on Software\\Microsoft\\Windows\\CurrentVersion (%ld)\n", res);
158
159 goto end;
160 }
161
162 res = RegOpenKeyExW(hkWin,
163 szKeyName,
164 0,
165 bDelete ? KEY_ALL_ACCESS : KEY_READ,
166 &hkRun);
167 if (res != ERROR_SUCCESS)
168 {
170 {
171 TRACE("Key doesn't exist - nothing to be done\n");
172
174 }
175 else
176 TRACE("RegOpenKeyExW failed on run key (%ld)\n", res);
177
178 goto end;
179 }
180
181 res = RegQueryInfoKeyW(hkRun,
182 NULL,
183 NULL,
184 NULL,
185 NULL,
186 NULL,
187 NULL,
188 &i,
189 &cchMaxValue,
190 &cbMaxCmdLine,
191 NULL,
192 NULL);
193 if (res != ERROR_SUCCESS)
194 {
195 TRACE("Couldn't query key info (%ld)\n", res);
196
197 goto end;
198 }
199
200 if (i == 0)
201 {
202 TRACE("No commands to execute.\n");
203
205 goto end;
206 }
207
208 szCmdLine = (WCHAR*)HeapAlloc(hProcessHeap,
209 0,
210 cbMaxCmdLine);
211 if (szCmdLine == NULL)
212 {
213 TRACE("Couldn't allocate memory for the commands to be executed\n");
214
216 goto end;
217 }
218
219 ++cchMaxValue;
220 szValue = (WCHAR*)HeapAlloc(hProcessHeap,
221 0,
222 cchMaxValue * sizeof(*szValue));
223 if (szValue == NULL)
224 {
225 TRACE("Couldn't allocate memory for the value names\n");
226
228 goto end;
229 }
230
231 while (i > 0)
232 {
233 WCHAR *szCmdLineExp = NULL;
234 DWORD cchValLength = cchMaxValue, cbDataLength = cbMaxCmdLine;
235 DWORD type;
236
237 --i;
238
239 res = RegEnumValueW(hkRun,
240 i,
241 szValue,
242 &cchValLength,
243 0,
244 &type,
245 (PBYTE)szCmdLine,
246 &cbDataLength);
247 if (res != ERROR_SUCCESS)
248 {
249 TRACE("Couldn't read in value %lu - %ld\n", i, res);
250
251 continue;
252 }
253
254 /* safe mode - force to run if prefixed with asterisk */
255 if (GetSystemMetrics(SM_CLEANBOOT) && (szValue[0] != L'*')) continue;
256
257 if (bDelete && (res = RegDeleteValueW(hkRun, szValue)) != ERROR_SUCCESS)
258 {
259 TRACE("Couldn't delete value - %lu, %ld. Running command anyways.\n", i, res);
260 }
261
262 if (type != REG_SZ && type != REG_EXPAND_SZ)
263 {
264 TRACE("Incorrect type of value #%lu (%lu)\n", i, type);
265
266 continue;
267 }
268
269 if (type == REG_EXPAND_SZ)
270 {
271 DWORD dwNumOfChars;
272
273 dwNumOfChars = ExpandEnvironmentStringsW(szCmdLine, NULL, 0);
274 if (dwNumOfChars)
275 {
276 szCmdLineExp = (WCHAR *)HeapAlloc(hProcessHeap, 0, dwNumOfChars * sizeof(*szCmdLineExp));
277
278 if (szCmdLineExp == NULL)
279 {
280 TRACE("Couldn't allocate memory for the commands to be executed\n");
281
283 goto end;
284 }
285
286 ExpandEnvironmentStringsW(szCmdLine, szCmdLineExp, dwNumOfChars);
287 }
288 }
289
290 res = runCmd(szCmdLineExp ? szCmdLineExp : szCmdLine, NULL, bSynchronous, FALSE);
292 {
293 TRACE("Error running cmd #%lu (%lu)\n", i, GetLastError());
294 }
295
296 if (szCmdLineExp != NULL)
297 {
298 HeapFree(hProcessHeap, 0, szCmdLineExp);
299 szCmdLineExp = NULL;
300 }
301
302 TRACE("Done processing cmd #%lu\n", i);
303 }
304
306end:
307 if (szValue != NULL)
308 HeapFree(hProcessHeap, 0, szValue);
309 if (szCmdLine != NULL)
310 HeapFree(hProcessHeap, 0, szCmdLine);
311 if (hkRun != NULL)
312 RegCloseKey(hkRun);
313 if (hkWin != NULL)
314 RegCloseKey(hkWin);
315
316 TRACE("done\n");
317
318 return res == ERROR_SUCCESS ? TRUE : FALSE;
319}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3662
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HANDLE hProcessHeap
Definition: kbswitch.c:37
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_READ
Definition: nt_native.h:1023
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
BYTE * PBYTE
Definition: pedump.c:66
#define INVALID_RUNCMD_RETURN
Definition: startup.cpp:48
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define SM_CLEANBOOT
Definition: winuser.h:1027
int WINAPI GetSystemMetrics(_In_ int)

Referenced by ProcessStartupItems().

◆ ProcessRunOnceEx()

static BOOL ProcessRunOnceEx ( HKEY  hkRoot)
static

Process "RunOnceEx" type registry key. rundll32.exe will be invoked if the corresponding key has items inside, and wait for it. hkRoot is the HKEY from which "Software\Microsoft\Windows\CurrentVersion\RunOnceEx" is opened.

Definition at line 328 of file startup.cpp.

329{
330 HKEY hkRunOnceEx = NULL;
332 WCHAR cmdLine[] = L"rundll32 iernonce.dll RunOnceExProcess";
333 DWORD dwSubKeyCnt;
334
335 res = RegOpenKeyExW(hkRoot,
336 L"Software\\Microsoft\\Windows\\CurrentVersion\\RunOnceEx",
337 0,
338 KEY_READ,
339 &hkRunOnceEx);
340 if (res != ERROR_SUCCESS)
341 {
342 TRACE("RegOpenKeyW failed on Software\\Microsoft\\Windows\\CurrentVersion\\RunOnceEx (%ld)\n", res);
343 goto end;
344 }
345
346 res = RegQueryInfoKeyW(hkRunOnceEx,
347 NULL,
348 NULL,
349 NULL,
350 &dwSubKeyCnt,
351 NULL,
352 NULL,
353 NULL,
354 NULL,
355 NULL,
356 NULL,
357 NULL);
358
359 if (res != ERROR_SUCCESS)
360 {
361 TRACE("RegQueryInfoKeyW failed on Software\\Microsoft\\Windows\\CurrentVersion\\RunOnceEx (%ld)\n", res);
362 goto end;
363 }
364
365 if (dwSubKeyCnt != 0)
366 {
367 if (runCmd(cmdLine, NULL, TRUE, TRUE) == INVALID_RUNCMD_RETURN)
368 {
369 TRACE("runCmd failed (%ld)\n", res = GetLastError());
370 goto end;
371 }
372 }
373
374end:
375 if (hkRunOnceEx != NULL)
376 RegCloseKey(hkRunOnceEx);
377
378 TRACE("done\n");
379
380 return res == ERROR_SUCCESS ? TRUE : FALSE;
381}

Referenced by ProcessStartupItems().

◆ ProcessStartupItems()

INT ProcessStartupItems ( VOID  )

Definition at line 453 of file startup.cpp.

454{
455 /* TODO: ProcessRunKeys already checks SM_CLEANBOOT -- items prefixed with * should probably run even in safe mode */
456 BOOL bNormalBoot = GetSystemMetrics(SM_CLEANBOOT) == 0; /* Perform the operations that are performed every boot */
457 /* First, set the current directory to SystemRoot */
458 WCHAR gen_path[MAX_PATH];
459 DWORD res;
460
461 res = GetWindowsDirectoryW(gen_path, _countof(gen_path));
462 if (res == 0)
463 {
464 TRACE("Couldn't get the windows directory - error %lu\n", GetLastError());
465
466 return 100;
467 }
468
469 if (!SetCurrentDirectoryW(gen_path))
470 {
471 TRACE("Cannot set the dir to %ls (%lu)\n", gen_path, GetLastError());
472
473 return 100;
474 }
475
476 /* Perform the operations by order checking if policy allows it, checking if this is not Safe Mode,
477 * stopping if one fails, skipping if necessary.
478 */
479 res = TRUE;
480
481 if (res && bNormalBoot)
483
486
487 if (res && bNormalBoot && (SHRestricted(REST_NOLOCALMACHINERUN) == 0))
489
490 if (res && bNormalBoot && (SHRestricted(REST_NOCURRENTUSERRUNONCE) == 0))
492
493 /* All users Startup folder */
495
496 /* Current user Startup folder */
498
499 /* TODO: HKCU\RunOnce runs even if StartupHasBeenRun exists */
500 if (res && bNormalBoot && (SHRestricted(REST_NOCURRENTUSERRUNONCE) == 0))
502
503 TRACE("Operation done\n");
504
505 return res ? 0 : 101;
506}
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2249
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
unsigned int BOOL
Definition: ntddk_ex.h:94
#define CSIDL_COMMON_STARTUP
Definition: shlobj.h:2181
#define CSIDL_STARTUP
Definition: shlobj.h:2165
@ REST_NOCURRENTUSERRUNONCE
Definition: shlobj.h:1731
@ REST_NOLOCALMACHINERUNONCE
Definition: shlobj.h:1730
@ REST_NOLOCALMACHINERUN
Definition: shlobj.h:1728
DWORD WINAPI SHRestricted(RESTRICTIONS rest)
Definition: shpolicy.c:146
#define _countof(array)
Definition: sndvol32.h:68
static BOOL ProcessRunKeys(HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete, BOOL bSynchronous)
Definition: startup.cpp:136
static BOOL ProcessRunOnceEx(HKEY hkRoot)
Definition: startup.cpp:328
static BOOL AutoStartupApplications(INT nCSIDL_Folder)
Definition: startup.cpp:384
#define HKEY_CURRENT_USER
Definition: winreg.h:11

Referenced by StartWithDesktop().

◆ runCmd()

static int runCmd ( LPWSTR  cmdline,
LPCWSTR  dir,
BOOL  wait,
BOOL  minimized 
)
static

This function runs the specified command in the specified dir. [in,out] cmdline - the command line to run. The function may change the passed buffer. [in] dir - the dir to run the command in. If it is NULL, then the current dir is used. [in] wait - whether to wait for the run program to finish before returning. [in] minimized - Whether to ask the program to run minimized.

Returns: If running the process failed, returns INVALID_RUNCMD_RETURN. Use GetLastError to get the error code. If wait is FALSE - returns 0 if successful. If wait is TRUE - returns the program's return value.

Definition at line 61 of file startup.cpp.

62{
63 STARTUPINFOW si;
65 DWORD exit_code = 0;
66
67 memset(&si, 0, sizeof(si));
68 si.cb = sizeof(si);
69 if (minimized)
70 {
73 }
74 memset(&info, 0, sizeof(info));
75
76 if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, dir, &si, &info))
77 {
78 TRACE("Failed to run command (%lu)\n", GetLastError());
79
81 }
82
83 TRACE("Successfully ran command\n");
84
85 if (wait)
86 {
87 HANDLE Handles[] = { info.hProcess };
88 DWORD nCount = _countof(Handles);
89 DWORD dwWait;
90 MSG msg;
91
92 /* wait for the process to exit */
93 for (;;)
94 {
95 /* We need to keep processing messages,
96 otherwise we will hang anything that is trying to send a message to us */
97 dwWait = MsgWaitForMultipleObjects(nCount, Handles, FALSE, INFINITE, QS_ALLINPUT);
98
99 /* WAIT_OBJECT_0 + nCount signals an event in the message queue,
100 so anything other than that means we are done. */
101 if (dwWait != WAIT_OBJECT_0 + nCount)
102 {
103 if (dwWait >= WAIT_OBJECT_0 && dwWait < WAIT_OBJECT_0 + nCount)
104 TRACE("Event %u signaled\n", dwWait - WAIT_OBJECT_0);
105 else
106 WARN("Return code: %u\n", dwWait);
107 break;
108 }
109
110 while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
111 {
114 }
115 }
116
118 }
119
120 CloseHandle(info.hThread);
121 CloseHandle(info.hProcess);
122
123 return exit_code;
124}
unsigned int dir
Definition: maze.c:112
#define msg(x)
Definition: auth_time.c:54
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4592
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1168
static UINT exit_code
Definition: process.c:78
#define memset(x, y, z)
Definition: compat.h:39
TCHAR * cmdline
Definition: stretchblt.cpp:32
DWORD cb
Definition: winbase.h:852
DWORD dwFlags
Definition: winbase.h:863
WORD wShowWindow
Definition: winbase.h:864
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define STARTF_USESHOWWINDOW
Definition: winbase.h:491
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define SW_MINIMIZE
Definition: winuser.h:776
#define QS_ALLINPUT
Definition: winuser.h:903
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
BOOL WINAPI PeekMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
#define PM_REMOVE
Definition: winuser.h:1196
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)

Referenced by AutoStartupApplications(), ProcessRunKeys(), and ProcessRunOnceEx().

Variable Documentation

◆ s_hStartupMutex

HANDLE s_hStartupMutex = NULL
static

Definition at line 46 of file startup.cpp.

Referenced by DoFinishStartupItems(), and DoStartStartupItems().