ReactOS 0.4.15-dev-8102-g108db8f
startup.c File Reference
#include <stdio.h>
#include <windows.h>
Include dependency graph for startup.c:

Go to the source code of this file.

Classes

struct  op_mask
 structure holding startup flags More...
 

Macros

#define INVALID_RUNCMD_RETURN   -1
 
#define DEFAULT   SESSION_START
 

Enumerations

enum  runkeys { RUNKEY_RUN , RUNKEY_RUNONCE , RUNKEY_RUNSERVICES , RUNKEY_RUNSERVICESONCE }
 

Functions

EXTERN_C HRESULT WINAPI SHCreateSessionKey (REGSAM samDesired, PHKEY phKey)
 
static BOOL wininit ()
 
static BOOL pendingRename ()
 
static int runCmd (LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
 
static BOOL ProcessRunKeys (HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete, BOOL bSynchronous)
 
int startup (int argc, const char *argv[])
 

Variables

const WCHAR runkeys_names [][30]
 
static const struct op_mask SESSION_START = {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE}
 
static const struct op_mask SETUP = {FALSE, FALSE, FALSE, TRUE, TRUE, TRUE}
 

Macro Definition Documentation

◆ DEFAULT

#define DEFAULT   SESSION_START

Definition at line 428 of file startup.c.

◆ INVALID_RUNCMD_RETURN

#define INVALID_RUNCMD_RETURN   -1

Definition at line 227 of file startup.c.

Enumeration Type Documentation

◆ runkeys

Enumerator
RUNKEY_RUN 
RUNKEY_RUNONCE 
RUNKEY_RUNSERVICES 
RUNKEY_RUNSERVICESONCE 

Definition at line 215 of file startup.c.

215 {
217};
@ RUNKEY_RUNSERVICES
Definition: startup.c:216
@ RUNKEY_RUN
Definition: startup.c:216
@ RUNKEY_RUNONCE
Definition: startup.c:216
@ RUNKEY_RUNSERVICESONCE
Definition: startup.c:216

Function Documentation

◆ pendingRename()

static BOOL pendingRename ( )
static

Definition at line 69 of file startup.c.

70{
71 static const WCHAR ValueName[] = {'P','e','n','d','i','n','g',
72 'F','i','l','e','R','e','n','a','m','e',
73 'O','p','e','r','a','t','i','o','n','s',0};
74 static const WCHAR SessionW[] = { 'S','y','s','t','e','m','\\',
75 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
76 'C','o','n','t','r','o','l','\\',
77 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
79 const WCHAR *src=NULL, *dst=NULL;
81 HKEY hSession=NULL;
82 DWORD res;
83
84 printf("Entered\n");
85
86 if ((res=RegOpenKeyExW(HKEY_LOCAL_MACHINE, SessionW, 0, KEY_ALL_ACCESS, &hSession))
88 {
90 {
91 printf("The key was not found - skipping\n");
92 res=TRUE;
93 }
94 else
95 {
96 printf("Couldn't open key, error %lu\n", res);
97 res=FALSE;
98 }
99
100 goto end;
101 }
102
103 res=RegQueryValueExW(hSession, ValueName, NULL, NULL /* The value type does not really interest us, as it is not
104 truely a REG_MULTI_SZ anyways */,
105 NULL, &dataLength);
107 {
108 /* No value - nothing to do. Great! */
109 printf("Value not present - nothing to rename\n");
110 res=TRUE;
111 goto end;
112 }
113
114 if (res!=ERROR_SUCCESS)
115 {
116 printf("Couldn't query value's length (%lu)\n", res);
117 res=FALSE;
118 goto end;
119 }
120
122 if (buffer==NULL)
123 {
124 printf("Couldn't allocate %lu bytes for the value\n", dataLength);
125 res=FALSE;
126 goto end;
127 }
128
130 if (res!=ERROR_SUCCESS)
131 {
132 printf("Couldn't query value after successfully querying before (%lu),\n"
133 "please report to wine-devel@winehq.org\n", res);
134 res=FALSE;
135 goto end;
136 }
137
138 /* Make sure that the data is long enough and ends with two NULLs. This
139 * simplifies the code later on.
140 */
141 if (dataLength<2*sizeof(buffer[0]) ||
142 buffer[dataLength/sizeof(buffer[0])-1]!='\0' ||
143 buffer[dataLength/sizeof(buffer[0])-2]!='\0')
144 {
145 printf("Improper value format - doesn't end with NULL\n");
146 res=FALSE;
147 goto end;
148 }
149
150 for(src=buffer; (src-buffer)*sizeof(src[0])<dataLength && *src!='\0';
151 src=dst+lstrlenW(dst)+1)
152 {
153 DWORD dwFlags=0;
154
155 printf("processing next command\n");
156
157 dst=src+lstrlenW(src)+1;
158
159 /* We need to skip the \??\ header */
160 if (src[0]=='\\' && src[1]=='?' && src[2]=='?' && src[3]=='\\')
161 src+=4;
162
163 if (dst[0]=='!')
164 {
166 dst++;
167 }
168
169 if (dst[0]=='\\' && dst[1]=='?' && dst[2]=='?' && dst[3]=='\\')
170 dst+=4;
171
172 if (*dst!='\0')
173 {
174 /* Rename the file */
176 } else
177 {
178 /* Delete the file or directory */
180 if (res != (DWORD)-1)
181 {
183 {
184 /* It's a file */
186 } else
187 {
188 /* It's a directory */
190 }
191 } else
192 {
193 printf("couldn't get file attributes (%ld)\n", GetLastError());
194 }
195 }
196 }
197
198 if ((res=RegDeleteValueW(hSession, ValueName))!=ERROR_SUCCESS)
199 {
200 printf("Error deleting the value (%lu)\n", GetLastError());
201 res=FALSE;
202 } else
203 res=TRUE;
204
205end:
206 if (buffer!=NULL)
207 free(buffer);
208
209 if (hSession!=NULL)
210 RegCloseKey(hSession);
211
212 return res;
213}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
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 RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
BOOL WINAPI MoveFileExW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName OPTIONAL, IN DWORD dwFlags)
Definition: move.c:1120
#define MOVEFILE_REPLACE_EXISTING
Definition: filesup.h:28
unsigned long DWORD
Definition: ntddk_ex.h:95
#define printf
Definition: freeldr.h:97
GLuint GLuint end
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
GLenum src
Definition: glext.h:6340
GLuint buffer
Definition: glext.h:5915
GLenum GLenum dst
Definition: glext.h:6340
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
ULONG dataLength
Definition: scsi.h:3751
unsigned char * LPBYTE
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by startup().

◆ 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 289 of file startup.c.

291{
292 static const WCHAR WINKEY_NAME[]={'S','o','f','t','w','a','r','e','\\',
293 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
294 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
295 HKEY hkWin=NULL, hkRun=NULL;
297 DWORD i, nMaxCmdLine=0, nMaxValue=0;
298 WCHAR *szCmdLine=NULL;
299 WCHAR *szValue=NULL;
300
301 if (hkRoot==HKEY_LOCAL_MACHINE)
302 wprintf(L"processing %s entries under HKLM\n", szKeyName);
303 else
304 wprintf(L"processing %s entries under HKCU\n", szKeyName);
305
306 if ((res=RegOpenKeyExW(hkRoot, WINKEY_NAME, 0, KEY_READ, &hkWin))!=ERROR_SUCCESS)
307 {
308 printf("RegOpenKey failed on Software\\Microsoft\\Windows\\CurrentVersion (%ld)\n",
309 res);
310
311 goto end;
312 }
313
314 if ((res=RegOpenKeyExW(hkWin, szKeyName, 0, bDelete?KEY_ALL_ACCESS:KEY_READ, &hkRun))!=
316 {
318 {
319 printf("Key doesn't exist - nothing to be done\n");
320
322 }
323 else
324 printf("RegOpenKey failed on run key (%ld)\n", res);
325
326 goto end;
327 }
328
329 if ((res=RegQueryInfoKeyW(hkRun, NULL, NULL, NULL, NULL, NULL, NULL, &i, &nMaxValue,
330 &nMaxCmdLine, NULL, NULL))!=ERROR_SUCCESS)
331 {
332 printf("Couldn't query key info (%ld)\n", res);
333
334 goto end;
335 }
336
337 if (i==0)
338 {
339 printf("No commands to execute.\n");
340
342 goto end;
343 }
344
345 if ((szCmdLine=malloc(nMaxCmdLine))==NULL)
346 {
347 printf("Couldn't allocate memory for the commands to be executed\n");
348
350 goto end;
351 }
352
353 if ((szValue=malloc((++nMaxValue)*sizeof(*szValue)))==NULL)
354 {
355 printf("Couldn't allocate memory for the value names\n");
356
357 free(szCmdLine);
359 goto end;
360 }
361
362 while(i>0)
363 {
364 DWORD nValLength=nMaxValue, nDataLength=nMaxCmdLine;
365 DWORD type;
366
367 --i;
368
369 if ((res=RegEnumValueW(hkRun, i, szValue, &nValLength, 0, &type,
370 (LPBYTE)szCmdLine, &nDataLength))!=ERROR_SUCCESS)
371 {
372 printf("Couldn't read in value %lu - %ld\n", i, res);
373
374 continue;
375 }
376
377 /* safe mode - force to run if prefixed with asterisk */
378 if (GetSystemMetrics(SM_CLEANBOOT) && (szValue[0] != L'*')) continue;
379
380 if (bDelete && (res=RegDeleteValueW(hkRun, szValue))!=ERROR_SUCCESS)
381 {
382 printf("Couldn't delete value - %lu, %ld. Running command anyways.\n", i, res);
383 }
384
385 if (type!=REG_SZ)
386 {
387 printf("Incorrect type of value #%lu (%lu)\n", i, type);
388
389 continue;
390 }
391
392 if ((res=runCmd(szCmdLine, NULL, bSynchronous, FALSE))==INVALID_RUNCMD_RETURN)
393 {
394 printf("Error running cmd #%lu (%ld)\n", i, GetLastError());
395 }
396
397 printf("Done processing cmd #%lu\n", i);
398 }
399
400 free(szValue);
401 free(szCmdLine);
403
404end:
405 if (hkRun!=NULL)
406 RegCloseKey(hkRun);
407 if (hkWin!=NULL)
408 RegCloseKey(hkWin);
409
410 printf("done\n");
411
412 return res==ERROR_SUCCESS?TRUE:FALSE;
413}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
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
GLuint GLuint GLsizei GLenum type
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
#define REG_SZ
Definition: layer.c:22
static int runCmd(LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
Definition: startup.c:240
#define INVALID_RUNCMD_RETURN
Definition: startup.c:227
#define KEY_READ
Definition: nt_native.h:1023
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define wprintf(...)
Definition: whoami.c:18
#define SM_CLEANBOOT
Definition: winuser.h:1027
int WINAPI GetSystemMetrics(_In_ int)

Referenced by startup().

◆ 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 240 of file startup.c.

241{
242 STARTUPINFOW si;
245 WCHAR szCmdLineExp[MAX_PATH+1]= L"\0";
246
247 ExpandEnvironmentStringsW(cmdline, szCmdLineExp, sizeof(szCmdLineExp) / sizeof(WCHAR));
248
249 memset(&si, 0, sizeof(si));
250 si.cb=sizeof(si);
251 if (minimized)
252 {
255 }
256 memset(&info, 0, sizeof(info));
257
258 if (!CreateProcessW(NULL, szCmdLineExp, NULL, NULL, FALSE, 0, NULL, dir, &si, &info))
259 {
260 printf("Failed to run command (%ld)\n", GetLastError());
261
263 }
264
265 printf("Successfully ran command\n"); //%s - Created process handle %p\n",
266 //wine_dbgstr_w(szCmdLineExp), info.hProcess);
267
268 if (wait)
269 { /* wait for the process to exit */
272 }
273
274 CloseHandle(info.hThread);
275 CloseHandle(info.hProcess);
276
277 return exit_code;
278}
unsigned int dir
Definition: maze.c:112
#define CloseHandle
Definition: compat.h:739
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
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
#define INFINITE
Definition: serial.h:102
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
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define STARTF_USESHOWWINDOW
Definition: winbase.h:491
#define SW_MINIMIZE
Definition: winuser.h:776

Referenced by ProcessRunKeys().

◆ SHCreateSessionKey()

EXTERN_C HRESULT WINAPI SHCreateSessionKey ( REGSAM  samDesired,
PHKEY  phKey 
)

Definition at line 147 of file shellreg.c.

148{
149 HRESULT hr = S_OK;
150 static WCHAR wszSessionKey[256];
151 LONG Error;
152
153 if (!wszSessionKey[0]) // FIXME: Critical Section
154 {
155 HANDLE hToken;
156
158 {
159 TOKEN_STATISTICS Stats;
161
162 if (GetTokenInformation(hToken, TokenStatistics, &Stats, sizeof(Stats), &ReturnLength))
163 {
164 swprintf(wszSessionKey,
165 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\SessionInfo\\%08x%08x",
167 }
168 else
170
171 CloseHandle(hToken);
172 }
173 else
175 }
176
177 if(SUCCEEDED(hr))
178 {
179 Error = RegCreateKeyExW(HKEY_LOCAL_MACHINE, wszSessionKey, 0, NULL,
180 REG_OPTION_VOLATILE, samDesired, NULL, phKey, NULL);
181 if (Error != ERROR_SUCCESS)
183 }
184
185 return hr;
186}
BOOL Error
Definition: chkdsk.c:66
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
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
Definition: security.c:411
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define GetCurrentProcess()
Definition: compat.h:759
#define swprintf
Definition: precomp.h:40
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
HRESULT hr
Definition: shlfolder.c:183
LONG HighPart
DWORD LowPart
LUID AuthenticationId
Definition: setypes.h:1087
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
@ TokenStatistics
Definition: setypes.h:975
#define TOKEN_READ
Definition: setypes.h:951

Referenced by startup().

◆ startup()

int startup ( int  argc,
const char argv[] 
)

Definition at line 430 of file startup.c.

431{
432 struct op_mask ops; /* Which of the ops do we want to perform? */
433 /* First, set the current directory to SystemRoot */
434 TCHAR gen_path[MAX_PATH];
435 DWORD res;
436 HKEY hSessionKey, hKey;
437 HRESULT hr;
438
439 res = GetWindowsDirectory(gen_path, sizeof(gen_path));
440
441 if (res==0)
442 {
443 printf("Couldn't get the windows directory - error %ld\n",
444 GetLastError());
445
446 return 100;
447 }
448
449 if (!SetCurrentDirectory(gen_path))
450 {
451 wprintf(L"Cannot set the dir to %s (%ld)\n", gen_path, GetLastError());
452
453 return 100;
454 }
455
456 hr = SHCreateSessionKey(KEY_WRITE, &hSessionKey);
457 if (SUCCEEDED(hr))
458 {
459 LONG Error;
460 DWORD dwDisp;
461
462 Error = RegCreateKeyEx(hSessionKey, L"StartupHasBeenRun", 0, NULL, REG_OPTION_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
463 RegCloseKey(hSessionKey);
464 if (Error == ERROR_SUCCESS)
465 {
467 if (dwDisp == REG_OPENED_EXISTING_KEY)
468 {
469 /* Startup programs has already been run */
470 return 0;
471 }
472 }
473 }
474
475 if (argc > 1)
476 {
477 switch(argv[1][0])
478 {
479 case 'r': /* Restart */
480 ops = SETUP;
481 break;
482 case 's': /* Full start */
483 ops = SESSION_START;
484 break;
485 default:
486 ops = DEFAULT;
487 break;
488 }
489 } else
490 ops = DEFAULT;
491
492 /* do not run certain items in Safe Mode */
493 if(GetSystemMetrics(SM_CLEANBOOT)) ops.startup = FALSE;
494
495 /* Perform the ops by order, stopping if one fails, skipping if necessary */
496 /* Shachar: Sorry for the perl syntax */
497 res = TRUE;
498 if (res && !ops.ntonly && ops.preboot)
499 res = wininit();
500 if (res && !ops.w9xonly && ops.preboot)
501 res = pendingRename();
502 if (res && !ops.ntonly && ops.prelogin)
504 if (res && !ops.ntonly && ops.prelogin && ops.startup)
506 if (res && ops.postlogin)
508 if (res && ops.postlogin && ops.startup)
510 if (res && ops.postlogin && ops.startup)
512 if (res && ops.postlogin && ops.startup)
514
515 printf("Operation done\n");
516
517 return res ? 0 : 101;
518}
static int argc
Definition: ServiceArgs.c:12
FxAutoRegKey hKey
static BOOL ProcessRunKeys(HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete, BOOL bSynchronous)
Definition: startup.c:289
const WCHAR runkeys_names[][30]
Definition: startup.c:219
EXTERN_C HRESULT WINAPI SHCreateSessionKey(REGSAM samDesired, PHKEY phKey)
Definition: shellreg.c:147
#define DEFAULT
Definition: startup.c:428
static const struct op_mask SESSION_START
Definition: startup.c:426
static const struct op_mask SETUP
Definition: startup.c:427
static BOOL pendingRename()
Definition: startup.c:69
static BOOL wininit()
Definition: startup.c:64
#define argv
Definition: mplay32.c:18
#define KEY_WRITE
Definition: nt_native.h:1031
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
structure holding startup flags
Definition: startup.c:416
#define GetWindowsDirectory
Definition: winbase.h:3857
#define SetCurrentDirectory
Definition: winbase.h:3903
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegCreateKeyEx
Definition: winreg.h:501
char TCHAR
Definition: xmlstorage.h:189

◆ wininit()

static BOOL wininit ( )
static

Performs the rename operations dictated in SystemRoot%\Wininit.ini. Returns FALSE if there was an error, or otherwise if all is ok.

Definition at line 64 of file startup.c.

65{
66 return TRUE;
67}

Referenced by startup().

Variable Documentation

◆ runkeys_names

const WCHAR runkeys_names[][30]
Initial value:
=
{
{'R','u','n',0},
{'R','u','n','O','n','c','e',0},
{'R','u','n','S','e','r','v','i','c','e','s',0},
{'R','u','n','S','e','r','v','i','c','e','s','O','n','c','e',0}
}

Definition at line 219 of file startup.c.

Referenced by startup().

◆ SESSION_START

const struct op_mask SESSION_START = {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE}
static

Definition at line 426 of file startup.c.

Referenced by startup().

◆ SETUP

const struct op_mask SETUP = {FALSE, FALSE, FALSE, TRUE, TRUE, TRUE}
static

Definition at line 427 of file startup.c.

Referenced by startup().