ReactOS  0.4.13-dev-79-gcd489d8
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 267 of file startup.cpp.

268 {
269  WCHAR szPath[MAX_PATH] = { 0 };
270  HRESULT hResult;
271  HANDLE hFind;
272  WIN32_FIND_DATAW FoundData;
273  size_t cchPathLen;
274 
275  TRACE("(%d)\n", nCSIDL_Folder);
276 
277  // Get the special folder path
278  hResult = SHGetFolderPathW(NULL, nCSIDL_Folder, NULL, SHGFP_TYPE_CURRENT, szPath);
279  cchPathLen = wcslen(szPath);
280  if (!SUCCEEDED(hResult) || cchPathLen == 0)
281  {
282  WARN("SHGetFolderPath() failed with error %lu\n", GetLastError());
283  return FALSE;
284  }
285 
286  // Build a path with wildcard
287  StringCbCatW(szPath, sizeof(szPath), L"\\*");
288 
289  // Start enumeration of files
290  hFind = FindFirstFileW(szPath, &FoundData);
291  if (hFind == INVALID_HANDLE_VALUE)
292  {
293  WARN("FindFirstFile(%s) failed with error %lu\n", debugstr_w(szPath), GetLastError());
294  return FALSE;
295  }
296 
297  // Enumerate the files
298  do
299  {
300  // Ignore "." and ".."
301  if (wcscmp(FoundData.cFileName, L".") == 0 ||
302  wcscmp(FoundData.cFileName, L"..") == 0)
303  {
304  continue;
305  }
306 
307  // Don't run hidden files
308  if (FoundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
309  continue;
310 
311  // Build the path
312  szPath[cchPathLen + 1] = UNICODE_NULL;
313  StringCbCatW(szPath, sizeof(szPath), FoundData.cFileName);
314 
315  TRACE("Executing %s in directory %s\n", debugstr_w(FoundData.cFileName), debugstr_w(szPath));
316 
317  DWORD dwType;
318  if (GetBinaryTypeW(szPath, &dwType))
319  {
321  }
322  else
323  {
324  SHELLEXECUTEINFOW ExecInfo;
325  ZeroMemory(&ExecInfo, sizeof(ExecInfo));
326  ExecInfo.cbSize = sizeof(ExecInfo);
327  ExecInfo.lpFile = szPath;
328  ShellExecuteExW(&ExecInfo);
329  }
330  } while (FindNextFileW(hFind, &FoundData));
331 
332  FindClose(hFind);
333  return TRUE;
334 }
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:111
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
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 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:2225
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
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:2085
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:57
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 389 of file startup.cpp.

390 {
391  if (s_hStartupMutex)
392  {
396  }
397  return TRUE;
398 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:564
static HANDLE s_hStartupMutex
Definition: startup.cpp:45

Referenced by DoStartStartupItems(), and StartWithDesktop().

◆ DoStartStartupItems()

BOOL DoStartStartupItems ( ITrayWindow *  Tray)

Definition at line 400 of file startup.cpp.

401 {
402  DWORD dwWait;
403 
404  if (!bExplorerIsShell)
405  return FALSE;
406 
407  if (!s_hStartupMutex)
408  {
409  // Accidentally, there is possibility that the system starts multiple Explorers
410  // before startup of shell. We use a mutex to match the timing of shell initialization.
411  s_hStartupMutex = CreateMutexW(NULL, FALSE, L"ExplorerIsShellMutex");
412  if (s_hStartupMutex == NULL)
413  return FALSE;
414  }
415 
417  TRACE("dwWait: 0x%08lX\n", dwWait);
418  if (dwWait != WAIT_OBJECT_0)
419  {
420  TRACE("LastError: %ld\n", GetLastError());
421 
423  return FALSE;
424  }
425 
426  const DWORD dwWaitTotal = 3000; // in milliseconds
427  DWORD dwTick = GetTickCount();
428  while (GetShellWindow() == NULL && GetTickCount() - dwTick < dwWaitTotal)
429  {
430  TrayProcessMessages(Tray);
431  }
432 
433  if (GetShellWindow() == NULL)
434  {
436  return FALSE;
437  }
438 
439  // Check the volatile "StartupHasBeenRun" key
440  HKEY hSessionKey, hKey;
441  HRESULT hr = SHCreateSessionKey(KEY_WRITE, &hSessionKey);
442  if (SUCCEEDED(hr))
443  {
444  ASSERT(hSessionKey);
445 
446  DWORD dwDisp;
447  LONG Error = RegCreateKeyExW(hSessionKey, L"StartupHasBeenRun", 0, NULL,
448  REG_OPTION_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
449  RegCloseKey(hSessionKey);
450  RegCloseKey(hKey);
451  if (Error == ERROR_SUCCESS && dwDisp == REG_OPENED_EXISTING_KEY)
452  {
453  return FALSE; // Startup programs has already been run
454  }
455  }
456 
457  return TRUE;
458 }
BOOL DoFinishStartupItems(VOID)
Definition: startup.cpp:389
HWND WINAPI GetShellWindow(VOID)
Definition: desktop.c:651
#define TRUE
Definition: types.h:120
BOOL bExplorerIsShell
Definition: explorer.cpp:27
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
VOID TrayProcessMessages(IN OUT ITrayWindow *Tray)
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#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:1094
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
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:77
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:522
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define INFINITE
Definition: serial.h:102
#define SUCCEEDED(hr)
Definition: intsafe.h:57

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

111 {
112  HKEY hkWin = NULL, hkRun = NULL;
114  DWORD i, cbMaxCmdLine = 0, cchMaxValue = 0;
115  WCHAR *szCmdLine = NULL;
116  WCHAR *szValue = NULL;
117 
118  if (hkRoot == HKEY_LOCAL_MACHINE)
119  TRACE("processing %ls entries under HKLM\n", szKeyName);
120  else
121  TRACE("processing %ls entries under HKCU\n", szKeyName);
122 
123  res = RegOpenKeyExW(hkRoot,
124  L"Software\\Microsoft\\Windows\\CurrentVersion",
125  0,
126  KEY_READ,
127  &hkWin);
128  if (res != ERROR_SUCCESS)
129  {
130  TRACE("RegOpenKeyW failed on Software\\Microsoft\\Windows\\CurrentVersion (%ld)\n", res);
131 
132  goto end;
133  }
134 
135  res = RegOpenKeyExW(hkWin,
136  szKeyName,
137  0,
138  bDelete ? KEY_ALL_ACCESS : KEY_READ,
139  &hkRun);
140  if (res != ERROR_SUCCESS)
141  {
142  if (res == ERROR_FILE_NOT_FOUND)
143  {
144  TRACE("Key doesn't exist - nothing to be done\n");
145 
146  res = ERROR_SUCCESS;
147  }
148  else
149  TRACE("RegOpenKeyExW failed on run key (%ld)\n", res);
150 
151  goto end;
152  }
153 
154  res = RegQueryInfoKeyW(hkRun,
155  NULL,
156  NULL,
157  NULL,
158  NULL,
159  NULL,
160  NULL,
161  &i,
162  &cchMaxValue,
163  &cbMaxCmdLine,
164  NULL,
165  NULL);
166  if (res != ERROR_SUCCESS)
167  {
168  TRACE("Couldn't query key info (%ld)\n", res);
169 
170  goto end;
171  }
172 
173  if (i == 0)
174  {
175  TRACE("No commands to execute.\n");
176 
177  res = ERROR_SUCCESS;
178  goto end;
179  }
180 
181  szCmdLine = (WCHAR*)HeapAlloc(hProcessHeap,
182  0,
183  cbMaxCmdLine);
184  if (szCmdLine == NULL)
185  {
186  TRACE("Couldn't allocate memory for the commands to be executed\n");
187 
189  goto end;
190  }
191 
192  ++cchMaxValue;
193  szValue = (WCHAR*)HeapAlloc(hProcessHeap,
194  0,
195  cchMaxValue * sizeof(*szValue));
196  if (szValue == NULL)
197  {
198  TRACE("Couldn't allocate memory for the value names\n");
199 
201  goto end;
202  }
203 
204  while (i > 0)
205  {
206  DWORD cchValLength = cchMaxValue, cbDataLength = cbMaxCmdLine;
207  DWORD type;
208 
209  --i;
210 
211  res = RegEnumValueW(hkRun,
212  i,
213  szValue,
214  &cchValLength,
215  0,
216  &type,
217  (PBYTE)szCmdLine,
218  &cbDataLength);
219  if (res != ERROR_SUCCESS)
220  {
221  TRACE("Couldn't read in value %lu - %ld\n", i, res);
222 
223  continue;
224  }
225 
226  /* safe mode - force to run if prefixed with asterisk */
227  if (GetSystemMetrics(SM_CLEANBOOT) && (szValue[0] != L'*')) continue;
228 
229  if (bDelete && (res = RegDeleteValueW(hkRun, szValue)) != ERROR_SUCCESS)
230  {
231  TRACE("Couldn't delete value - %lu, %ld. Running command anyways.\n", i, res);
232  }
233 
234  if (type != REG_SZ)
235  {
236  TRACE("Incorrect type of value #%lu (%lu)\n", i, type);
237 
238  continue;
239  }
240 
241  res = runCmd(szCmdLine, NULL, bSynchronous, FALSE);
242  if (res == INVALID_RUNCMD_RETURN)
243  {
244  TRACE("Error running cmd #%lu (%lu)\n", i, GetLastError());
245  }
246 
247  TRACE("Done processing cmd #%lu\n", i);
248  }
249 
250  res = ERROR_SUCCESS;
251 end:
252  if (szValue != NULL)
253  HeapFree(hProcessHeap, 0, szValue);
254  if (szCmdLine != NULL)
255  HeapFree(hProcessHeap, 0, szCmdLine);
256  if (hkRun != NULL)
257  RegCloseKey(hkRun);
258  if (hkWin != NULL)
259  RegCloseKey(hkWin);
260 
261  TRACE("done\n");
262 
263  return res == ERROR_SUCCESS ? TRUE : FALSE;
264 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
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:1059
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
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:2867
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:3704
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:2368
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
GLuint res
Definition: glext.h:9613
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
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:394
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 336 of file startup.cpp.

337 {
338  /* TODO: ProcessRunKeys already checks SM_CLEANBOOT -- items prefixed with * should probably run even in safe mode */
339  BOOL bNormalBoot = GetSystemMetrics(SM_CLEANBOOT) == 0; /* Perform the operations that are performed every boot */
340  /* First, set the current directory to SystemRoot */
341  WCHAR gen_path[MAX_PATH];
342  DWORD res;
343 
344  res = GetWindowsDirectoryW(gen_path, _countof(gen_path));
345  if (res == 0)
346  {
347  TRACE("Couldn't get the windows directory - error %lu\n", GetLastError());
348 
349  return 100;
350  }
351 
352  if (!SetCurrentDirectoryW(gen_path))
353  {
354  TRACE("Cannot set the dir to %ls (%lu)\n", gen_path, GetLastError());
355 
356  return 100;
357  }
358 
359  /* Perform the operations by order checking if policy allows it, checking if this is not Safe Mode,
360  * stopping if one fails, skipping if necessary.
361  */
362  res = TRUE;
363  /* TODO: RunOnceEx */
364 
367 
368  if (res && bNormalBoot && (SHRestricted(REST_NOLOCALMACHINERUN) == 0))
370 
371  if (res && bNormalBoot && (SHRestricted(REST_NOCURRENTUSERRUNONCE) == 0))
373 
374  /* All users Startup folder */
376 
377  /* Current user Startup folder */
379 
380  /* TODO: HKCU\RunOnce runs even if StartupHasBeenRun exists */
381  if (res && bNormalBoot && (SHRestricted(REST_NOCURRENTUSERRUNONCE) == 0))
383 
384  TRACE("Operation done\n");
385 
386  return res ? 0 : 101;
387 }
#define TRUE
Definition: types.h:120
#define _countof(array)
Definition: fontsub.cpp:30
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define CSIDL_COMMON_STARTUP
Definition: shlobj.h:2026
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static BOOL ProcessRunKeys(HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete, BOOL bSynchronous)
Definition: startup.cpp:109
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
unsigned int BOOL
Definition: ntddk_ex.h:94
static BOOL AutoStartupApplications(INT nCSIDL_Folder)
Definition: startup.cpp:267
#define SM_CLEANBOOT
Definition: winuser.h:1017
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
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:2010
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  WCHAR szCmdLineExp[MAX_PATH+1] = L"\0";
66 
67  ExpandEnvironmentStringsW(cmdline, szCmdLineExp, _countof(szCmdLineExp));
68 
69  memset(&si, 0, sizeof(si));
70  si.cb = sizeof(si);
71  if (minimized)
72  {
75  }
76  memset(&info, 0, sizeof(info));
77 
78  if (!CreateProcessW(NULL, szCmdLineExp, NULL, NULL, FALSE, 0, NULL, dir, &si, &info))
79  {
80  TRACE("Failed to run command (%lu)\n", GetLastError());
81 
82  return INVALID_RUNCMD_RETURN;
83  }
84 
85  TRACE("Successfully ran command\n");
86 
87  if (wait)
88  { /* wait for the process to exit */
90  GetExitCodeProcess(info.hProcess, &exit_code);
91  }
92 
93  CloseHandle(info.hThread);
94  CloseHandle(info.hProcess);
95 
96  return exit_code;
97 }
#define CloseHandle
Definition: compat.h:398
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1198
#define _countof(array)
Definition: fontsub.cpp:30
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
TCHAR * cmdline
Definition: stretchblt.cpp:32
struct _test_info info[]
Definition: SetCursorPos.c:19
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
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:4623
static UINT exit_code
Definition: process.c:78
#define TRACE(s)
Definition: solgame.cpp:4
DWORD cb
Definition: winbase.h:817
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SW_MINIMIZE
Definition: winuser.h:770
static const WCHAR L[]
Definition: oid.c:1250
WORD wShowWindow
Definition: winbase.h:829
#define INVALID_RUNCMD_RETURN
Definition: startup.cpp:47
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
DWORD dwFlags
Definition: winbase.h:828
#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().