Source code of Windows XP (NT5)
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.

349 lines
9.7 KiB

  1. #include <windows.h>
  2. #include <userenv.h>
  3. #include <userenvp.h>
  4. #include <shlwapi.h>
  5. #include "shmgdefs.h"
  6. EXTERN_C void UpgradeDesktopWallpaper(void);
  7. enum {
  8. CMD_W95_TO_SUR,
  9. CMD_DAYTONA_CURSORS,
  10. CMD_FIX_CURSOR_PATHS,
  11. CMD_FIX_SPECIAL_FOLDERS,
  12. CMD_FIX_WINDOWS_PROFILE_SECURITY,
  13. CMD_FIX_USER_PROFILE_SECURITY,
  14. CMD_FIX_POLICIES_SECURITY,
  15. CMD_CVT_SCHEMES_TO_MULTIUSER,
  16. CMD_UPGRADE_NT4_PROFILE_TO_NT5,
  17. CMD_UPGRADE_SCHEMES_AND_NCMETRICS_TO_WIN2000,
  18. CMD_UPGRADE_SCHEMES_AND_NCMETRICS_FROM_WIN9X_TO_WIN2000,
  19. CMD_FIX_CAPI_DIR_ATTRIBUTES,
  20. CMD_MERGE_DESKTOP_AND_NORMAL_STREAMS,
  21. CMD_MOVE_AND_ADJUST_ICON_METRICS,
  22. CMD_FIX_HTML_HELP,
  23. CMD_SET_SCREENSAVER_FRIENDLYUI,
  24. CMD_ADD_CONFIGURE_PROGRAMS,
  25. CMD_OCINSTALL_FIXUP,
  26. // enums from here down will run within OleInitialize/OleUnitialize
  27. CMD_OLE_REQUIRED_START = 10000,
  28. CMD_OCINSTALL_SHOW_IE,
  29. CMD_OCINSTALL_REINSTALL_IE,
  30. CMD_OCINSTALL_HIDE_IE,
  31. CMD_OCINSTALL_USER_CONFIG_IE,
  32. CMD_OCINSTALL_SHOW_OE,
  33. CMD_OCINSTALL_REINSTALL_OE,
  34. CMD_OCINSTALL_HIDE_OE,
  35. CMD_OCINSTALL_USER_CONFIG_OE,
  36. CMD_OCINSTALL_SHOW_VM,
  37. CMD_OCINSTALL_REINSTALL_VM,
  38. CMD_OCINSTALL_HIDE_VM,
  39. CMD_OCINSTALL_UPDATE,
  40. CMD_OCINSTALL_CLEANUP_INITIALLY_CLEAR,
  41. } CMD_VALS;
  42. int mystrcpy( LPTSTR pszOut, LPTSTR pszIn, TCHAR chTerm ) {
  43. BOOL fInQuote = FALSE;
  44. LPTSTR pszStrt = pszOut;
  45. while( *pszIn && !fInQuote && *pszIn != chTerm ) {
  46. if (*pszIn == TEXT('"')) {
  47. fInQuote = !fInQuote;
  48. }
  49. *pszOut++ = *pszIn++;
  50. }
  51. *pszOut = TEXT('\0');
  52. return (int)(pszOut - pszStrt);
  53. }
  54. BOOL HasPath( LPTSTR pszFilename ) {
  55. //
  56. // Special case null string so it won't get changed
  57. //
  58. if (*pszFilename == TEXT('\0'))
  59. return TRUE;
  60. for(; *pszFilename; pszFilename++ ) {
  61. if (*pszFilename == TEXT(':') || *pszFilename == TEXT('\\') || *pszFilename == TEXT('/')) {
  62. return TRUE;
  63. }
  64. }
  65. return FALSE;
  66. }
  67. void HandOffToShell32 (LPCSTR pcszCommand, LPCSTR pcszOptionalArgument)
  68. {
  69. TCHAR szShell32Path[MAX_PATH];
  70. if (GetSystemDirectory(szShell32Path, ARRAYSIZE(szShell32Path)) != 0)
  71. {
  72. HINSTANCE hInstShell32;
  73. PathAppend(szShell32Path, TEXT("shell32.dll"));
  74. hInstShell32 = LoadLibrary(szShell32Path);
  75. if (hInstShell32 != NULL)
  76. {
  77. typedef HRESULT (*PFNFirstUserLogon) (LPCSTR pcszCommand, LPCSTR pcszOptionalArgument);
  78. PFNFirstUserLogon pfnFirstUserLogon;
  79. // Call shell32!FirstUserLogon which is Ordinal230 defined in shell32.src.
  80. pfnFirstUserLogon = (PFNFirstUserLogon)GetProcAddress(hInstShell32, (LPCSTR)MAKEINTRESOURCE(230));
  81. if (pfnFirstUserLogon != NULL)
  82. pfnFirstUserLogon(pcszCommand, pcszOptionalArgument);
  83. FreeLibrary(hInstShell32);
  84. }
  85. }
  86. }
  87. /*
  88. * Command Parser
  89. */
  90. typedef struct {
  91. LPSTR pszCmd;
  92. int idCmd;
  93. } CMD;
  94. CMD aCmds[] = {
  95. { "W", CMD_W95_TO_SUR },
  96. { "Cvt-Curs", CMD_DAYTONA_CURSORS },
  97. { "Fix-Curs", CMD_FIX_CURSOR_PATHS },
  98. { "Fix-Folders", CMD_FIX_SPECIAL_FOLDERS},
  99. { "Fix-Win-Security", CMD_FIX_WINDOWS_PROFILE_SECURITY},
  100. { "Fix-User-Security", CMD_FIX_USER_PROFILE_SECURITY},
  101. { "Fix-Policies-Security", CMD_FIX_POLICIES_SECURITY},
  102. { "Cvt-Mouse-Schemes", CMD_CVT_SCHEMES_TO_MULTIUSER},
  103. { "UpgradeProfileNT4ToNT5", CMD_UPGRADE_NT4_PROFILE_TO_NT5},
  104. { "UpgradeSchemesAndNcMetricsToWin2000", CMD_UPGRADE_SCHEMES_AND_NCMETRICS_TO_WIN2000},
  105. { "UpgradeSchemesAndNcMetricsFromWin9xToWin2000", CMD_UPGRADE_SCHEMES_AND_NCMETRICS_FROM_WIN9X_TO_WIN2000},
  106. { "FixCAPIDirAttrib", CMD_FIX_CAPI_DIR_ATTRIBUTES},
  107. { "MergeDesktopAndNormalStreams", CMD_MERGE_DESKTOP_AND_NORMAL_STREAMS },
  108. { "MoveAndAdjustIconMetrics", CMD_MOVE_AND_ADJUST_ICON_METRICS },
  109. { "Fix-HTML-Help", CMD_FIX_HTML_HELP },
  110. { "Set-Screensaver-On-FriendlyUI", CMD_SET_SCREENSAVER_FRIENDLYUI },
  111. { "AddConfigurePrograms", CMD_ADD_CONFIGURE_PROGRAMS },
  112. { "OCInstallShowIE", CMD_OCINSTALL_SHOW_IE },
  113. { "OCInstallReinstallIE", CMD_OCINSTALL_REINSTALL_IE },
  114. { "OCInstallHideIE", CMD_OCINSTALL_HIDE_IE },
  115. { "OCInstallUserConfigIE", CMD_OCINSTALL_USER_CONFIG_IE },
  116. { "OCInstallShowOE", CMD_OCINSTALL_SHOW_OE },
  117. { "OCInstallReinstallOE", CMD_OCINSTALL_REINSTALL_OE },
  118. { "OCInstallHideOE", CMD_OCINSTALL_HIDE_OE },
  119. { "OCInstallUserConfigOE", CMD_OCINSTALL_USER_CONFIG_OE },
  120. // { "OCInstallShowVM", CMD_OCINSTALL_SHOW_VM },
  121. { "OCInstallReinstallVM", CMD_OCINSTALL_REINSTALL_VM },
  122. // { "OCInstallHideVM", CMD_OCINSTALL_HIDE_VM },
  123. { "OCInstallFixup", CMD_OCINSTALL_FIXUP },
  124. { "OCInstallUpdate", CMD_OCINSTALL_UPDATE },
  125. { "OCInstallCleanupInitiallyClear", CMD_OCINSTALL_CLEANUP_INITIALLY_CLEAR },
  126. };
  127. #define C_CMDS ARRAYSIZE(aCmds)
  128. void __cdecl main( int cArgs, char **szArg) {
  129. int i;
  130. HRESULT hrOle = E_FAIL;
  131. SHMGLogErrMsg("main called with args", (DWORD)cArgs);
  132. if (cArgs < 2 || cArgs > 3)
  133. ExitProcess(1);
  134. #ifdef SHMG_DBG
  135. for(i=1; i<cArgs; i++)
  136. SHMGLogErrMsg(szArg[i], (DWORD)i);
  137. #endif
  138. for( i = 0; i < C_CMDS && lstrcmpA( szArg[1], aCmds[i].pszCmd ) != 0; i++ );
  139. if (i >= C_CMDS)
  140. ExitProcess(1);
  141. if (aCmds[i].idCmd >= CMD_OLE_REQUIRED_START)
  142. {
  143. hrOle = OleInitialize(NULL);
  144. if (FAILED(hrOle))
  145. {
  146. ExitProcess(1);
  147. }
  148. }
  149. switch( aCmds[i].idCmd ) {
  150. case CMD_W95_TO_SUR:
  151. CvtDeskCPL_Win95ToSUR();
  152. break;
  153. case CMD_DAYTONA_CURSORS:
  154. CvtCursorsCPL_DaytonaToSUR();
  155. break;
  156. case CMD_FIX_CURSOR_PATHS:
  157. FixupCursorSchemePaths();
  158. break;
  159. case CMD_FIX_SPECIAL_FOLDERS:
  160. ResetUserSpecialFolderPaths();
  161. break;
  162. case CMD_FIX_WINDOWS_PROFILE_SECURITY:
  163. FixWindowsProfileSecurity();
  164. break;
  165. case CMD_FIX_USER_PROFILE_SECURITY:
  166. FixUserProfileSecurity();
  167. break;
  168. case CMD_FIX_POLICIES_SECURITY:
  169. FixPoliciesSecurity();
  170. break;
  171. case CMD_CVT_SCHEMES_TO_MULTIUSER:
  172. CvtCursorSchemesToMultiuser();
  173. break;
  174. case CMD_UPGRADE_NT4_PROFILE_TO_NT5:
  175. MigrateNT4ToNT5();
  176. break;
  177. case CMD_UPGRADE_SCHEMES_AND_NCMETRICS_TO_WIN2000:
  178. UpgradeSchemesAndNcMetricsToWin2000();
  179. break;
  180. case CMD_UPGRADE_SCHEMES_AND_NCMETRICS_FROM_WIN9X_TO_WIN2000:
  181. UpgradeSchemesAndNcMetricsFromWin9xToWin2000(cArgs > 2 ? szArg[2] : NULL);
  182. break;
  183. case CMD_FIX_CAPI_DIR_ATTRIBUTES:
  184. SetSystemBitOnCAPIDir();
  185. break;
  186. case CMD_MERGE_DESKTOP_AND_NORMAL_STREAMS:
  187. case CMD_MOVE_AND_ADJUST_ICON_METRICS:
  188. HandOffToShell32(szArg[1], cArgs > 2 ? szArg[2] : NULL);
  189. break;
  190. case CMD_FIX_HTML_HELP:
  191. FixHtmlHelp();
  192. break;
  193. case CMD_SET_SCREENSAVER_FRIENDLYUI:
  194. SetScreensaverOnFriendlyUI();
  195. break;
  196. case CMD_ADD_CONFIGURE_PROGRAMS:
  197. AddConfigurePrograms();
  198. break;
  199. case CMD_OCINSTALL_FIXUP:
  200. FixupOptionalComponents();
  201. break;
  202. case CMD_OCINSTALL_UPDATE:
  203. OCInstallUpdate();
  204. break;
  205. case CMD_OCINSTALL_CLEANUP_INITIALLY_CLEAR:
  206. OCInstallCleanupInitiallyClear();
  207. break;
  208. case CMD_OCINSTALL_SHOW_IE:
  209. ShowHideIE(TRUE, FALSE, TRUE);
  210. break;
  211. case CMD_OCINSTALL_REINSTALL_IE:
  212. ShowHideIE(TRUE, TRUE, TRUE);
  213. break;
  214. case CMD_OCINSTALL_HIDE_IE:
  215. ShowHideIE(FALSE, FALSE, TRUE);
  216. break;
  217. case CMD_OCINSTALL_USER_CONFIG_IE:
  218. UserConfigIE();
  219. break;
  220. case CMD_OCINSTALL_SHOW_OE:
  221. ShowHideOE(TRUE, FALSE, TRUE);
  222. break;
  223. case CMD_OCINSTALL_REINSTALL_OE:
  224. ShowHideOE(TRUE, TRUE, TRUE);
  225. break;
  226. case CMD_OCINSTALL_HIDE_OE:
  227. ShowHideOE(FALSE, FALSE, TRUE);
  228. break;
  229. case CMD_OCINSTALL_USER_CONFIG_OE:
  230. UserConfigOE();
  231. break;
  232. case CMD_OCINSTALL_SHOW_VM:
  233. // Do nothing...
  234. break;
  235. case CMD_OCINSTALL_REINSTALL_VM:
  236. ReinstallVM();
  237. break;
  238. case CMD_OCINSTALL_HIDE_VM:
  239. // Do nothing...
  240. break;
  241. default:
  242. ExitProcess(2);
  243. }
  244. if (SUCCEEDED(hrOle))
  245. {
  246. OleUninitialize();
  247. }
  248. ExitProcess(0);
  249. }
  250. #ifdef SHMG_DBG
  251. /***************************************************************************\
  252. *
  253. * FUNCTION: FmtSprintf( DWORD id, ... );
  254. *
  255. * PURPOSE: sprintf but it gets the pattern string from the message rc.
  256. *
  257. * History:
  258. * 03-May-1993 JonPa Created it.
  259. \***************************************************************************/
  260. TCHAR g_szDbgBuffer[16384];
  261. char g_szDbgBufA[16384];
  262. void Dprintf( LPTSTR pszFmt, ... ) {
  263. DWORD cb;
  264. LPVOID psz = g_szDbgBuffer;
  265. va_list marker;
  266. va_start( marker, pszFmt );
  267. wvsprintf( g_szDbgBuffer, pszFmt, marker );
  268. OutputDebugString(g_szDbgBuffer);
  269. #ifdef UNICODE
  270. cb = WideCharToMultiByte(CP_ACP, 0, g_szDbgBuffer, -1, g_szDbgBufA, sizeof(g_szDbgBufA), NULL, NULL);
  271. psz = g_szDbgBufA;
  272. #else
  273. cb = lstrlen(g_szDbgBuffer) * sizeof(TCHAR);
  274. #endif
  275. WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), psz, cb, &cb, NULL);
  276. va_end( marker );
  277. }
  278. #endif