ReactOS  0.4.15-dev-1152-g6c94e4f
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 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 47 of file startup.cpp.

Function Documentation

◆ AutoStartupApplications()

static BOOL AutoStartupApplications ( INT  nCSIDL_Folder)
static

Definition at line 321 of file startup.cpp.

322 {
323  WCHAR szPath[MAX_PATH] = { 0 };
324  HRESULT hResult;
325  HANDLE hFind;
326  WIN32_FIND_DATAW FoundData;
327  size_t cchPathLen;
328 
329  TRACE("(%d)\n", nCSIDL_Folder);
330 
331  // Get the special folder path
332  hResult = SHGetFolderPathW(NULL, nCSIDL_Folder, NULL, SHGFP_TYPE_CURRENT, szPath);
333  cchPathLen = wcslen(szPath);
334  if (!SUCCEEDED(hResult) || cchPathLen == 0)
335  {
336  WARN("SHGetFolderPath() failed with error %lu\n", GetLastError());
337  return FALSE;
338  }
339 
340  // Build a path with wildcard
341  StringCbCatW(szPath, sizeof(szPath), L"\\*");
342 
343  // Start enumeration of files
344  hFind = FindFirstFileW(szPath, &FoundData);
345  if (hFind == INVALID_HANDLE_VALUE)
346  {
347  WARN("FindFirstFile(%s) failed with error %lu\n", debugstr_w(szPath), GetLastError());
348  return FALSE;
349  }
350 
351  // Enumerate the files
352  do
353  {
354  // Ignore "." and ".."
355  if (wcscmp(FoundData.cFileName, L".") == 0 ||
356  wcscmp(FoundData.cFileName, L"..") == 0)
357  {
358  continue;
359  }
360 
361  // Don't run hidden files
362  if (FoundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
363  continue;
364 
365  // Build the path
366  szPath[cchPathLen + 1] = UNICODE_NULL;
367  StringCbCatW(szPath, sizeof(szPath), FoundData.cFileName);
368 
369  TRACE("Executing %s in directory %s\n", debugstr_w(FoundData.cFileName), debugstr_w(szPath));
370 
371  DWORD dwType;
372  if (GetBinaryTypeW(szPath, &dwType))
373  {
375  }
376  else
377  {
378  SHELLEXECUTEINFOW ExecInfo;
379  ZeroMemory(&ExecInfo, sizeof(ExecInfo));
380  ExecInfo.cbSize = sizeof(ExecInfo);
381  ExecInfo.lpFile = szPath;
382  ShellExecuteExW(&ExecInfo);
383  }
384  } while (FindNextFileW(hFind, &FoundData));
385 
386  FindClose(hFind);
387  return TRUE;
388 }
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:112
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ZeroMemory
Definition: winbase.h:1648
BOOL WINAPI GetBinaryTypeW(LPCWSTR lpApplicationName, LPDWORD lpBinaryType)
Definition: vdm.c:1235
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2263
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
LPCWSTR szPath
Definition: env.c:35
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2208
static int runCmd(LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
Definition: startup.cpp:60
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:49
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by ProcessStartupItems().

◆ DoFinishStartupItems()

BOOL DoFinishStartupItems ( VOID  )

Definition at line 443 of file startup.cpp.

444 {
445  if (s_hStartupMutex)
446  {
450  }
451  return TRUE;
452 }
#define CloseHandle
Definition: compat.h:487
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
static HANDLE s_hStartupMutex
Definition: startup.cpp:45

Referenced by DoStartStartupItems(), and StartWithDesktop().

◆ DoStartStartupItems()

BOOL DoStartStartupItems ( ITrayWindow *  Tray)

Definition at line 454 of file startup.cpp.

455 {
456  DWORD dwWait;
457 
458  if (!bExplorerIsShell)
459  return FALSE;
460 
461  if (!s_hStartupMutex)
462  {
463  // Accidentally, there is possibility that the system starts multiple Explorers
464  // before startup of shell. We use a mutex to match the timing of shell initialization.
465  s_hStartupMutex = CreateMutexW(NULL, FALSE, L"ExplorerIsShellMutex");
466  if (s_hStartupMutex == NULL)
467  return FALSE;
468  }
469 
471  TRACE("dwWait: 0x%08lX\n", dwWait);
472  if (dwWait != WAIT_OBJECT_0)
473  {
474  TRACE("LastError: %ld\n", GetLastError());
475 
477  return FALSE;
478  }
479 
480  const DWORD dwWaitTotal = 3000; // in milliseconds
481  DWORD dwTick = GetTickCount();
482  while (GetShellWindow() == NULL && GetTickCount() - dwTick < dwWaitTotal)
483  {
484  TrayProcessMessages(Tray);
485  }
486 
487  if (GetShellWindow() == NULL)
488  {
490  return FALSE;
491  }
492 
493  // Check the volatile "StartupHasBeenRun" key
494  HKEY hSessionKey, hKey;
495  HRESULT hr = SHCreateSessionKey(KEY_WRITE, &hSessionKey);
496  if (SUCCEEDED(hr))
497  {
498  ASSERT(hSessionKey);
499 
500  DWORD dwDisp;
501  LONG Error = RegCreateKeyExW(hSessionKey, L"StartupHasBeenRun", 0, NULL,
502  REG_OPTION_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
503  RegCloseKey(hSessionKey);
504  RegCloseKey(hKey);
505  if (Error == ERROR_SUCCESS && dwDisp == REG_OPENED_EXISTING_KEY)
506  {
507  return FALSE; // Startup programs has already been run
508  }
509  }
510 
511  return TRUE;
512 }
BOOL DoFinishStartupItems(VOID)
Definition: startup.cpp:443
HWND WINAPI GetShellWindow(VOID)
Definition: desktop.c:651
BOOL bExplorerIsShell
Definition: explorer.cpp:27
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
#define TRUE
Definition: types.h:120
VOID TrayProcessMessages(IN OUT ITrayWindow *Tray)
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
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:1091
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define KEY_WRITE
Definition: nt_native.h:1031
#define TRACE(s)
Definition: solgame.cpp:4
#define WAIT_OBJECT_0
Definition: winbase.h:387
HRESULT WINAPI SHCreateSessionKey(REGSAM samDesired, PHKEY phKey)
Definition: shellreg.c:151
LONG HRESULT
Definition: typedefs.h:79
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
static HANDLE s_hStartupMutex
Definition: startup.cpp:45
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define INFINITE
Definition: serial.h:102
#define SUCCEEDED(hr)
Definition: intsafe.h:49

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 135 of file startup.cpp.

137 {
138  HKEY hkWin = NULL, hkRun = NULL;
140  DWORD i, cbMaxCmdLine = 0, cchMaxValue = 0;
141  WCHAR *szCmdLine = NULL;
142  WCHAR *szValue = NULL;
143 
144  if (hkRoot == HKEY_LOCAL_MACHINE)
145  TRACE("processing %ls entries under HKLM\n", szKeyName);
146  else
147  TRACE("processing %ls entries under HKCU\n", szKeyName);
148 
149  res = RegOpenKeyExW(hkRoot,
150  L"Software\\Microsoft\\Windows\\CurrentVersion",
151  0,
152  KEY_READ,
153  &hkWin);
154  if (res != ERROR_SUCCESS)
155  {
156  TRACE("RegOpenKeyW failed on Software\\Microsoft\\Windows\\CurrentVersion (%ld)\n", res);
157 
158  goto end;
159  }
160 
161  res = RegOpenKeyExW(hkWin,
162  szKeyName,
163  0,
164  bDelete ? KEY_ALL_ACCESS : KEY_READ,
165  &hkRun);
166  if (res != ERROR_SUCCESS)
167  {
168  if (res == ERROR_FILE_NOT_FOUND)
169  {
170  TRACE("Key doesn't exist - nothing to be done\n");
171 
172  res = ERROR_SUCCESS;
173  }
174  else
175  TRACE("RegOpenKeyExW failed on run key (%ld)\n", res);
176 
177  goto end;
178  }
179 
180  res = RegQueryInfoKeyW(hkRun,
181  NULL,
182  NULL,
183  NULL,
184  NULL,
185  NULL,
186  NULL,
187  &i,
188  &cchMaxValue,
189  &cbMaxCmdLine,
190  NULL,
191  NULL);
192  if (res != ERROR_SUCCESS)
193  {
194  TRACE("Couldn't query key info (%ld)\n", res);
195 
196  goto end;
197  }
198 
199  if (i == 0)
200  {
201  TRACE("No commands to execute.\n");
202 
203  res = ERROR_SUCCESS;
204  goto end;
205  }
206 
207  szCmdLine = (WCHAR*)HeapAlloc(hProcessHeap,
208  0,
209  cbMaxCmdLine);
210  if (szCmdLine == NULL)
211  {
212  TRACE("Couldn't allocate memory for the commands to be executed\n");
213 
215  goto end;
216  }
217 
218  ++cchMaxValue;
219  szValue = (WCHAR*)HeapAlloc(hProcessHeap,
220  0,
221  cchMaxValue * sizeof(*szValue));
222  if (szValue == NULL)
223  {
224  TRACE("Couldn't allocate memory for the value names\n");
225 
227  goto end;
228  }
229 
230  while (i > 0)
231  {
232  WCHAR *szCmdLineExp = NULL;
233  DWORD cchValLength = cchMaxValue, cbDataLength = cbMaxCmdLine;
234  DWORD type;
235 
236  --i;
237 
238  res = RegEnumValueW(hkRun,
239  i,
240  szValue,
241  &cchValLength,
242  0,
243  &type,
244  (PBYTE)szCmdLine,
245  &cbDataLength);
246  if (res != ERROR_SUCCESS)
247  {
248  TRACE("Couldn't read in value %lu - %ld\n", i, res);
249 
250  continue;
251  }
252 
253  /* safe mode - force to run if prefixed with asterisk */
254  if (GetSystemMetrics(SM_CLEANBOOT) && (szValue[0] != L'*')) continue;
255 
256  if (bDelete && (res = RegDeleteValueW(hkRun, szValue)) != ERROR_SUCCESS)
257  {
258  TRACE("Couldn't delete value - %lu, %ld. Running command anyways.\n", i, res);
259  }
260 
261  if (type != REG_SZ && type != REG_EXPAND_SZ)
262  {
263  TRACE("Incorrect type of value #%lu (%lu)\n", i, type);
264 
265  continue;
266  }
267 
268  if (type == REG_EXPAND_SZ)
269  {
270  DWORD dwNumOfChars;
271 
272  dwNumOfChars = ExpandEnvironmentStringsW(szCmdLine, NULL, 0);
273  if (dwNumOfChars)
274  {
275  szCmdLineExp = (WCHAR *)HeapAlloc(hProcessHeap, 0, dwNumOfChars * sizeof(*szCmdLineExp));
276 
277  if (szCmdLineExp == NULL)
278  {
279  TRACE("Couldn't allocate memory for the commands to be executed\n");
280 
282  goto end;
283  }
284 
285  ExpandEnvironmentStringsW(szCmdLine, szCmdLineExp, dwNumOfChars);
286  }
287  }
288 
289  res = runCmd(szCmdLineExp ? szCmdLineExp : szCmdLine, NULL, bSynchronous, FALSE);
290  if (res == INVALID_RUNCMD_RETURN)
291  {
292  TRACE("Error running cmd #%lu (%lu)\n", i, GetLastError());
293  }
294 
295  if (szCmdLineExp != NULL)
296  {
297  HeapFree(hProcessHeap, 0, szCmdLineExp);
298  szCmdLineExp = NULL;
299  }
300 
301  TRACE("Done processing cmd #%lu\n", i);
302  }
303 
304  res = ERROR_SUCCESS;
305 end:
306  if (szValue != NULL)
307  HeapFree(hProcessHeap, 0, szValue);
308  if (szCmdLine != NULL)
309  HeapFree(hProcessHeap, 0, szCmdLine);
310  if (hkRun != NULL)
311  RegCloseKey(hkRun);
312  if (hkWin != NULL)
313  RegCloseKey(hkWin);
314 
315  TRACE("done\n");
316 
317  return res == ERROR_SUCCESS ? TRUE : FALSE;
318 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
GLuint GLuint end
Definition: gl.h:1545
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
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
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:2853
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define SM_CLEANBOOT
Definition: winuser.h:1017
#define TRACE(s)
Definition: solgame.cpp:4
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
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:3686
static const WCHAR L[]
Definition: oid.c:1250
#define INVALID_RUNCMD_RETURN
Definition: startup.cpp:47
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2355
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
GLuint res
Definition: glext.h:9613
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
static int runCmd(LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
Definition: startup.cpp:60
BYTE * PBYTE
Definition: pedump.c:66
#define HeapFree(x, y, z)
Definition: compat.h:483
HANDLE hProcessHeap
Definition: kbswitch.c:25
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by ProcessStartupItems().

◆ ProcessStartupItems()

INT ProcessStartupItems ( VOID  )

Definition at line 390 of file startup.cpp.

391 {
392  /* TODO: ProcessRunKeys already checks SM_CLEANBOOT -- items prefixed with * should probably run even in safe mode */
393  BOOL bNormalBoot = GetSystemMetrics(SM_CLEANBOOT) == 0; /* Perform the operations that are performed every boot */
394  /* First, set the current directory to SystemRoot */
395  WCHAR gen_path[MAX_PATH];
396  DWORD res;
397 
398  res = GetWindowsDirectoryW(gen_path, _countof(gen_path));
399  if (res == 0)
400  {
401  TRACE("Couldn't get the windows directory - error %lu\n", GetLastError());
402 
403  return 100;
404  }
405 
406  if (!SetCurrentDirectoryW(gen_path))
407  {
408  TRACE("Cannot set the dir to %ls (%lu)\n", gen_path, GetLastError());
409 
410  return 100;
411  }
412 
413  /* Perform the operations by order checking if policy allows it, checking if this is not Safe Mode,
414  * stopping if one fails, skipping if necessary.
415  */
416  res = TRUE;
417  /* TODO: RunOnceEx */
418 
421 
422  if (res && bNormalBoot && (SHRestricted(REST_NOLOCALMACHINERUN) == 0))
424 
425  if (res && bNormalBoot && (SHRestricted(REST_NOCURRENTUSERRUNONCE) == 0))
427 
428  /* All users Startup folder */
430 
431  /* Current user Startup folder */
433 
434  /* TODO: HKCU\RunOnce runs even if StartupHasBeenRun exists */
435  if (res && bNormalBoot && (SHRestricted(REST_NOCURRENTUSERRUNONCE) == 0))
437 
438  TRACE("Operation done\n");
439 
440  return res ? 0 : 101;
441 }
#define TRUE
Definition: types.h:120
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define CSIDL_COMMON_STARTUP
Definition: shlobj.h:2035
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
static BOOL ProcessRunKeys(HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete, BOOL bSynchronous)
Definition: startup.cpp:135
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
static BOOL AutoStartupApplications(INT nCSIDL_Folder)
Definition: startup.cpp:321
#define SM_CLEANBOOT
Definition: winuser.h:1017
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define CSIDL_STARTUP
Definition: shlobj.h:2019
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2248
GLuint res
Definition: glext.h:9613
DWORD WINAPI SHRestricted(RESTRICTIONS policy)
Definition: shpolicy.c:836
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

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 60 of file startup.cpp.

61 {
62  STARTUPINFOW si;
64  DWORD exit_code = 0;
65 
66  memset(&si, 0, sizeof(si));
67  si.cb = sizeof(si);
68  if (minimized)
69  {
72  }
73  memset(&info, 0, sizeof(info));
74 
75  if (!CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, dir, &si, &info))
76  {
77  TRACE("Failed to run command (%lu)\n", GetLastError());
78 
79  return INVALID_RUNCMD_RETURN;
80  }
81 
82  TRACE("Successfully ran command\n");
83 
84  if (wait)
85  {
86  HANDLE Handles[] = { info.hProcess };
87  DWORD nCount = _countof(Handles);
88  DWORD dwWait;
89  MSG msg;
90 
91  /* wait for the process to exit */
92  for (;;)
93  {
94  /* We need to keep processing messages,
95  otherwise we will hang anything that is trying to send a message to us */
96  dwWait = MsgWaitForMultipleObjects(nCount, Handles, FALSE, INFINITE, QS_ALLINPUT);
97 
98  /* WAIT_OBJECT_0 + nCount signals an event in the message queue,
99  so anything other than that means we are done. */
100  if (dwWait != WAIT_OBJECT_0 + nCount)
101  {
102  if (dwWait >= WAIT_OBJECT_0 && dwWait < WAIT_OBJECT_0 + nCount)
103  TRACE("Event %u signaled\n", dwWait - WAIT_OBJECT_0);
104  else
105  WARN("Return code: %u\n", dwWait);
106  break;
107  }
108 
109  while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
110  {
113  }
114  }
115 
116  GetExitCodeProcess(info.hProcess, &exit_code);
117  }
118 
119  CloseHandle(info.hThread);
120  CloseHandle(info.hProcess);
121 
122  return exit_code;
123 }
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define CloseHandle
Definition: compat.h:487
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1168
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define WARN(fmt,...)
Definition: debug.h:112
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
TCHAR * cmdline
Definition: stretchblt.cpp:32
struct _test_info info[]
Definition: SetCursorPos.c:19
#define FALSE
Definition: types.h:117
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
smooth NULL
Definition: ftsmooth.c:416
unsigned int dir
Definition: maze.c:112
#define STARTF_USESHOWWINDOW
Definition: winbase.h:472
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:4595
static UINT exit_code
Definition: process.c:78
#define TRACE(s)
Definition: solgame.cpp:4
#define WAIT_OBJECT_0
Definition: winbase.h:387
DWORD cb
Definition: winbase.h:830
#define _countof(array)
Definition: sndvol32.h:68
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SW_MINIMIZE
Definition: winuser.h:770
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
WORD wShowWindow
Definition: winbase.h:842
#define INVALID_RUNCMD_RETURN
Definition: startup.cpp:47
#define QS_ALLINPUT
Definition: winuser.h:874
#define msg(x)
Definition: auth_time.c:54
DWORD dwFlags
Definition: winbase.h:841
BOOL WINAPI PeekMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
#define PM_REMOVE
Definition: winuser.h:1182
#define INFINITE
Definition: serial.h:102
#define memset(x, y, z)
Definition: compat.h:39

Referenced by AutoStartupApplications(), and ProcessRunKeys().

Variable Documentation

◆ s_hStartupMutex

HANDLE s_hStartupMutex = NULL
static

Definition at line 45 of file startup.cpp.

Referenced by DoFinishStartupItems(), and DoStartStartupItems().