d008cae4abdff35ac8b59675b576c0a94081f0bc
2 * PROJECT: ReactOS System Control Panel
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: ReactOS System Control Panel
5 * COPYRIGHT: Copyright 2004 Gero Kuehn (reactos.filter@gkware.com)
6 * Copyright 2008 Colin Finck (colin@reactos.org)
7 * Copyright 2014 Hermès Bélusca-Maïto (hermes.belusca-maito@reactos.org)
12 #define WIN32_NO_STATUS
23 #define MAX_VALUE_NAME 16383
26 * Macro for calling "rundll32.exe"
27 * According to MSDN, ShellExecute returns a value greater than 32
28 * if the operation was successful.
30 #define RUNDLL(param) \
31 ((INT_PTR)ShellExecuteW(NULL, L"open", L"rundll32.exe", (param), NULL, SW_SHOWDEFAULT) > 32)
35 Control_RunDLLW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR cmd
, DWORD nCmdShow
);
38 OpenShellFolder(LPWSTR lpFolderCLSID
)
40 WCHAR szParameters
[MAX_PATH
];
43 * Open a shell folder using "explorer.exe". The passed CLSIDs
44 * are all subfolders of the "Control Panel" shell folder.
46 StringCbCopy(szParameters
, sizeof(szParameters
), L
"/n,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}");
47 StringCbCat(szParameters
,sizeof(szParameters
), lpFolderCLSID
);
49 return (INT_PTR
)ShellExecuteW(NULL
,
58 RunControlPanel(LPCWSTR lpCmd
)
63 WCHAR szParameters[MAX_PATH];
64 wcscpy(szParameters, L"shell32.dll,Control_RunDLL ");
65 wcscat(szParameters, lpCmd);
66 return RUNDLL(szParameters);
70 Control_RunDLLW(GetDesktopWindow(), 0, lpCmd
, SW_SHOW
);
76 wWinMain(HINSTANCE hInstance
,
77 HINSTANCE hPrevInstance
,
83 /* Show the control panel window if no argument or "panel" was passed */
84 if (*lpCmdLine
== 0 || !_wcsicmp(lpCmdLine
, L
"panel"))
85 return OpenShellFolder(L
"");
87 /* Check one of the built-in control panel handlers */
88 if (!_wcsicmp(lpCmdLine
, L
"admintools")) return OpenShellFolder(L
"\\::{D20EA4E1-3957-11d2-A40B-0C5020524153}");
89 else if (!_wcsicmp(lpCmdLine
, L
"color")) return RunControlPanel(L
"desk.cpl"); /* TODO: Switch to the "Apperance" tab */
90 else if (!_wcsicmp(lpCmdLine
, L
"date/time")) return RunControlPanel(L
"timedate.cpl");
91 else if (!_wcsicmp(lpCmdLine
, L
"desktop")) return RunControlPanel(L
"desk.cpl");
92 else if (!_wcsicmp(lpCmdLine
, L
"folders")) return RUNDLL(L
"shell32.dll,Options_RunDLL");
93 else if (!_wcsicmp(lpCmdLine
, L
"fonts")) return OpenShellFolder(L
"\\::{D20EA4E1-3957-11d2-A40B-0C5020524152}");
94 else if (!_wcsicmp(lpCmdLine
, L
"infrared")) return RunControlPanel(L
"irprops.cpl");
95 else if (!_wcsicmp(lpCmdLine
, L
"international")) return RunControlPanel(L
"intl.cpl");
96 else if (!_wcsicmp(lpCmdLine
, L
"keyboard")) return RunControlPanel(L
"main.cpl @1");
97 else if (!_wcsicmp(lpCmdLine
, L
"mouse")) return RunControlPanel(L
"main.cpl @0");
98 else if (!_wcsicmp(lpCmdLine
, L
"netconnections")) return OpenShellFolder(L
"\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}");
99 else if (!_wcsicmp(lpCmdLine
, L
"netware")) return RunControlPanel(L
"nwc.cpl");
100 else if (!_wcsicmp(lpCmdLine
, L
"ports")) return RunControlPanel(L
"sysdm.cpl"); /* TODO: Switch to the "Computer Name" tab */
101 else if (!_wcsicmp(lpCmdLine
, L
"printers")) return OpenShellFolder(L
"\\::{2227A280-3AEA-1069-A2DE-08002B30309D}");
102 else if (!_wcsicmp(lpCmdLine
, L
"scannercamera")) return OpenShellFolder(L
"\\::{E211B736-43FD-11D1-9EFB-0000F8757FCD}");
103 else if (!_wcsicmp(lpCmdLine
, L
"schedtasks")) return OpenShellFolder(L
"\\::{D6277990-4C6A-11CF-8D87-00AA0060F5BF}");
104 else if (!_wcsicmp(lpCmdLine
, L
"telephony")) return RunControlPanel(L
"telephon.cpl");
105 else if (!_wcsicmp(lpCmdLine
, L
"userpasswords")) return RunControlPanel(L
"nusrmgr.cpl"); /* Graphical User Account Manager */
106 else if (!_wcsicmp(lpCmdLine
, L
"userpasswords2")) return RUNDLL(L
"netplwiz.dll,UsersRunDll"); /* Dialog based advanced User Account Manager */
108 /* It is none of them, so look for a handler in the registry */
109 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
110 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls",
113 &hKey
) == ERROR_SUCCESS
)
117 for (dwIndex
= 0; ; ++dwIndex
)
120 DWORD dwValueSize
= MAX_VALUE_NAME
;
121 WCHAR szValueName
[MAX_VALUE_NAME
];
123 /* Get the value name and data size */
124 if (RegEnumValueW(hKey
,
131 &dwDataSize
) != ERROR_SUCCESS
)
136 /* Check if the parameter is the value name */
137 if (!_wcsicmp(lpCmdLine
, szValueName
))
140 * Allocate memory for the data plus two more characters,
141 * so we can quote the file name if required.
144 pszData
= HeapAlloc(GetProcessHeap(),
146 dwDataSize
+ 2 * sizeof(WCHAR
));
150 * This value is the one we are looking for, so get the data.
151 * It is the path to a .cpl file.
153 if (RegQueryValueExW(hKey
,
158 &dwDataSize
) == ERROR_SUCCESS
)
162 /* Quote the file name if required */
163 if (*pszData
!= L
'\"')
165 *(--pszData
) = L
'\"';
166 pszData
[dwDataSize
/ sizeof(WCHAR
)] = L
'\"';
167 pszData
[(dwDataSize
/ sizeof(WCHAR
)) + 1] = 0;
170 nReturnValue
= RunControlPanel(pszData
);
171 HeapFree(GetProcessHeap(), 0, pszData
);
177 HeapFree(GetProcessHeap(), 0, pszData
);
185 * It's none of the known parameters, so interpret the parameter
186 * as the file name of a control panel applet.
188 return RunControlPanel(lpCmdLine
);