ReactOS 0.4.16-dev-91-g764881a
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
10static
14{
18 STARTUPINFOW si;
19 TCHAR szData[MAX_PATH];
20
21 for (Index = 0; Index < Count; Index++)
22 {
24
25 ZeroMemory(&si, sizeof(si));
26 si.cb = sizeof(si);
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
47static
48VOID
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,
60 {
61 for (dwIndex = 0; ; dwIndex++)
62 {
63 dwSize = sizeof(szAppPath);
64 dwData = sizeof(szData) / sizeof(TCHAR);
65
67 dwIndex,
68 szAppPath,
69 &dwSize,
70 NULL,
71 &dwType,
72 (LPBYTE)szData,
74 {
75 if (dwType != REG_SZ) continue;
76
78 }
79 }
80
82 }
83
85 0,
87 (LPVOID)hDlg,
88 0,
89 &dwThreadId));
90}
91
92static
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
111INT
112WINAPI
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,
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
173 }
174
175 return 1;
176 }
177
179
180 return 0;
181}
#define IDC_COMP_LIST
Definition: resource.h:7
#define IDD_RUNONCE_DLG
Definition: resource.h:5
static VOID InitDialog(HWND hDlg)
Definition: runonce.c:49
static DWORD WINAPI StartApplication(LPVOID lpDlg)
Definition: runonce.c:13
static INT_PTR CALLBACK RunOnceDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: runonce.c:95
#define RegCloseKey(hKey)
Definition: registry.h:49
struct @1636 Msg[]
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#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
#define CloseHandle
Definition: compat.h:739
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
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:137
#define INFINITE
Definition: serial.h:102
HINSTANCE hInst
Definition: dxdiag.c:13
DWORD dwThreadId
Definition: fdebug.c:31
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define _tWinMain
Definition: tchar.h:498
#define REG_SZ
Definition: layer.c:22
HWND hList
Definition: livecd.c:10
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static HANDLE ULONG_PTR dwData
Definition: file.c:35
static refpint_t pi[]
Definition: server.c:96
unsigned int UINT
Definition: ndis.h:50
int Count
Definition: noreturn.cpp:7
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
DWORD cb
Definition: winbase.h:852
DWORD dwFlags
Definition: winbase.h:863
WORD wShowWindow
Definition: winbase.h:864
DWORD WINAPI WaitForSingleObjectEx(IN HANDLE hHandle, IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:94
int32_t INT_PTR
Definition: typedefs.h:64
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
_In_ WDFCOLLECTION _In_ ULONG Index
#define CreateProcess
Definition: winbase.h:3758
#define ZeroMemory
Definition: winbase.h:1712
#define STARTF_USESHOWWINDOW
Definition: winbase.h:491
#define GetCommandLine
Definition: winbase.h:3799
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegDeleteKey
Definition: winreg.h:502
#define RegEnumValue
Definition: winreg.h:511
#define RegDeleteValue
Definition: winreg.h:508
#define LB_GETCOUNT
Definition: winuser.h:2041
#define WM_CLOSE
Definition: winuser.h:1624
#define LB_GETTEXT
Definition: winuser.h:2052
#define WM_INITDIALOG
Definition: winuser.h:1742
#define LB_ADDSTRING
Definition: winuser.h:2034
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define SendMessage
Definition: winuser.h:5855
#define PostMessage
Definition: winuser.h:5844
#define SW_SHOW
Definition: winuser.h:778
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define DialogBox
Definition: winuser.h:5773
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
char TCHAR
Definition: xmlstorage.h:189
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192