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.

935 lines
29 KiB

  1. #include <windows.h>
  2. #include <shellapi.h>
  3. #include <advpub.h>
  4. #include <ntverp.h>
  5. #include "resource.h"
  6. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  7. #define REGLEN(str) (lstrlen(str) + 1)
  8. #define NUM_VERSION_NUM 4
  9. //---------------------------------------------------------------------------
  10. // appwide globals
  11. HINSTANCE g_hinst = NULL;
  12. HANDLE g_hIExplore = NULL;
  13. char g_szTemp[2048] = {0};
  14. char g_szTemp2[2048] = {0};
  15. char g_szCurrentDir[MAX_PATH];
  16. BOOL g_fWindowsNT;
  17. void ConvertVersionStr(LPSTR pszVer, WORD rwVer[]);
  18. int VersionCmp(WORD rwVer1[], WORD rwVer2[]);
  19. long AtoL(const char *nptr);
  20. //---------------------------------------------------------------------------
  21. // Convert a string resource into a character pointer
  22. // NOTE: Flag is in case we call this twice before we use the data
  23. char * Res2Str(int rsString)
  24. {
  25. static BOOL fSet = FALSE;
  26. if(fSet)
  27. {
  28. LoadString(g_hinst, rsString, g_szTemp, ARRAYSIZE(g_szTemp));
  29. fSet = FALSE;
  30. return(g_szTemp);
  31. }
  32. LoadString(g_hinst, rsString, g_szTemp2, ARRAYSIZE(g_szTemp2));
  33. fSet = TRUE;
  34. return(g_szTemp2);
  35. }
  36. //---------------------------------------------------------------------------
  37. // G E T I E V E R S I O N
  38. //
  39. // ISK3
  40. // This will pull build information out of the system registry and return
  41. // true if it is less than IE5.
  42. //---------------------------------------------------------------------------
  43. int GetIEVersion( )
  44. {
  45. HKEY hkIE;
  46. DWORD dwType;
  47. DWORD dwSize = 32;
  48. DWORD result;
  49. char szData[32],* lpszData;
  50. BOOL bNotIE5=1;
  51. if(RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Internet Explorer", 0, KEY_READ|KEY_WRITE, &hkIE ) == ERROR_SUCCESS)
  52. {
  53. result = RegQueryValueEx( hkIE, "Version", NULL, &dwType, szData, &dwSize );
  54. if( result == ERROR_SUCCESS )
  55. {
  56. WORD rwRegVer[NUM_VERSION_NUM];
  57. WORD rwRegVer2[NUM_VERSION_NUM];
  58. ConvertVersionStr(szData, rwRegVer);
  59. if (LoadString(g_hinst, IDS_IE_VERSION, szData, sizeof(szData)) == 0)
  60. lstrcpy(szData, VER_PRODUCTVERSION_STR);
  61. ConvertVersionStr(szData, rwRegVer2);
  62. // Check the version of IE is 5.0 or greater is installed
  63. if (VersionCmp(rwRegVer, rwRegVer2) >= 0)
  64. bNotIE5=0;
  65. }
  66. RegCloseKey( hkIE );
  67. }
  68. return bNotIE5;
  69. }
  70. //---------------------------------------------------------------------------
  71. // C H E C K B R A N D
  72. //
  73. // ISK3
  74. //---------------------------------------------------------------------------
  75. BOOL CheckBrand( )
  76. {
  77. HKEY hkRegKey;
  78. char szCompany[MAX_PATH];
  79. char szInsPath[MAX_PATH];
  80. char szName[MAX_PATH];
  81. DWORD dwType;
  82. DWORD dwLength = MAX_PATH;
  83. wsprintf( szInsPath, "%s\\install.ins", g_szCurrentDir );
  84. GetPrivateProfileString( "Branding", "CompanyName", "", szName, MAX_PATH, szInsPath );
  85. if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Internet Explorer\\Main", 0, KEY_READ|KEY_WRITE, &hkRegKey ) != ERROR_SUCCESS )
  86. if( lstrlen( szName ) != 0 )
  87. return FALSE;
  88. RegQueryValueEx( hkRegKey, "CompanyName", NULL, &dwType, szCompany, &dwLength );
  89. RegCloseKey( hkRegKey );
  90. if( lstrlen( szName ) == 0 )
  91. return TRUE;
  92. if( lstrlen(szCompany) == 0 )
  93. return FALSE;
  94. if( lstrcmpi( szName, szCompany ) == 0 )
  95. return TRUE;
  96. return FALSE;
  97. }
  98. //---------------------------------------------------------------------------
  99. // G E T I E P A T H
  100. //
  101. // ISK3
  102. // This will retrieve the AppPath for IEXPLORE.EXE from the system registry
  103. // and return it as a string.
  104. //
  105. // Parameters:
  106. // pszString - pointer to buffer to store path
  107. // nSize - size of buffer
  108. //---------------------------------------------------------------------------
  109. char *GetIEPath( LPSTR pszString, int nSize )
  110. {
  111. HKEY hkAppPath;
  112. DWORD dwType = REG_SZ;
  113. DWORD dwSize;
  114. dwSize = nSize;
  115. RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE",
  116. 0, KEY_READ|KEY_WRITE, &hkAppPath );
  117. RegQueryValueEx( hkAppPath, "", NULL, &dwType, pszString, &dwSize );
  118. RegCloseKey( hkAppPath );
  119. return pszString;
  120. }
  121. //---------------------------------------------------------------------------
  122. BOOL _PathRemoveFileSpec(LPSTR pFile)
  123. {
  124. LPSTR pT;
  125. LPSTR pT2 = pFile;
  126. for (pT = pT2; *pT2; pT2 = CharNext(pT2)) {
  127. if (*pT2 == '\\')
  128. pT = pT2; // last "\" found, (we will strip here)
  129. else if (*pT2 == ':') { // skip ":\" so we don't
  130. if (pT2[1] =='\\') // strip the "\" from "C:\"
  131. pT2++;
  132. pT = pT2 + 1;
  133. }
  134. }
  135. if (*pT == 0)
  136. return FALSE; // didn't strip anything
  137. //
  138. // handle the \foo case
  139. //
  140. else if ((pT == pFile) && (*pT == '\\')) {
  141. // Is it just a '\'?
  142. if (*(pT+1) != '\0') {
  143. // Nope.
  144. *(pT+1) = '\0';
  145. return TRUE; // stripped something
  146. }
  147. else {
  148. // Yep.
  149. return FALSE;
  150. }
  151. }
  152. else {
  153. *pT = 0;
  154. return TRUE; // stripped something
  155. }
  156. }
  157. //---------------------------------------------------------------------------
  158. BOOL AutoRunCDIsInDrive( )
  159. {
  160. char me[MAX_PATH];
  161. GetModuleFileName(g_hinst, me, ARRAYSIZE(me));
  162. while (!(GetFileAttributes(me)!=-1))
  163. if (MessageBox(NULL,Res2Str(IDS_NEEDCDROM),Res2Str(IDS_APPTITLE),MB_OKCANCEL | MB_ICONSTOP) == IDCANCEL)
  164. return FALSE;
  165. return TRUE;
  166. }
  167. //---------------------------------------------------------------------------
  168. // E X E C A P P
  169. //
  170. // ISK3
  171. // Similar to AutoRunExec except that we don't put process information into
  172. // the g_ahWait array. For use with WaitForSingleObject.
  173. //---------------------------------------------------------------------------
  174. HANDLE ExecApp( char *command, char *params, char *dir, int nWinState )
  175. {
  176. SHELLEXECUTEINFO sei;
  177. sei.fMask = SEE_MASK_NOCLOSEPROCESS;
  178. sei.hwnd = NULL;
  179. sei.lpVerb = "Open";
  180. sei.lpFile = command;
  181. sei.lpParameters = params;
  182. sei.lpDirectory = dir;
  183. sei.nShow = nWinState;
  184. sei.cbSize = sizeof(sei);
  185. if( ShellExecuteEx(&sei) )
  186. return sei.hProcess;
  187. return NULL;
  188. }
  189. //---------------------------------------------------------------------------
  190. void AutoRunKillIE( void )
  191. {
  192. HWND hwndIE;
  193. hwndIE=FindWindow("IEFrame",NULL);
  194. if(hwndIE!=NULL)
  195. {
  196. PostMessage(hwndIE,WM_CLOSE,(WPARAM) NULL,(LPARAM) NULL);
  197. }
  198. else if ((hwndIE=FindWindow("Internet Explorer_Frame",NULL))!=NULL)
  199. {
  200. PostMessage(hwndIE,WM_CLOSE,(WPARAM) NULL,(LPARAM) NULL);
  201. }
  202. else
  203. {
  204. hwndIE=FindWindow("CabinetWClass",NULL);
  205. if(hwndIE!=NULL)
  206. {
  207. PostMessage(hwndIE,WM_CLOSE,(WPARAM) NULL,(LPARAM) NULL);
  208. }
  209. }
  210. }
  211. //---------------------------------------------------------------------------
  212. void RegisterISKRun( )
  213. {
  214. HKEY hkISK;
  215. HKEY hkISK2;
  216. DWORD dwDisp;
  217. char szCommand[MAX_PATH];
  218. char szSource[MAX_PATH];
  219. lstrcpy( szSource, g_szCurrentDir );
  220. lstrcat( szSource, "\\iskrun.exe" );
  221. GetWindowsDirectory( szCommand, MAX_PATH );
  222. lstrcat( szCommand, "\\iskrun.exe" );
  223. CopyFile( szSource, szCommand, FALSE );
  224. lstrcat( szCommand, " %1" );
  225. if (RegCreateKeyEx( HKEY_CLASSES_ROOT, ".isk", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &hkISK, &dwDisp ) == ERROR_SUCCESS)
  226. {
  227. RegSetValueEx( hkISK, "", 0, REG_SZ, "ISKFile", REGLEN( "ISKFile" ));
  228. RegCloseKey( hkISK );
  229. }
  230. if (RegCreateKeyEx( HKEY_CLASSES_ROOT, "ISKFile", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &hkISK, &dwDisp ) == ERROR_SUCCESS)
  231. {
  232. if (RegCreateKeyEx( hkISK, "Shell", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &hkISK2, &dwDisp ) != ERROR_SUCCESS)
  233. {
  234. RegCloseKey( hkISK );
  235. return;
  236. }
  237. RegCloseKey( hkISK );
  238. if (RegCreateKeyEx( hkISK2, "Open", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &hkISK, &dwDisp ) != ERROR_SUCCESS)
  239. {
  240. RegCloseKey( hkISK2 );
  241. return;
  242. }
  243. RegCloseKey( hkISK2 );
  244. if (RegCreateKeyEx( hkISK, "Command", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &hkISK2, &dwDisp ) != ERROR_SUCCESS)
  245. {
  246. RegCloseKey( hkISK );
  247. return;
  248. }
  249. RegCloseKey( hkISK );
  250. RegSetValueEx( hkISK2, "", 0, REG_SZ, szCommand, REGLEN( szCommand ));
  251. RegCloseKey( hkISK2 );
  252. }
  253. }
  254. //---------------------------------------------------------------------------
  255. void UnregisterISKRun( )
  256. {
  257. HKEY hkISK;
  258. HKEY hkISK2;
  259. char szCommand[MAX_PATH];
  260. GetWindowsDirectory( szCommand, MAX_PATH );
  261. lstrcat( szCommand, "\\iskrun.exe" );
  262. SetFileAttributes( szCommand, FILE_ATTRIBUTE_NORMAL );
  263. DeleteFile( szCommand );
  264. RegDeleteKey( HKEY_CLASSES_ROOT, ".isk" );
  265. if (RegOpenKeyEx( HKEY_CLASSES_ROOT, "ISKFile\\Shell\\Open", 0, KEY_READ|KEY_WRITE, &hkISK ) == ERROR_SUCCESS)
  266. {
  267. RegDeleteKey( hkISK, "Command" );
  268. RegCloseKey( hkISK );
  269. }
  270. if (RegOpenKeyEx( HKEY_CLASSES_ROOT, "ISKFile\\Shell", 0, KEY_READ|KEY_WRITE, &hkISK ) == ERROR_SUCCESS)
  271. {
  272. RegDeleteKey( hkISK, "Open" );
  273. RegCloseKey( hkISK );
  274. }
  275. if (RegOpenKeyEx( HKEY_CLASSES_ROOT, "ISKFile", 0, KEY_READ|KEY_WRITE, &hkISK ) == ERROR_SUCCESS)
  276. {
  277. RegDeleteKey( hkISK, "Shell" );
  278. RegCloseKey( hkISK );
  279. }
  280. RegDeleteKey( HKEY_CLASSES_ROOT, "ISKFile" );
  281. }
  282. //---------------------------------------------------------------------------
  283. void ActiveXEnable( )
  284. {
  285. HKEY hkRegKey;
  286. DWORD dwType;
  287. DWORD dwLength = 4;
  288. DWORD dwValue;
  289. char szSCD[16];
  290. if (RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, KEY_READ|KEY_WRITE, &hkRegKey ) == ERROR_SUCCESS)
  291. {
  292. if( RegQueryValueEx( hkRegKey, "Security_RunActiveXControls", NULL, &dwType, (LPBYTE) &dwValue, &dwLength ) == ERROR_SUCCESS )
  293. RegSetValueEx( hkRegKey, "SRAXC_BACKUP", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  294. else
  295. {
  296. dwValue = 1;
  297. RegSetValueEx( hkRegKey, "SRAXC_BACKUP", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  298. }
  299. dwValue = 1;
  300. RegSetValueEx( hkRegKey, "Security_RunActiveXControls", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  301. dwLength = 4 ;
  302. if( RegQueryValueEx( hkRegKey, "Security_RunJavaApplets", NULL, &dwType, (LPBYTE) &dwValue, &dwLength ) == ERROR_SUCCESS )
  303. RegSetValueEx( hkRegKey, "SRJA_BACKUP", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  304. else
  305. {
  306. dwValue = 1;
  307. RegSetValueEx( hkRegKey, "SRJA_BACKUP", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  308. }
  309. dwValue = 1;
  310. RegSetValueEx( hkRegKey, "Security_RunJavaApplets", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  311. dwLength = 4 ;
  312. if( RegQueryValueEx( hkRegKey, "Security_RunScripts", NULL, &dwType, (LPBYTE) &dwValue, &dwLength ) == ERROR_SUCCESS )
  313. RegSetValueEx( hkRegKey, "SRS_BACKUP", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  314. else
  315. {
  316. dwValue = 1;
  317. RegSetValueEx( hkRegKey, "SRS_BACKUP", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  318. }
  319. dwValue = 1;
  320. RegSetValueEx( hkRegKey, "Security_RunScripts", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  321. dwLength = 16;
  322. dwType = REG_SZ;
  323. if( RegQueryValueEx( hkRegKey, "Code Download", NULL, &dwType, szSCD, &dwLength ) == ERROR_SUCCESS )
  324. RegSetValueEx( hkRegKey, "SCD_BACKUP", 0, REG_SZ, szSCD, lstrlen(szSCD) + 1);
  325. else
  326. RegSetValueEx( hkRegKey, "SCD_BACKUP", 0, REG_SZ, "yes", 4);
  327. RegSetValueEx( hkRegKey, "Code Download", 0, REG_SZ, "yes", 4 );
  328. RegCloseKey( hkRegKey );
  329. }
  330. }
  331. //---------------------------------------------------------------------------
  332. void RestoreActiveX( )
  333. {
  334. HKEY hkRegKey;
  335. DWORD dwType;
  336. DWORD dwLength = 4;
  337. DWORD dwValue;
  338. char szSCD[16];
  339. if (RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, KEY_READ|KEY_WRITE, &hkRegKey ) == ERROR_SUCCESS)
  340. {
  341. RegQueryValueEx( hkRegKey, "SRAXC_BACKUP", NULL, &dwType, (LPBYTE) &dwValue, &dwLength );
  342. RegSetValueEx( hkRegKey, "Security_RunActiveXControls", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  343. RegDeleteValue( hkRegKey, "SRAXC_BACKUP" );
  344. dwLength = 4;
  345. RegQueryValueEx( hkRegKey, "SRJA_BACKUP", NULL, &dwType, (LPBYTE) &dwValue, &dwLength );
  346. RegSetValueEx( hkRegKey, "Security_RunJavaApplets", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  347. RegDeleteValue( hkRegKey, "SRJA_BACKUP" );
  348. dwLength = 4;
  349. RegQueryValueEx( hkRegKey, "SRS_BACKUP", NULL, &dwType, (LPBYTE) &dwValue, &dwLength );
  350. RegSetValueEx( hkRegKey, "Security_RunScripts", 0, REG_BINARY, (LPBYTE) &dwValue, sizeof(DWORD) );
  351. RegDeleteValue( hkRegKey, "SRS_BACKUP" );
  352. dwLength = 16;
  353. RegQueryValueEx( hkRegKey, "SCD_BACKUP", NULL, &dwType, szSCD, &dwLength );
  354. RegSetValueEx( hkRegKey, "Code Download", 0, REG_SZ, szSCD, lstrlen(szSCD) + 1);
  355. RegDeleteValue( hkRegKey, "SCD_BACKUP" );
  356. RegCloseKey( hkRegKey );
  357. }
  358. }
  359. //---------------------------------------------------------------------------
  360. void CreateAppPath( )
  361. {
  362. HKEY hkAppPath;
  363. HKEY hkIECD;
  364. DWORD dwDisp;
  365. char szIECD[MAX_PATH];
  366. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths", 0, KEY_READ|KEY_WRITE, &hkAppPath ) == ERROR_SUCCESS)
  367. {
  368. if (RegCreateKeyEx( hkAppPath, "IECD.EXE", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &hkIECD, &dwDisp ) != ERROR_SUCCESS)
  369. {
  370. RegCloseKey( hkAppPath );
  371. return;
  372. }
  373. RegCloseKey( hkAppPath );
  374. lstrcpy( szIECD, g_szCurrentDir );
  375. lstrcat( szIECD, "\\iecd.exe" );
  376. RegSetValueEx( hkIECD, "", 0, REG_SZ, szIECD, REGLEN( szIECD ));
  377. RegCloseKey( hkIECD );
  378. }
  379. }
  380. //---------------------------------------------------------------------------
  381. BOOL InstallVideoCodec( )
  382. {
  383. char szInfPath[MAX_PATH];
  384. char szInfFile[MAX_PATH];
  385. HKEY hkRegKey;
  386. DWORD dwType = REG_SZ;
  387. DWORD dwLength = sizeof(szInfPath)/sizeof(szInfPath[0]);
  388. HRESULT hReturnCode;
  389. HANDLE hSetupLib;
  390. HRESULT (WINAPI *RunSetupCommand)(HWND,LPCSTR,LPCSTR,LPCSTR,LPCSTR,HANDLE,DWORD,LPVOID);
  391. char szSetupPath[MAX_PATH];
  392. char szInstalled[32];
  393. char szIECD[MAX_PATH];
  394. // quit if we are under NT
  395. if( g_fWindowsNT )
  396. return TRUE;
  397. // Check to see if video is installed
  398. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Setup\\OptionalComponents\\icm", 0, KEY_READ|KEY_WRITE, &hkRegKey ) != ERROR_SUCCESS)
  399. return TRUE;
  400. RegQueryValueEx( hkRegKey, "Installed", NULL, &dwType, szInstalled, &dwLength );
  401. RegCloseKey( hkRegKey );
  402. if( szInstalled[0] == '1' )
  403. return TRUE;
  404. dwLength = MAX_PATH;
  405. // get inf path
  406. if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ|KEY_WRITE, &hkRegKey ) != ERROR_SUCCESS )
  407. return TRUE;
  408. RegQueryValueEx( hkRegKey, "DevicePath", NULL, &dwType, szInfPath, &dwLength );
  409. RegCloseKey( hkRegKey );
  410. if( lstrlen( szInfPath ) == 0 )
  411. return TRUE;
  412. // load dll
  413. hSetupLib = LoadLibrary( "advpack.dll" );
  414. if( hSetupLib )
  415. {
  416. RunSetupCommand = (RUNSETUPCOMMAND) GetProcAddress( hSetupLib, "RunSetupCommand" );
  417. if( !RunSetupCommand )
  418. return TRUE;
  419. }
  420. wsprintf( szInfFile, "%s\\motown.inf", szInfPath );
  421. // get setup directory
  422. RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Setup", 0, KEY_READ|KEY_WRITE, &hkRegKey );
  423. dwLength = MAX_PATH;
  424. RegQueryValueEx( hkRegKey, "SourcePath", NULL, &dwType, szSetupPath, &dwLength );
  425. RegCloseKey( hkRegKey );
  426. if( lstrlen( szSetupPath ) == 0 )
  427. lstrcpy( szSetupPath, szInfPath );
  428. if( lstrlen( szSetupPath ) > 4 )
  429. szSetupPath[lstrlen(szSetupPath) - 1] = '\0';
  430. if(MessageBox( NULL, Res2Str( IDS_VIDEO ), Res2Str( IDS_APPTITLE ), MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND ) == IDNO )
  431. return TRUE;
  432. // run setup
  433. hReturnCode = (*RunSetupCommand)( NULL, szInfFile, "media_icm", szSetupPath, Res2Str( IDS_APPTITLE ),
  434. NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL );
  435. lstrcpy( szIECD, g_szCurrentDir );
  436. lstrcpy( szIECD, "\\iecd.exe" );
  437. if( !AutoRunCDIsInDrive( ))
  438. return FALSE;
  439. FreeLibrary( hSetupLib );
  440. return TRUE;
  441. }
  442. //-------------------------------------------------------------------------
  443. //
  444. // C H E C K O S V E R S I O N
  445. //
  446. //
  447. // Checks the platform and version.
  448. //-------------------------------------------------------------------------
  449. BOOL CheckOsVersion( )
  450. {
  451. OSVERSIONINFO osVersion;
  452. osVersion.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
  453. GetVersionEx( &osVersion );
  454. // if we are running anything less than Windows NT 4.0 or Windows 95, return FALSE
  455. if( osVersion.dwMajorVersion < 4 )
  456. {
  457. // MessageBox( NULL, Res2Str( IDS_WRONGVERSION ), Res2Str( IDS_TITLE ), MB_OK | MB_SETFOREGROUND );
  458. return FALSE;
  459. }
  460. if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT )
  461. g_fWindowsNT = TRUE;
  462. else
  463. g_fWindowsNT = FALSE;
  464. return TRUE;
  465. }
  466. LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  467. {
  468. switch( msg )
  469. {
  470. case WM_QUERYENDSESSION:
  471. {
  472. HWND hwndIE;
  473. DWORD dwExitCode=0;
  474. AutoRunKillIE();
  475. do
  476. {
  477. if(hwndIE=FindWindow(NULL,"Microsoft Internet Explorer"))
  478. {
  479. HWND hButton;
  480. hButton=GetWindow(hwndIE,GW_CHILD);
  481. PostMessage(hwndIE,WM_COMMAND,MAKEWPARAM(IDOK,BN_CLICKED),MAKELPARAM(hButton,0)); //Press the ok button to dismiss the dialog
  482. }
  483. GetExitCodeProcess(g_hIExplore,&dwExitCode);
  484. } while(dwExitCode==STILL_ACTIVE);
  485. return(TRUE);
  486. }
  487. case WM_DESTROY:
  488. PostQuitMessage(0);
  489. break;
  490. default:
  491. return DefWindowProc( hWnd, msg, wParam, lParam );
  492. }
  493. return 1;
  494. }
  495. int _stdcall ModuleEntry(void)
  496. {
  497. int i;
  498. STARTUPINFO si;
  499. LPSTR pszCmdLine = GetCommandLine();
  500. if ( *pszCmdLine == '\"' ) {
  501. /*
  502. * Scan, and skip over, subsequent characters until
  503. * another double-quote or a null is encountered.
  504. */
  505. while ( *++pszCmdLine && (*pszCmdLine != '\"') )
  506. ;
  507. /*
  508. * If we stopped on a double-quote (usual case), skip
  509. * over it.
  510. */
  511. if ( *pszCmdLine == '\"' )
  512. pszCmdLine++;
  513. }
  514. else {
  515. while (*pszCmdLine > ' ')
  516. pszCmdLine++;
  517. }
  518. /*
  519. * Skip past any white space preceeding the second token.
  520. */
  521. while (*pszCmdLine && (*pszCmdLine <= ' ')) {
  522. pszCmdLine++;
  523. }
  524. si.dwFlags = 0;
  525. GetStartupInfoA(&si);
  526. i = WinMain(GetModuleHandle(NULL), NULL, pszCmdLine,
  527. si.dwFlags & STARTF_USESHOWWINDOW ? si.wShowWindow : SW_SHOWDEFAULT);
  528. ExitProcess(i);
  529. return i; // We never comes here.
  530. }
  531. //---------------------------------------------------------------------------
  532. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  533. {
  534. HWND window;
  535. HWND hwndIE;
  536. HWND hwndTray;
  537. HKEY hkLocale;
  538. HKEY hkIE;
  539. HKEY hkWin;
  540. int retval;
  541. char szIECmd[MAX_PATH];
  542. char szLang[MAX_PATH];
  543. DWORD dwLangSize=MAX_PATH;
  544. char szIEParams[MAX_PATH];
  545. char szIEDir[MAX_PATH];
  546. char szTemp[1024];
  547. char szStartHtm[MAX_PATH];
  548. // for security settings
  549. DWORD dwType;
  550. DWORD dwSize = 64;
  551. char szSecurity[64];
  552. char szTrust[64];
  553. BOOL fCmdLine = FALSE;
  554. HANDLE hMutex,hCDCache;
  555. HWND hIskRo;
  556. WNDCLASS wc;
  557. MSG msg;
  558. if( lstrlen( lpCmdLine ) != 0 )
  559. fCmdLine = TRUE;
  560. g_hinst = hInstance;
  561. if( !CheckOsVersion( ))
  562. return FALSE;
  563. //in case this is run from another directory...
  564. GetModuleFileName( NULL, g_szCurrentDir, MAX_PATH );
  565. _PathRemoveFileSpec( g_szCurrentDir );
  566. hMutex = CreateMutex( NULL, TRUE, "IESK_IECD" );
  567. if( GetLastError( ) == ERROR_ALREADY_EXISTS )
  568. return(0);
  569. RegisterISKRun( );
  570. //
  571. // make sure they have IE5 Installed
  572. //
  573. if( (GetIEVersion()) || (!CheckBrand()) )
  574. {
  575. //Install Microsoft Explorer 6
  576. char szIE5Cmd[MAX_PATH],szInstallMessage[MAX_PATH],szInstallTitle[MAX_PATH];
  577. // build paths for ExecApp
  578. lstrcpy( szIE5Cmd, g_szCurrentDir );
  579. lstrcat( szIE5Cmd, "\\ie3inst.exe" );
  580. ExecApp( szIE5Cmd, " ", g_szCurrentDir, SW_SHOWNORMAL );
  581. UnregisterISKRun( );
  582. ReleaseMutex( hMutex );
  583. return 0;
  584. }
  585. lstrcpy( szIEDir, GetIEPath( szIECmd, MAX_PATH ));
  586. _PathRemoveFileSpec( szIEDir );
  587. // add video compression drivers
  588. if(!InstallVideoCodec( ))
  589. {
  590. UnregisterISKRun( );
  591. ReleaseMutex( hMutex );
  592. return 0;
  593. }
  594. CreateAppPath( );
  595. RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\Document Windows", 0, KEY_READ|KEY_WRITE, &hkIE );
  596. RegSetValueEx( hkIE, "Maximized", 0, REG_SZ, "yes", 4 );
  597. RegCloseKey( hkIE );
  598. RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\Security", 0, KEY_READ|KEY_WRITE, &hkIE );
  599. RegQueryValueEx( hkIE, "Safety Warning Level", NULL, &dwType, szSecurity, &dwSize );
  600. RegSetValueEx( hkIE, "SWL Backup", 0, REG_SZ, szSecurity, REGLEN( szSecurity ));
  601. RegSetValueEx( hkIE, "Safety Warning Level", 0, REG_SZ, "SucceedSilent", 14 );
  602. RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, KEY_READ|KEY_WRITE, &hkWin );
  603. dwSize = 64;
  604. RegQueryValueEx( hkWin, "Trust Warning Level", NULL, &dwType, szTrust, &dwSize );
  605. RegSetValueEx( hkWin, "TWL Backup", 0, REG_SZ, szTrust, REGLEN( szTrust ));
  606. RegSetValueEx( hkWin, "Trust Warning Level", 0, REG_SZ, "No Security", 12 );
  607. ActiveXEnable( );
  608. lstrcpy( szIEParams, "-SLF -k file://" );
  609. if( !fCmdLine )
  610. {
  611. lstrcat( szIEParams, g_szCurrentDir );
  612. lstrcat( szIEParams, "\\start.htm" );
  613. lstrcpy( szStartHtm, g_szCurrentDir);
  614. lstrcat( szStartHtm, "\\start.htm");
  615. }
  616. else
  617. {
  618. lstrcat( szIEParams, lpCmdLine );
  619. lstrcpy( szStartHtm, lpCmdLine);
  620. }
  621. if (GetFileAttributes(szStartHtm) != 0xFFFFFFFF)
  622. {
  623. g_hIExplore = ExecApp( szIECmd, szIEParams, szIEDir, SW_SHOWNORMAL );
  624. if(g_hIExplore)
  625. {
  626. DWORD dwExitCode;
  627. BOOL bContinue=TRUE;
  628. HANDLE hArray[2];
  629. HWND hIEWnd;
  630. hArray[0]=g_hIExplore;
  631. wc.style = 0;
  632. wc.lpfnWndProc = MainWndProc;
  633. wc.cbClsExtra = wc.cbWndExtra = 0;
  634. wc.hInstance = g_hinst;
  635. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  636. wc.hIcon = NULL;
  637. wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
  638. wc.lpszMenuName = NULL;
  639. wc.lpszClassName = "IECD";
  640. RegisterClass(&wc);
  641. // NOTE: If the window classname is changed, it should be reflected in closeie.exe,
  642. // iskrun.exe and browseui.dll which depend on the classname to check whether iecd.exe
  643. // is running.
  644. hIEWnd=CreateWindow( "IECD", "IECD", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 30, 30,
  645. NULL, NULL, g_hinst, NULL );
  646. hArray[1]=hIEWnd;
  647. while(bContinue)
  648. {
  649. MsgWaitForMultipleObjects(2,hArray,FALSE,INFINITE,QS_ALLINPUT);
  650. if(PeekMessage(&msg,hIEWnd,0,0,PM_REMOVE))
  651. {
  652. if(msg.message==WM_QUIT)
  653. {
  654. bContinue=FALSE;
  655. }
  656. else
  657. {
  658. TranslateMessage( &msg );
  659. DispatchMessage( &msg );
  660. }
  661. }
  662. GetExitCodeProcess(g_hIExplore,&dwExitCode);
  663. if(dwExitCode!=STILL_ACTIVE)
  664. {
  665. bContinue=FALSE;
  666. }
  667. }
  668. }
  669. }
  670. else
  671. {
  672. BOOL fShow = TRUE;
  673. DWORD dwVal = 0;
  674. HKEY hkShow;
  675. if (RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Tips", 0, KEY_READ|KEY_WRITE, &hkShow ) == ERROR_SUCCESS)
  676. {
  677. if ((RegQueryValueEx( hkShow, "DisableStartHtm", NULL, &dwType, (LPBYTE)&dwVal, &dwSize ) == ERROR_SUCCESS) &&
  678. dwVal)
  679. {
  680. RegDeleteValue(hkShow, "DisableStartHtm");
  681. fShow = FALSE;
  682. }
  683. RegCloseKey( hkShow );
  684. }
  685. if (fShow)
  686. MessageBox(NULL, Res2Str(IDS_LATESTVER), Res2Str(IDS_APPTITLE), MB_OK);
  687. }
  688. RestoreActiveX( );
  689. RegSetValueEx( hkIE, "Safety Warning Level", 0, REG_SZ, szSecurity, REGLEN( szSecurity ));
  690. RegDeleteValue( hkIE, "SWL Backup" );
  691. RegCloseKey( hkIE );
  692. RegSetValueEx( hkWin, "Trust Warning Level", 0, REG_SZ, szTrust, REGLEN( szTrust ));
  693. RegDeleteValue( hkWin, "TWL Backup" );
  694. RegCloseKey( hkWin );
  695. UnregisterISKRun( );
  696. ReleaseMutex( hMutex );
  697. return 0;
  698. }
  699. void ConvertVersionStr(LPSTR pszVer, WORD rwVer[])
  700. {
  701. int i;
  702. for(i = 0; i < NUM_VERSION_NUM; i++)
  703. rwVer[i] = 0;
  704. for(i = 0; i < NUM_VERSION_NUM && pszVer; i++)
  705. {
  706. rwVer[i] = (WORD) AtoL(pszVer);
  707. pszVer = strchr(pszVer, '.');
  708. if (pszVer)
  709. pszVer++;
  710. }
  711. }
  712. // Returns:
  713. // -1 Ver1 < Ver2
  714. // 0 Ver1 == Ver2
  715. // 1 Ver1 > Ver2
  716. // Notes:
  717. int VersionCmp(WORD rwVer1[], WORD rwVer2[])
  718. {
  719. int i;
  720. for(i = 0; i < NUM_VERSION_NUM; i++)
  721. {
  722. if(rwVer1[i] < rwVer2[i])
  723. return -1;
  724. if(rwVer1[i] > rwVer2[i])
  725. return 1;
  726. }
  727. return 0;
  728. }
  729. #define IsSpace(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n' || (c) == '\v' || (c) == '\f')
  730. #define IsDigit(c) ((c) >= '0' && (c) <= '9')
  731. // copied from msdev\crt\src\atox.c
  732. /***
  733. *long AtoL(char *nptr) - Convert string to long
  734. *
  735. *Purpose:
  736. * Converts ASCII string pointed to by nptr to binary.
  737. * Overflow is not detected.
  738. *
  739. *Entry:
  740. * nptr = ptr to string to convert
  741. *
  742. *Exit:
  743. * return long int value of the string
  744. *
  745. *Exceptions:
  746. * None - overflow is not detected.
  747. *
  748. *******************************************************************************/
  749. long AtoL(const char *nptr)
  750. {
  751. int c; /* current char */
  752. long total; /* current total */
  753. int sign; /* if '-', then negative, otherwise positive */
  754. // NOTE: no need to worry about DBCS chars here because IsSpace(c), IsDigit(c),
  755. // '+' and '-' are "pure" ASCII chars, i.e., they are neither DBCS Leading nor
  756. // DBCS Trailing bytes -- pritvi
  757. /* skip whitespace */
  758. while ( IsSpace((int)(unsigned char)*nptr) )
  759. ++nptr;
  760. c = (int)(unsigned char)*nptr++;
  761. sign = c; /* save sign indication */
  762. if (c == '-' || c == '+')
  763. c = (int)(unsigned char)*nptr++; /* skip sign */
  764. total = 0;
  765. while (IsDigit(c)) {
  766. total = 10 * total + (c - '0'); /* accumulate digit */
  767. c = (int)(unsigned char)*nptr++; /* get next char */
  768. }
  769. if (sign == '-')
  770. return -total;
  771. else
  772. return total; /* return result, negated if necessary */
  773. }