Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 2000.
  5. //
  6. // File: cpl.cpp
  7. //
  8. // Contents: Control Panel entry point (CPlApplet)
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include <regstr.h> // REGSTR_PATH_POLICIES
  13. #include <lm.h> // NetGetJoinInformation
  14. #include <cpl.h>
  15. #include "resource.h"
  16. const struct
  17. {
  18. LPCTSTR pszApp;
  19. LPCTSTR pszCommand;
  20. }
  21. s_rgCommands[] =
  22. {
  23. { TEXT("%SystemRoot%\\system32\\rundll32.exe"), TEXT("rundll32.exe \"%SystemRoot%\\system32\\netplwiz.dll\",UsersRunDll") },
  24. { TEXT("%SystemRoot%\\system32\\mshta.exe"), TEXT("mshta.exe \"res://%SystemRoot%\\system32\\nusrmgr.cpl/nusrmgr.hta\"") },
  25. };
  26. TCHAR const c_szPolicyKey[] = REGSTR_PATH_POLICIES TEXT("\\Explorer");
  27. TCHAR const c_szPolicyVal[] = TEXT("UserPasswordsVer");
  28. HRESULT StartUserManager(LPCTSTR pszParams)
  29. {
  30. TCHAR szApp[MAX_PATH];
  31. TCHAR szCommand[MAX_PATH];
  32. int iCommandIndex;
  33. STARTUPINFO rgStartup = {0};
  34. PROCESS_INFORMATION rgProcess = {0};
  35. // Default is to use the old UI
  36. iCommandIndex = 0;
  37. #ifndef _WIN64
  38. if (IsOS(OS_PERSONAL) || (IsOS(OS_PROFESSIONAL) && !IsOS(OS_DOMAINMEMBER)))
  39. {
  40. // Switch to the friendly UI.
  41. iCommandIndex = 1;
  42. }
  43. #endif
  44. DWORD cch = ExpandEnvironmentStrings(s_rgCommands[iCommandIndex].pszApp, szApp, ARRAYSIZE(szApp));
  45. if (cch == 0 || cch > ARRAYSIZE(szApp))
  46. {
  47. return E_FAIL;
  48. }
  49. cch = ExpandEnvironmentStrings(s_rgCommands[iCommandIndex].pszCommand, szCommand, ARRAYSIZE(szCommand));
  50. if (cch == 0 || cch > ARRAYSIZE(szCommand))
  51. {
  52. return E_FAIL;
  53. }
  54. if (pszParams && *pszParams != TEXT('\0'))
  55. {
  56. // ExpandEnvironmentStrings counts the last '\0'
  57. // (we checked cch == 0 above)
  58. cch--;
  59. // Is there room for the params?
  60. if (cch + sizeof(' ') + lstrlen(pszParams) < ARRAYSIZE(szCommand))
  61. {
  62. szCommand[cch++] = TEXT(' ');
  63. lstrcpyn(&szCommand[cch], pszParams, ARRAYSIZE(szCommand)-cch);
  64. }
  65. // else launch without extra parameters
  66. }
  67. rgStartup.cb = sizeof(rgStartup);
  68. rgStartup.wShowWindow = SW_SHOWNORMAL;
  69. if (CreateProcess(szApp,
  70. szCommand,
  71. NULL,
  72. NULL,
  73. FALSE,
  74. 0,
  75. NULL,
  76. NULL,
  77. &rgStartup,
  78. &rgProcess))
  79. {
  80. WaitForInputIdle(rgProcess.hProcess, 10000);
  81. CloseHandle(rgProcess.hProcess);
  82. CloseHandle(rgProcess.hThread);
  83. return S_OK;
  84. }
  85. return E_FAIL;
  86. }
  87. LONG APIENTRY CPlApplet(HWND hwnd, UINT Msg, LPARAM lParam1, LPARAM lParam2)
  88. {
  89. LPCPLINFO lpCplInfo;
  90. switch (Msg)
  91. {
  92. case CPL_INIT:
  93. return TRUE;
  94. case CPL_GETCOUNT:
  95. return 1;
  96. case CPL_INQUIRE:
  97. lpCplInfo = (LPCPLINFO)lParam2;
  98. lpCplInfo->idIcon = IDI_CPLICON;
  99. lpCplInfo->idName = IDS_NAME;
  100. lpCplInfo->idInfo = IDS_INFO;
  101. lpCplInfo->lData = 0;
  102. break;
  103. case CPL_DBLCLK:
  104. StartUserManager(NULL);
  105. return TRUE;
  106. case CPL_STARTWPARMS:
  107. StartUserManager((LPCTSTR)lParam2);
  108. return TRUE;
  109. }
  110. return 0;
  111. }