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.

326 lines
9.5 KiB

  1. // **************************************************************************
  2. //
  3. // ROMain.C
  4. //
  5. // Microsoft Confidential
  6. // Copyright (c) Microsoft Corporation 1992-1993
  7. // All rights reserved
  8. //
  9. // The window/messages pump for RunOnce
  10. //
  11. // 5 June 1994 FelixA Started
  12. //
  13. // 23 June 94 FelixA Moved to Shell tree. Changed UI.
  14. //
  15. // *************************************************************************/
  16. #include "precomp.h"
  17. #include "regstr.h"
  18. #include <shlwapi.h>
  19. #include <shlwapip.h>
  20. #include <commctrl.h>
  21. #include <comctrlp.h>
  22. #include <shellapi.h>
  23. #include <winuserp.h>
  24. #include <shlobj.h>
  25. #include <shlobjp.h>
  26. #include "resource.h"
  27. #include <runonce.c> // shared runonce code
  28. // needed to make this code compile (legacy runonce.c baggage from explorer\initcab.cpp)
  29. BOOL g_fCleanBoot = FALSE;
  30. BOOL g_fEndSession = FALSE;
  31. HINSTANCE g_hInst; // current instance
  32. BOOL InitROInstance( HINSTANCE hInstance, int nCmdShow);
  33. typedef void (WINAPI *RUNONCEEXPROCESS)(HWND, HINSTANCE, LPSTR, int);
  34. int ParseCmdLine(LPCTSTR lpCmdLine)
  35. {
  36. int Res=0;
  37. while(*lpCmdLine)
  38. {
  39. while( *lpCmdLine && *lpCmdLine!=TEXT('-') && *lpCmdLine!=TEXT('/'))
  40. lpCmdLine++;
  41. if (!(*lpCmdLine)) {
  42. return Res;
  43. }
  44. // skip over the '/'
  45. lpCmdLine++;
  46. if (lstrcmpi(lpCmdLine, TEXT("RunOnce6432")) == 0)
  47. {
  48. if (IsOS(OS_WOW6432))
  49. {
  50. // this means we have to process the 32-bit RunOnce keys for wow64
  51. Res = Cabinet_EnumRegApps(HKEY_LOCAL_MACHINE,
  52. REGSTR_PATH_RUNONCE,
  53. RRA_DELETE | RRA_WAIT,
  54. ExecuteRegAppEnumProc,
  55. 0);
  56. }
  57. return Res;
  58. }
  59. else if (lstrcmpi(lpCmdLine, TEXT("RunOnceEx6432")) == 0)
  60. {
  61. if (IsOS(OS_WOW6432))
  62. {
  63. // this means that we have to process the 32-bit RunOnceEx keys for wow64
  64. HINSTANCE hLib;
  65. hLib = LoadLibrary(TEXT("iernonce.dll"));
  66. if (hLib)
  67. {
  68. // Note: if ew ant TS install mode for wow64 apps we need to enable/disable install mode here
  69. RUNONCEEXPROCESS pfnRunOnceExProcess = (RUNONCEEXPROCESS)GetProcAddress(hLib, "RunOnceExProcess");
  70. if (pfnRunOnceExProcess)
  71. {
  72. // the four param in the function is due to the function cab be called
  73. // from RunDLL which will path in those params. But RunOnceExProcess ignore all
  74. // of them. Therefore, I don't pass any meaningful thing here.
  75. //
  76. pfnRunOnceExProcess(NULL, NULL, NULL, 0);
  77. Res = 1;
  78. }
  79. FreeLibrary(hLib);
  80. }
  81. }
  82. return Res;
  83. }
  84. else if (lstrcmpi(lpCmdLine, TEXT("Run6432")) == 0)
  85. {
  86. if (IsOS(OS_WOW6432))
  87. {
  88. // this means that we have to process the 32-bit Run keys for wow64
  89. Res = Cabinet_EnumRegApps(HKEY_LOCAL_MACHINE,
  90. REGSTR_PATH_RUN,
  91. RRA_NOUI,
  92. ExecuteRegAppEnumProc,
  93. 0);
  94. }
  95. return Res;
  96. }
  97. switch(*lpCmdLine)
  98. {
  99. case TEXT('r'):
  100. Res|=CMD_DO_CHRIS;
  101. break;
  102. case TEXT('b'):
  103. Res|=CMD_DO_REBOOT;
  104. break;
  105. case TEXT('s'):
  106. Res|=CMD_DO_RESTART;
  107. break;
  108. }
  109. lpCmdLine++;
  110. }
  111. return Res;
  112. }
  113. /****************************************************************************
  114. FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  115. PURPOSE: calls initialization function, processes message loop
  116. ****************************************************************************/
  117. int g_iState=0;
  118. int __stdcall WinMainT(
  119. HINSTANCE hInstance,
  120. HINSTANCE hPrevInstance,
  121. LPTSTR lpCmdLine,
  122. int nCmdShow)
  123. {
  124. if (!hPrevInstance)
  125. { // Other instances of app running?
  126. if (!InitApplication(hInstance))
  127. { // Initialize shared things
  128. return (FALSE); // Exits if unable to initialize
  129. }
  130. }
  131. // see if we have a commnand line switch - in a VERY bad way.
  132. g_iState = ParseCmdLine(GetCommandLine());
  133. if(g_iState & CMD_DO_CHRIS )
  134. {
  135. // Go do chris's runonce stuff.
  136. if (!InitROInstance(hInstance, nCmdShow))
  137. return (FALSE);
  138. return TRUE;
  139. }
  140. else
  141. {
  142. /* Perform initializations that apply to a specific instance */
  143. if (!InitInstance(hInstance, nCmdShow))
  144. return (FALSE);
  145. }
  146. return (FALSE);
  147. }
  148. /****************************************************************************
  149. FUNCTION: InitApplication(HINSTANCE)
  150. ****************************************************************************/
  151. BOOL InitApplication(HINSTANCE hInstance)
  152. {
  153. // CreateGlobals();
  154. return TRUE;
  155. }
  156. /****************************************************************************
  157. FUNCTION: InitInstance(HINSTANCE, int)
  158. ****************************************************************************/
  159. BOOL InitInstance( HINSTANCE hInstance, int nCmdShow)
  160. {
  161. HWND hShell=GetShellWindow();
  162. g_hInst = hInstance; // Store instance handle in our global variable
  163. DialogBox(hInstance, MAKEINTRESOURCE(IDD_RUNONCE),NULL,dlgProcRunOnce);
  164. return (TRUE); // We succeeded...
  165. }
  166. BOOL InitROInstance( HINSTANCE hInstance, int nCmdShow)
  167. {
  168. g_hInst = hInstance; // Store instance handle in our global variable
  169. // Ideally this should be sufficient.
  170. Cabinet_EnumRegApps(HKEY_LOCAL_MACHINE, REGSTR_PATH_RUNONCE, RRA_DELETE| RRA_WAIT, ExecuteRegAppEnumProc, 0);
  171. return TRUE;
  172. }
  173. BOOL TopLeftWindow( HWND hwndChild, HWND hwndParent)
  174. {
  175. return SetWindowPos(hwndChild, NULL, 32, 32, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  176. }
  177. /****************************************************************************
  178. FUNCTION: CenterWindow (HWND, HWND)
  179. PURPOSE: Center one window over another
  180. COMMENTS:
  181. Dialog boxes take on the screen position that they were designed at,
  182. which is not always appropriate. Centering the dialog over a particular
  183. window usually results in a better position.
  184. ****************************************************************************/
  185. BOOL CenterWindow (HWND hwndChild, HWND hwndParent)
  186. {
  187. RECT rChild, rParent;
  188. int wChild, hChild, wParent, hParent;
  189. int wScreen, hScreen, xNew, yNew;
  190. HDC hdc;
  191. // Get the Height and Width of the child window
  192. GetWindowRect (hwndChild, &rChild);
  193. wChild = rChild.right - rChild.left;
  194. hChild = rChild.bottom - rChild.top;
  195. // Get the display limits
  196. hdc = GetDC (hwndChild);
  197. wScreen = GetDeviceCaps (hdc, HORZRES);
  198. hScreen = GetDeviceCaps (hdc, VERTRES);
  199. ReleaseDC (hwndChild, hdc);
  200. // Get the Height and Width of the parent window
  201. if( !GetWindowRect (hwndParent, &rParent) )
  202. {
  203. rParent.right = wScreen;
  204. rParent.left = 0;
  205. rParent.top = 0;
  206. rParent.bottom = hScreen;
  207. }
  208. wParent = rParent.right - rParent.left;
  209. hParent = rParent.bottom - rParent.top;
  210. // Calculate new X position, then adjust for screen
  211. xNew = rParent.left + ((wParent - wChild) /2);
  212. if (xNew < 0)
  213. {
  214. xNew = 0;
  215. }
  216. else
  217. if ((xNew+wChild) > wScreen)
  218. {
  219. xNew = wScreen - wChild;
  220. }
  221. // Calculate new Y position, then adjust for screen
  222. yNew = rParent.top + ((hParent - hChild) /2);
  223. if (yNew < 0)
  224. {
  225. yNew = 0;
  226. } else if ((yNew+hChild) > hScreen)
  227. {
  228. yNew = hScreen - hChild;
  229. }
  230. // Set it, and return
  231. return SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  232. }
  233. // stolen from the CRT, used to shirink our code
  234. int _stdcall ModuleEntry(void)
  235. {
  236. int i;
  237. STARTUPINFO si;
  238. LPTSTR pszCmdLine = GetCommandLine();
  239. if ( *pszCmdLine == TEXT('\"') ) {
  240. /*
  241. * Scan, and skip over, subsequent characters until
  242. * another double-quote or a null is encountered.
  243. */
  244. while ( *++pszCmdLine && (*pszCmdLine
  245. != TEXT('\"')) );
  246. /*
  247. * If we stopped on a double-quote (usual case), skip
  248. * over it.
  249. */
  250. if ( *pszCmdLine == TEXT('\"') )
  251. pszCmdLine++;
  252. }
  253. else {
  254. while (*pszCmdLine > TEXT(' '))
  255. pszCmdLine++;
  256. }
  257. /*
  258. * Skip past any white space preceeding the second token.
  259. */
  260. while (*pszCmdLine && (*pszCmdLine <= TEXT(' '))) {
  261. pszCmdLine++;
  262. }
  263. si.dwFlags = 0;
  264. GetStartupInfo(&si);
  265. i = WinMainT(GetModuleHandle(NULL), NULL, pszCmdLine,
  266. si.dwFlags & STARTF_USESHOWWINDOW ? si.wShowWindow : SW_SHOWDEFAULT);
  267. ExitProcess(i);
  268. return i; // We never comes here.
  269. }