ReactOS  0.4.14-dev-317-g96040ec
runonce.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS runonce.exe
4  * FILE: base/system/runonce/runonce.c
5  * PROGRAMMER: Dmitry Chapyshev (dmitry@reactos.org)
6  */
7 
8 #include "runonce.h"
9 
10 static
11 DWORD
12 WINAPI
14 {
18  STARTUPINFOW si;
20 
21  for (Index = 0; Index < Count; Index++)
22  {
24 
25  ZeroMemory(&si, sizeof(si));
26  si.cb = sizeof(si);
28  si.wShowWindow = SW_SHOW;
29 
30  if (!CreateProcess(NULL, szData, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
31  continue;
32 
34 
35  CloseHandle(pi.hProcess);
36  CloseHandle(pi.hThread);
37  }
38 
40  _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce\\Setup"));
41 
42  PostMessage((HWND)lpDlg, WM_CLOSE, 0, 0);
43 
44  return 0;
45 }
46 
47 static
48 VOID
50 {
51  TCHAR szAppPath[MAX_PATH], szData[MAX_PATH];
52  DWORD dwIndex, dwSize, dwType, dwData, dwThreadId;
53  HKEY hKey;
54 
56  _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce\\Setup"),
57  0,
59  &hKey) == ERROR_SUCCESS)
60  {
61  for (dwIndex = 0; ; dwIndex++)
62  {
63  dwSize = sizeof(szAppPath);
64  dwData = sizeof(szData) / sizeof(TCHAR);
65 
66  if (RegEnumValue(hKey,
67  dwIndex,
68  szAppPath,
69  &dwSize,
70  NULL,
71  &dwType,
72  (LPBYTE)szData,
73  &dwData) == ERROR_SUCCESS)
74  {
75  if (dwType != REG_SZ) continue;
76 
78  }
79  }
80 
81  RegCloseKey(hKey);
82  }
83 
85  0,
87  (LPVOID)hDlg,
88  0,
89  &dwThreadId));
90 }
91 
92 static
93 INT_PTR
96 {
97  switch (Msg)
98  {
99  case WM_INITDIALOG:
100  InitDialog(hDlg);
101  break;
102 
103  case WM_CLOSE:
104  EndDialog(hDlg, 0);
105  break;
106  }
107 
108  return 0;
109 }
110 
111 INT
112 WINAPI
113 _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
114 {
115  LPCTSTR lpCmd = GetCommandLine();
116  TCHAR szAppPath[MAX_PATH], szData[MAX_PATH];
117  DWORD dwIndex, dwSize, dwType, dwData;
119  STARTUPINFOW si;
120  BOOL bRunApps = FALSE;
121  HKEY hKey;
122 
123  while (*lpCmd)
124  {
125  while (*lpCmd && *lpCmd != _T('/') && *lpCmd != _T('-')) lpCmd++;
126  if (!*lpCmd) break;
127  if (*++lpCmd == _T('r')) bRunApps = TRUE;
128  lpCmd++;
129  }
130 
131  if (bRunApps)
132  {
134  _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce"),
135  0,
137  &hKey) == ERROR_SUCCESS)
138  {
139  for (dwIndex = 0; ; dwIndex++)
140  {
141  dwSize = sizeof(szAppPath);
142  dwData = sizeof(szData) / sizeof(TCHAR);
143 
144  if (RegEnumValue(hKey,
145  dwIndex,
146  szAppPath,
147  &dwSize,
148  NULL,
149  &dwType,
150  (LPBYTE)szData,
151  &dwData) == ERROR_SUCCESS)
152  {
153  RegDeleteValue(hKey, szAppPath);
154 
155  if (dwType != REG_SZ) continue;
156 
157  ZeroMemory(&si, sizeof(si));
158  si.cb = sizeof(si);
160  si.wShowWindow = SW_SHOW;
161 
162  if (!CreateProcess(NULL, szData, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
163  continue;
164 
166 
167  CloseHandle(pi.hProcess);
168  CloseHandle(pi.hThread);
169  }
170  }
171 
172  RegCloseKey(hKey);
173  }
174 
175  return 1;
176  }
177 
179 
180  return 0;
181 }
DWORD WINAPI WaitForSingleObjectEx(IN HANDLE hHandle, IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:94
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define TRUE
Definition: types.h:120
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LB_ADDSTRING
Definition: winuser.h:2013
static const WCHAR szData[]
Definition: msipriv.h:1195
#define CALLBACK
Definition: compat.h:27
static HANDLE ULONG_PTR dwData
Definition: file.c:35
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define ZeroMemory
Definition: winbase.h:1642
UINT_PTR WPARAM
Definition: windef.h:207
int32_t INT_PTR
Definition: typedefs.h:62
int32_t INT
Definition: typedefs.h:56
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define DialogBox
Definition: winuser.h:5662
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
static INT_PTR CALLBACK RunOnceDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: runonce.c:95
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define IDD_RUNONCE_DLG
Definition: resource.h:5
#define GetCommandLine
Definition: winbase.h:3623
struct @1593 Msg[]
#define STARTF_USESHOWWINDOW
Definition: winbase.h:472
#define SW_SHOW
Definition: winuser.h:769
#define LB_GETCOUNT
Definition: winuser.h:2020
#define PostMessage
Definition: winuser.h:5733
char TCHAR
Definition: xmlstorage.h:189
#define RegDeleteValue
Definition: winreg.h:508
static DWORD WINAPI StartApplication(LPVOID lpDlg)
Definition: runonce.c:13
#define _T(x)
Definition: vfdio.h:22
#define IDC_COMP_LIST
Definition: resource.h:7
DWORD cb
Definition: winbase.h:824
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define WM_CLOSE
Definition: winuser.h:1603
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:8
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD pi
Definition: protocol.c:150
DWORD dwThreadId
Definition: fdebug.c:31
#define LB_GETTEXT
Definition: winuser.h:2031
WORD wShowWindow
Definition: winbase.h:836
INT WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow)
Definition: runonce.c:113
#define CreateProcess
Definition: winbase.h:3582
static VOID InitDialog(HWND hDlg)
Definition: runonce.c:49
HWND hList
Definition: livecd.c:10
#define RegOpenKeyEx
Definition: winreg.h:520
HINSTANCE hInst
Definition: dxdiag.c:13
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
unsigned int UINT
Definition: ndis.h:50
#define RegDeleteKey
Definition: winreg.h:502
#define SendMessage
Definition: winuser.h:5744
DWORD dwFlags
Definition: winbase.h:835
#define INFINITE
Definition: serial.h:102
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define RegEnumValue
Definition: winreg.h:511
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22