mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 13:03:55 +00:00
Try to read shell name from HKCU registry key.
If HKCU registry key or file not found, fall back to HKLM registry key If HKLM registry key or file not found, fall back to names "explorer.exe" and "cmd.exe" svn path=/trunk/; revision=25145
This commit is contained in:
parent
7f7148ea0c
commit
8a628a8eea
1 changed files with 49 additions and 39 deletions
|
@ -25,6 +25,7 @@
|
||||||
*/
|
*/
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <cfgmgr32.h>
|
#include <cfgmgr32.h>
|
||||||
|
#include <regstr.h>
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
|
@ -77,7 +78,7 @@ BOOL IsConsoleShell(void)
|
||||||
|
|
||||||
rc = RegOpenKeyEx(
|
rc = RegOpenKeyEx(
|
||||||
HKEY_LOCAL_MACHINE,
|
HKEY_LOCAL_MACHINE,
|
||||||
L"SYSTEM\\CurrentControlSet\\Control",
|
REGSTR_PATH_CURRENT_CONTROL_SET,
|
||||||
0,
|
0,
|
||||||
KEY_QUERY_VALUE,
|
KEY_QUERY_VALUE,
|
||||||
&ControlKey);
|
&ControlKey);
|
||||||
|
@ -109,7 +110,7 @@ cleanup:
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
BOOL GetShell(WCHAR *CommandLine)
|
BOOL GetShell(WCHAR *CommandLine, HKEY hRootKey)
|
||||||
{
|
{
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
DWORD Type, Size;
|
DWORD Type, Size;
|
||||||
|
@ -117,8 +118,8 @@ BOOL GetShell(WCHAR *CommandLine)
|
||||||
BOOL Ret = FALSE;
|
BOOL Ret = FALSE;
|
||||||
BOOL ConsoleShell = IsConsoleShell();
|
BOOL ConsoleShell = IsConsoleShell();
|
||||||
|
|
||||||
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
if(RegOpenKeyEx(hRootKey,
|
||||||
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
|
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", /* FIXME: should be REGSTR_PATH_WINLOGON */
|
||||||
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
|
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
Size = MAX_PATH * sizeof(WCHAR);
|
Size = MAX_PATH * sizeof(WCHAR);
|
||||||
|
@ -138,24 +139,6 @@ BOOL GetShell(WCHAR *CommandLine)
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Ret)
|
|
||||||
{
|
|
||||||
if (ConsoleShell)
|
|
||||||
{
|
|
||||||
if(GetSystemDirectory(CommandLine, MAX_PATH - 8))
|
|
||||||
wcscat(CommandLine, L"\\cmd.exe");
|
|
||||||
else
|
|
||||||
wcscpy(CommandLine, L"cmd.exe");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(GetWindowsDirectory(CommandLine, MAX_PATH - 13))
|
|
||||||
wcscat(CommandLine, L"\\explorer.exe");
|
|
||||||
else
|
|
||||||
wcscpy(CommandLine, L"explorer.exe");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,17 +183,12 @@ StartAutoApplications(int clsid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static BOOL
|
||||||
static
|
TryToStartShell(LPCWSTR Shell)
|
||||||
void StartShell(void)
|
|
||||||
{
|
{
|
||||||
STARTUPINFO si;
|
STARTUPINFO si;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
WCHAR Shell[MAX_PATH];
|
|
||||||
WCHAR ExpandedShell[MAX_PATH];
|
WCHAR ExpandedShell[MAX_PATH];
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
|
||||||
|
|
||||||
GetShell(Shell);
|
|
||||||
|
|
||||||
ZeroMemory(&si, sizeof(STARTUPINFO));
|
ZeroMemory(&si, sizeof(STARTUPINFO));
|
||||||
si.cb = sizeof(STARTUPINFO);
|
si.cb = sizeof(STARTUPINFO);
|
||||||
|
@ -218,7 +196,7 @@ void StartShell(void)
|
||||||
|
|
||||||
ExpandEnvironmentStrings(Shell, ExpandedShell, MAX_PATH);
|
ExpandEnvironmentStrings(Shell, ExpandedShell, MAX_PATH);
|
||||||
|
|
||||||
if(CreateProcess(NULL,
|
if(!CreateProcess(NULL,
|
||||||
ExpandedShell,
|
ExpandedShell,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -228,14 +206,46 @@ void StartShell(void)
|
||||||
NULL,
|
NULL,
|
||||||
&si,
|
&si,
|
||||||
&pi))
|
&pi))
|
||||||
{
|
return FALSE;
|
||||||
StartAutoApplications(CSIDL_STARTUP);
|
|
||||||
StartAutoApplications(CSIDL_COMMON_STARTUP);
|
StartAutoApplications(CSIDL_STARTUP);
|
||||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
StartAutoApplications(CSIDL_COMMON_STARTUP);
|
||||||
CloseHandle(pi.hProcess);
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hProcess);
|
||||||
}
|
CloseHandle(pi.hThread);
|
||||||
else
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void StartShell(void)
|
||||||
|
{
|
||||||
|
WCHAR Shell[MAX_PATH];
|
||||||
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
|
|
||||||
|
/* Try to run shell in user key */
|
||||||
|
if (GetShell(Shell, HKEY_CURRENT_USER) && TryToStartShell(Shell))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Try to run shell in local machine key */
|
||||||
|
if (GetShell(Shell, HKEY_LOCAL_MACHINE) && TryToStartShell(Shell))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Try default shell */
|
||||||
|
if (IsConsoleShell())
|
||||||
|
{
|
||||||
|
if(GetSystemDirectory(Shell, MAX_PATH - 8))
|
||||||
|
wcscat(Shell, L"\\cmd.exe");
|
||||||
|
else
|
||||||
|
wcscpy(Shell, L"cmd.exe");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(GetWindowsDirectory(Shell, MAX_PATH - 13))
|
||||||
|
wcscat(Shell, L"\\explorer.exe");
|
||||||
|
else
|
||||||
|
wcscpy(Shell, L"explorer.exe");
|
||||||
|
}
|
||||||
|
if (!TryToStartShell(Shell))
|
||||||
{
|
{
|
||||||
LoadString( GetModuleHandle(NULL), STRING_USERINIT_FAIL, szMsg, sizeof(szMsg) / sizeof(szMsg[0]));
|
LoadString( GetModuleHandle(NULL), STRING_USERINIT_FAIL, szMsg, sizeof(szMsg) / sizeof(szMsg[0]));
|
||||||
MessageBox(0, szMsg, NULL, 0);
|
MessageBox(0, szMsg, NULL, 0);
|
||||||
|
@ -250,7 +260,7 @@ void SetUserSettings(void)
|
||||||
WCHAR szWallpaper[MAX_PATH + 1];
|
WCHAR szWallpaper[MAX_PATH + 1];
|
||||||
|
|
||||||
if(RegOpenKeyEx(HKEY_CURRENT_USER,
|
if(RegOpenKeyEx(HKEY_CURRENT_USER,
|
||||||
L"Control Panel\\Desktop",
|
REGSTR_PATH_DESKTOP,
|
||||||
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
|
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
Size = sizeof(szWallpaper);
|
Size = sizeof(szWallpaper);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue