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.

1028 lines
26 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. Nt.c
  6. Abstract:
  7. Routines to migrate Win95 printing components to NT
  8. Author:
  9. Keisuke Tsuchida (KeisukeT) 10-Oct-2000
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. //
  14. // Extern
  15. //
  16. extern LPCSTR g_WorkingDirectory;
  17. extern LPCSTR g_SourceDirectory;
  18. extern LPCSTR g_MediaDirectory;
  19. //
  20. // Typedef
  21. //
  22. typedef BOOL (WINAPI *PMIGRATEDEVICE)(PDEVICE_INFO);
  23. typedef DWORD (WINAPI *PSHDELETEKEY)(HKEY, LPCSTR);
  24. LONG
  25. CALLBACK
  26. InitializeNT(
  27. IN LPCWSTR pszWorkingDir,
  28. IN LPCWSTR pszSourceDir,
  29. IN LPCWSTR pszMediaDir
  30. )
  31. {
  32. LONG lError;
  33. //
  34. // Initialize local.
  35. //
  36. lError = ERROR_SUCCESS;
  37. //
  38. // Save given parameters.
  39. //
  40. g_WorkingDirectory = AllocStrAFromStrW(pszWorkingDir);
  41. g_SourceDirectory = AllocStrAFromStrW(pszSourceDir);
  42. g_MediaDirectory = AllocStrAFromStrW(pszMediaDir);
  43. if(NULL == g_WorkingDirectory){
  44. SetupLogError("WIA Migration: InitializeNT: ERROR!! insufficient memory.\r\n", LogSevError);
  45. lError = ERROR_NOT_ENOUGH_MEMORY;
  46. goto InitializeNT_return;
  47. }
  48. InitializeNT_return:
  49. if(ERROR_SUCCESS != lError){
  50. //
  51. // Can't process migration. Clean up.
  52. //
  53. if(NULL != g_WorkingDirectory){
  54. FreeMem((PVOID)g_WorkingDirectory);
  55. g_WorkingDirectory = NULL;
  56. }
  57. if(NULL != g_SourceDirectory){
  58. FreeMem((PVOID)g_SourceDirectory);
  59. g_SourceDirectory = NULL;
  60. }
  61. if(NULL != g_MediaDirectory){
  62. FreeMem((PVOID)g_MediaDirectory);
  63. g_MediaDirectory = NULL;
  64. }
  65. } // if(ERROR_SUCCESS != lError)
  66. return lError;
  67. }
  68. LONG
  69. CALLBACK
  70. MigrateUserNT(
  71. IN HINF hUnattendInf,
  72. IN HKEY hUserRegKey,
  73. IN LPCWSTR pszUserName,
  74. LPVOID Reserved
  75. )
  76. {
  77. return ERROR_SUCCESS;
  78. }
  79. LONG
  80. CALLBACK
  81. MigrateSystemNT(
  82. IN HINF hUnattendInf,
  83. LPVOID Reserved
  84. )
  85. {
  86. LONG lError;
  87. HANDLE hFile;
  88. CHAR szFile[MAX_PATH];
  89. //
  90. // Initialize local.
  91. //
  92. lError = ERROR_SUCCESS;
  93. hFile = (HANDLE)INVALID_HANDLE_VALUE;
  94. //
  95. // Check global initialization.
  96. //
  97. if(NULL == g_WorkingDirectory){
  98. lError = ERROR_NOT_ENOUGH_MEMORY;
  99. MyLogError("WIA Migration: MigrateSystemNT: ERROR!! Initialize failed. Err=0x%x\n", lError);
  100. goto MigrateSystemNT_return;
  101. } // if(NULL == g_WorkingDirectory)
  102. //
  103. // Create path to the files.
  104. //
  105. // wsprintfA(szFile, "%s\\%s", g_WorkingDirectory, NAME_WIN9X_SETTING_FILE_A);
  106. _snprintf(szFile, sizeof(szFile), "%s\\%s", g_WorkingDirectory, NAME_WIN9X_SETTING_FILE_A);
  107. //
  108. // Make sure the string is NULL terminated.
  109. //
  110. szFile[sizeof(szFile)/sizeof(szFile[0]) -1] = '\0';
  111. //
  112. // Open migration file.
  113. //
  114. hFile = CreateFileA(szFile,
  115. GENERIC_READ,
  116. FILE_SHARE_READ,
  117. NULL,
  118. OPEN_EXISTING,
  119. FILE_ATTRIBUTE_NORMAL |
  120. FILE_FLAG_SEQUENTIAL_SCAN,
  121. NULL);
  122. if (hFile == INVALID_HANDLE_VALUE){
  123. lError = GetLastError();
  124. MyLogError("WIA Migration: MigrateSystemNT: ERROR!! Unable to open migration file. Err=0x%x\n", lError);
  125. goto MigrateSystemNT_return;
  126. } // if (hFile == INVALID_HANDLE_VALUE)
  127. //
  128. // Process migration info file created on Win9x.
  129. //
  130. lError = MigNtProcessMigrationInfo(hFile);
  131. //
  132. // Remove certain reg if inbox Kodak Imaging for Win9x is installed.
  133. //
  134. if(MigNtIsWin9xImagingExisting()){
  135. MigNtRemoveKodakImagingKey();
  136. } // if(MigNtIsWin9xImagingExisting())
  137. MigrateSystemNT_return:
  138. //
  139. // Clean up.
  140. //
  141. if(INVALID_HANDLE_VALUE == hFile){
  142. CloseHandle(hFile);
  143. }
  144. return lError;
  145. } // MigrateSystemNT()
  146. LONG
  147. MigNtProcessMigrationInfo(
  148. HANDLE hFile
  149. )
  150. {
  151. LONG lError;
  152. DEVICE_INFO MigrateDevice;
  153. HMODULE hInstaller;
  154. PMIGRATEDEVICE pfnMigrateDevice;
  155. //
  156. // Initialize local.
  157. //
  158. lError = ERROR_SUCCESS;
  159. hInstaller = (HMODULE)NULL;
  160. pfnMigrateDevice = NULL;
  161. memset(&MigrateDevice, 0, sizeof(MigrateDevice));
  162. //
  163. // Load STI_CI.DLL.
  164. //
  165. hInstaller = LoadLibrary(NAME_INSTALLER_A);
  166. if(NULL == hInstaller){
  167. //
  168. // Unable to load sti_ci.dll.
  169. //
  170. lError = GetLastError();
  171. MyLogError("WIA Migration: MigNtProcessMigrationInfo: ERROR!! Unable to load sti_ci.dll. Err=0x%x\n", lError);
  172. goto MigNtProcessMigrationInfo_return;
  173. } // if(NULL == hInstaller)
  174. //
  175. // Get address of MigrateDevice()
  176. //
  177. pfnMigrateDevice = (PMIGRATEDEVICE)GetProcAddress(hInstaller, NAME_PROC_MIGRATEDEVICE_A);
  178. if(NULL == pfnMigrateDevice){
  179. //
  180. // Unable to get proc address.
  181. //
  182. lError = GetLastError();
  183. MyLogError("WIA Migration: MigNtProcessMigrationInfo: ERROR!! Unable to get proc address. Err=0x%x\n", lError);
  184. goto MigNtProcessMigrationInfo_return;
  185. } // if(NULL == pfnMigrateDevice)
  186. //
  187. // Query migrating device.
  188. //
  189. while(ERROR_SUCCESS == MigNtGetDevice(hFile, &MigrateDevice)){
  190. //
  191. // Install only COM/LPT device.
  192. //
  193. if( (NULL != strstr(MigrateDevice.pszCreateFileName, "COM"))
  194. || (NULL != strstr(MigrateDevice.pszCreateFileName, "LPT"))
  195. || (NULL != strstr(MigrateDevice.pszCreateFileName, "AUTO")) )
  196. {
  197. pfnMigrateDevice(&MigrateDevice);
  198. }
  199. /***********
  200. {
  201. PPARAM_LIST pTemp;
  202. printf("\"%s\" = \"%s\"\r\n", NAME_FRIENDLYNAME_A, MigrateDevice.pszFriendlyName);
  203. printf("\"%s\" = \"%s\"\r\n", NAME_CREATEFILENAME_A, MigrateDevice.pszCreateFileName);
  204. printf("\"%s\" = \"%s\"\r\n", NAME_INF_PATH_A, MigrateDevice.pszInfPath);
  205. printf("\"%s\" = \"%s\"\r\n", NAME_INF_SECTION_A, MigrateDevice.pszInfSection);
  206. for(pTemp = MigrateDevice.pDeviceDataParam; pTemp != NULL;){
  207. printf("\"%s\" = \"%s\"\r\n", pTemp->pParam1, pTemp->pParam2);
  208. pTemp = (PPARAM_LIST)pTemp->pNext;
  209. } // for(pTemp = MigrateDevice.pDeviceDataParam; pTemp != NULL;)
  210. printf("\r\n");
  211. }
  212. ***********/
  213. //
  214. // Clean up.
  215. //
  216. MigNtFreeDeviceInfo(&MigrateDevice);
  217. } // while(ERROR_SUCCESS == MigNtGetDevice(hFile, &MigrateDevice))
  218. MigNtProcessMigrationInfo_return:
  219. //
  220. // Clean up.
  221. //
  222. if(NULL != hInstaller){
  223. FreeLibrary(hInstaller);
  224. }
  225. return lError;
  226. } // MigNtProcessMigrationInfo()
  227. LONG
  228. MigNtGetDevice(
  229. HANDLE hFile,
  230. PDEVICE_INFO pMigrateDevice
  231. )
  232. {
  233. LONG lError;
  234. LPSTR pParam1;
  235. LPSTR pParam2;
  236. BOOL bFound;
  237. LPSTR pszFriendlyName;
  238. LPSTR pszCreateFileName;
  239. LPSTR pszInfPath;
  240. LPSTR pszInfSection;
  241. DWORD dwNumberOfDeviceDataKey;
  242. PPARAM_LIST pDeviceDataParam;
  243. PPARAM_LIST pTempParam;
  244. //
  245. // Initialize local.
  246. //
  247. lError = ERROR_SUCCESS;
  248. pParam1 = NULL;
  249. pParam2 = NULL;
  250. bFound = FALSE;
  251. pszFriendlyName = NULL;
  252. pszCreateFileName = NULL;
  253. pszInfPath = NULL;
  254. pszInfSection = NULL;
  255. pDeviceDataParam = NULL;
  256. pTempParam = NULL;
  257. dwNumberOfDeviceDataKey = 0;
  258. //
  259. // Find "Device = BEGIN"
  260. //
  261. while(FALSE == bFound){
  262. ReadString(hFile, &pParam1, &pParam2);
  263. if( (NULL != pParam1) && (NULL != pParam2) ){
  264. //
  265. // Both parameter exist.
  266. //
  267. if( (0 == MyStrCmpiA(pParam1, NAME_DEVICE_A))
  268. && (0 == MyStrCmpiA(pParam2, NAME_BEGIN_A)) )
  269. {
  270. //
  271. // Found begining of device description.
  272. //
  273. bFound = TRUE;
  274. }
  275. } else { // if( (NULL != pParam1) && (NULL != pParam2) )
  276. if( (NULL == pParam1) && (NULL == pParam2) ){
  277. //
  278. // Error or EOF.
  279. //
  280. lError = ERROR_NO_MORE_ITEMS;
  281. goto MigNtGetDevice_return;
  282. } else {
  283. //
  284. // A line with single parameter. Just ignore.
  285. //
  286. }
  287. }
  288. //
  289. // Free allocated memory.
  290. //
  291. if(NULL != pParam1){
  292. FreeMem(pParam1);
  293. pParam1 = NULL;
  294. }
  295. if(NULL != pParam2){
  296. FreeMem(pParam2);
  297. pParam2 = NULL;
  298. }
  299. } // while(FALSE == bFound)
  300. //
  301. // Get FriendlyName
  302. //
  303. ReadString(hFile, &pParam1, &pParam2);
  304. if( (NULL == pParam1) || (NULL == pParam2) ){
  305. lError = ERROR_NOT_ENOUGH_MEMORY;
  306. goto MigNtGetDevice_return;
  307. } // if( (NULL == pParam1) || (NULL == pParam2) )
  308. if(0 != MyStrCmpiA(pParam1, NAME_FRIENDLYNAME_A)){
  309. //
  310. // Invalid migration file.
  311. //
  312. lError = ERROR_INVALID_PARAMETER;
  313. goto MigNtGetDevice_return;
  314. } //if(0 != MyStrCmpiA(pParam1, NAME_FRIENDLYNAME_A))
  315. //
  316. // Copy to allocated buffer.
  317. //
  318. pszFriendlyName = AllocStrA(pParam2);
  319. //
  320. // Free allocated memory.
  321. //
  322. if(NULL != pParam1){
  323. FreeMem(pParam1);
  324. pParam1 = NULL;
  325. }
  326. if(NULL != pParam2){
  327. FreeMem(pParam2);
  328. pParam2 = NULL;
  329. }
  330. //
  331. // Get CreateFileName
  332. //
  333. ReadString(hFile, &pParam1, &pParam2);
  334. if( (NULL == pParam1) || (NULL == pParam2) ){
  335. lError = ERROR_NOT_ENOUGH_MEMORY;
  336. goto MigNtGetDevice_return;
  337. } // if( (NULL == pParam1) || (NULL == pParam2) )
  338. if(0 != MyStrCmpiA(pParam1, NAME_CREATEFILENAME_A)){
  339. //
  340. // Invalid migration file.
  341. //
  342. lError = ERROR_INVALID_PARAMETER;
  343. goto MigNtGetDevice_return;
  344. } //if(0 != MyStrCmpiA(pParam1, NAME_CREATEFILENAME_A))
  345. //
  346. // Copy to allocated buffer.
  347. //
  348. pszCreateFileName = AllocStrA(pParam2);
  349. //
  350. // Free allocated memory.
  351. //
  352. if(NULL != pParam1){
  353. FreeMem(pParam1);
  354. pParam1 = NULL;
  355. }
  356. if(NULL != pParam2){
  357. FreeMem(pParam2);
  358. pParam2 = NULL;
  359. }
  360. //
  361. // Get InfPath
  362. //
  363. ReadString(hFile, &pParam1, &pParam2);
  364. if( (NULL == pParam1) || (NULL == pParam2) ){
  365. lError = ERROR_NOT_ENOUGH_MEMORY;
  366. goto MigNtGetDevice_return;
  367. } // if( (NULL == pParam1) || (NULL == pParam2) )
  368. if(0 != MyStrCmpiA(pParam1, NAME_INF_PATH_A)){
  369. //
  370. // Invalid migration file.
  371. //
  372. lError = ERROR_INVALID_PARAMETER;
  373. goto MigNtGetDevice_return;
  374. } //if(0 != MyStrCmpiA(pParam1, NAME_INF_PATH_A))
  375. //
  376. // Copy to allocated buffer.
  377. //
  378. pszInfPath = AllocStrA(pParam2);
  379. //
  380. // Free allocated memory.
  381. //
  382. if(NULL != pParam1){
  383. FreeMem(pParam1);
  384. pParam1 = NULL;
  385. }
  386. if(NULL != pParam2){
  387. FreeMem(pParam2);
  388. pParam2 = NULL;
  389. }
  390. //
  391. // Get InfSection
  392. //
  393. ReadString(hFile, &pParam1, &pParam2);
  394. if( (NULL == pParam1) || (NULL == pParam2) ){
  395. lError = ERROR_NOT_ENOUGH_MEMORY;
  396. goto MigNtGetDevice_return;
  397. } // if( (NULL == pParam1) || (NULL == pParam2) )
  398. if(0 != MyStrCmpiA(pParam1, NAME_INF_SECTION_A)){
  399. //
  400. // Invalid migration file.
  401. //
  402. lError = ERROR_INVALID_PARAMETER;
  403. goto MigNtGetDevice_return;
  404. } //if(0 != MyStrCmpiA(pParam1, NAME_INF_SECTION_A))
  405. //
  406. // Copy to allocated buffer.
  407. //
  408. pszInfSection = AllocStrA(pParam2);
  409. //
  410. // Free allocated memory.
  411. //
  412. if(NULL != pParam1){
  413. FreeMem(pParam1);
  414. pParam1 = NULL;
  415. }
  416. if(NULL != pParam2){
  417. FreeMem(pParam2);
  418. pParam2 = NULL;
  419. }
  420. //
  421. // Get DeviceData section.
  422. //
  423. bFound = FALSE;
  424. while(FALSE == bFound){
  425. ReadString(hFile, &pParam1, &pParam2);
  426. if( (NULL == pParam1) || (NULL == pParam2) ){
  427. lError = ERROR_NOT_ENOUGH_MEMORY;
  428. goto MigNtGetDevice_return;
  429. } // if( (NULL == pParam1) || (NULL == pParam2) )
  430. if(0 == MyStrCmpiA(pParam1, REGKEY_DEVICEDATA_A)){
  431. //
  432. // Found beginning of DeviceData section.
  433. //
  434. bFound = TRUE;
  435. } // if(0 == MyStrCmpiA(pParam1, REGKEY_DEVICEDATA_A))
  436. //
  437. // Free allocated memory.
  438. //
  439. if(NULL != pParam1){
  440. FreeMem(pParam1);
  441. pParam1 = NULL;
  442. }
  443. if(NULL != pParam2){
  444. FreeMem(pParam2);
  445. pParam2 = NULL;
  446. }
  447. } // while(FALSE == bFound)
  448. //
  449. // Process until DeviceData = END is found.
  450. //
  451. bFound = FALSE;
  452. while(FALSE == bFound){
  453. ReadString(hFile, &pParam1, &pParam2);
  454. if( (NULL == pParam1) || (NULL == pParam2) ){
  455. lError = ERROR_NOT_ENOUGH_MEMORY;
  456. goto MigNtGetDevice_return;
  457. } // if( (NULL == pParam1) || (NULL == pParam2) )
  458. if( (0 == MyStrCmpiA(pParam1, REGKEY_DEVICEDATA_A))
  459. && (0 == MyStrCmpiA(pParam2, NAME_END_A)) )
  460. {
  461. //
  462. // Found beginning of DeviceData section.
  463. //
  464. bFound = TRUE;
  465. //
  466. // Free allocated memory.
  467. //
  468. if(NULL != pParam1){
  469. FreeMem(pParam1);
  470. pParam1 = NULL;
  471. }
  472. if(NULL != pParam2){
  473. FreeMem(pParam2);
  474. pParam2 = NULL;
  475. }
  476. break;
  477. } // if(0 == MyStrCmpiA(pParam1, REGKEY_DEVICEDATA_A))
  478. //
  479. // Increment counter.
  480. //
  481. dwNumberOfDeviceDataKey++;
  482. //
  483. // Allocate new structure for parameters.
  484. //
  485. pTempParam = (PPARAM_LIST)AllocMem(sizeof(PARAM_LIST));
  486. if(NULL == pTempParam){
  487. lError = ERROR_NOT_ENOUGH_MEMORY;
  488. goto MigNtGetDevice_return;
  489. } // if(NULL == pTempParam)
  490. //
  491. // Set parameters.
  492. //
  493. pTempParam->pNext = NULL;
  494. pTempParam->pParam1 = AllocStrA(pParam1);
  495. pTempParam->pParam2 = AllocStrA(pParam2);
  496. //
  497. // Add this parameter to list.
  498. //
  499. if(NULL == pDeviceDataParam){
  500. pDeviceDataParam = pTempParam;
  501. } else { // if(NULL == pDeviceDataParam)
  502. PPARAM_LIST pTemp;
  503. //
  504. // Find the last data, and add.
  505. //
  506. for(pTemp = pDeviceDataParam; NULL !=pTemp->pNext; pTemp=(PPARAM_LIST)pTemp->pNext);
  507. pTemp->pNext = (PVOID)pTempParam;
  508. } // else(NULL == pDeviceDataParam)
  509. //
  510. // Free allocated memory.
  511. //
  512. if(NULL != pParam1){
  513. FreeMem(pParam1);
  514. pParam1 = NULL;
  515. }
  516. if(NULL != pParam2){
  517. FreeMem(pParam2);
  518. pParam2 = NULL;
  519. }
  520. } // while(FALSE == bFound)
  521. //
  522. // Copy all data.
  523. //
  524. pMigrateDevice->pszFriendlyName = pszFriendlyName;
  525. pMigrateDevice->pszCreateFileName = pszCreateFileName;
  526. pMigrateDevice->pszInfPath = pszInfPath;
  527. pMigrateDevice->pszInfSection = pszInfSection;
  528. pMigrateDevice->dwNumberOfDeviceDataKey = dwNumberOfDeviceDataKey;
  529. pMigrateDevice->pDeviceDataParam = pDeviceDataParam;
  530. //
  531. // Operation succeeded.
  532. //
  533. lError = ERROR_SUCCESS;
  534. MigNtGetDevice_return:
  535. //
  536. // Clean up.
  537. //
  538. if(ERROR_SUCCESS != lError){
  539. PPARAM_LIST pTemp;
  540. //
  541. // Free all allocated parameters.
  542. //
  543. if(NULL != pszFriendlyName){
  544. FreeMem(pszFriendlyName);
  545. }
  546. if(NULL != pszCreateFileName){
  547. FreeMem(pszCreateFileName);
  548. }
  549. if(NULL != pszInfPath){
  550. FreeMem(pszInfPath);
  551. }
  552. if(NULL != pszInfSection){
  553. FreeMem(pszInfSection);
  554. }
  555. if(NULL != pDeviceDataParam){
  556. pTemp = pDeviceDataParam;
  557. while(NULL != pTemp){
  558. pDeviceDataParam = (PPARAM_LIST)pDeviceDataParam->pNext;
  559. FreeMem(pTemp);
  560. pTemp = pDeviceDataParam;
  561. } // while(NULL != pTemp)
  562. } // if(NULL != pDeviceDataParam)
  563. } // if(ERROR_SUCCESS != lError)
  564. if(NULL != pParam1){
  565. FreeMem(pParam1);
  566. }
  567. if(NULL != pParam2){
  568. FreeMem(pParam2);
  569. }
  570. return lError;
  571. } // MigNtGetDevice()
  572. VOID
  573. MigNtFreeDeviceInfo(
  574. PDEVICE_INFO pMigrateDevice
  575. )
  576. {
  577. PPARAM_LIST pCurrent;
  578. PPARAM_LIST pNext;
  579. if(NULL == pMigrateDevice){
  580. goto MigNtFreeDeviceInfo_return;
  581. } // if(NULL == pMigrateDevice)
  582. //
  583. // Free all allocated parameters.
  584. //
  585. if(NULL != pMigrateDevice->pszFriendlyName){
  586. FreeMem(pMigrateDevice->pszFriendlyName);
  587. }
  588. if(NULL != pMigrateDevice->pszCreateFileName){
  589. FreeMem(pMigrateDevice->pszCreateFileName);
  590. }
  591. if(NULL != pMigrateDevice->pszInfPath){
  592. FreeMem(pMigrateDevice->pszInfPath);
  593. }
  594. if(NULL != pMigrateDevice->pszInfSection){
  595. FreeMem(pMigrateDevice->pszInfSection);
  596. }
  597. if(NULL != pMigrateDevice->pDeviceDataParam){
  598. pCurrent = pMigrateDevice->pDeviceDataParam;
  599. while(NULL != pCurrent){
  600. pNext = (PPARAM_LIST)pCurrent->pNext;
  601. FreeMem(pCurrent);
  602. pCurrent = pNext;
  603. } // while(NULL != pTemp)
  604. } // if(NULL != pDeviceDataParam)
  605. //
  606. // Null out the buffer.
  607. //
  608. memset(pMigrateDevice, 0, sizeof(DEVICE_INFO));
  609. MigNtFreeDeviceInfo_return:
  610. return;
  611. } // MigNtFreeDeviceInfo()
  612. BOOL
  613. CALLBACK
  614. MigNtIsWin9xImagingExisting(
  615. VOID
  616. )
  617. {
  618. BOOL bRet;
  619. LONG lError;
  620. HKEY hkKodak;
  621. TCHAR szWindowsDirectory[MAX_PATH];
  622. TCHAR szKodakImaging[MAX_PATH];
  623. DWORD dwVersionInfoSize;
  624. DWORD dwDummy;
  625. PVOID pVersion;
  626. PVOID pFileVersionInfo;
  627. DWORD dwFileVersionInfoSize;
  628. //
  629. // Initialize local.
  630. //
  631. bRet = FALSE;
  632. lError = ERROR_SUCCESS;
  633. dwVersionInfoSize = 0;
  634. dwFileVersionInfoSize = 0;
  635. pVersion = NULL;
  636. pFileVersionInfo = NULL;
  637. memset(szWindowsDirectory, 0, sizeof(szWindowsDirectory));
  638. memset(szKodakImaging, 0, sizeof(szKodakImaging));
  639. //
  640. // Get Windows directory.
  641. //
  642. if(0 == GetWindowsDirectory(szWindowsDirectory, sizeof(szWindowsDirectory)/sizeof(TCHAR))){
  643. lError = GetLastError();
  644. MyLogError("WIA Migration: MigNtIsWin9xImagingExisting: ERROR!! GetWindowsDirectory() failed. Err=0x%x\n", lError);
  645. goto MigNtIsWin9xImagingExisting_return;
  646. } // if(0 == GetWindowsDirectory(szTemp, sizeof(szTemp)/sizeof(TCHAR)))
  647. //
  648. // Create path to Kodak Imaging.
  649. //
  650. // wsprintf(szKodakImaging, "%s\\%s", szWindowsDirectory, NAME_KODAKIMAGING);
  651. _sntprintf(szKodakImaging, sizeof(szKodakImaging)/sizeof(TCHAR), TEXT("%s\\%s"), szWindowsDirectory, NAME_KODAKIMAGING);
  652. //
  653. // Make sure the string is NULL terminated.
  654. //
  655. szKodakImaging[sizeof(szKodakImaging)/sizeof(szKodakImaging[0]) -1] = TEXT('\0');
  656. //
  657. // Get size of version resource of the file.
  658. //
  659. dwVersionInfoSize = GetFileVersionInfoSize(szKodakImaging, &dwDummy);
  660. if(0 == dwVersionInfoSize){
  661. //
  662. // Unable to get version info of the file. Most probably the file doesn't exist.
  663. //
  664. lError = GetLastError();
  665. if(ERROR_FILE_NOT_FOUND == lError){
  666. //
  667. // File doesn't exist. Now it's safe to remove regkey for kodakimg.exe.
  668. //
  669. bRet = TRUE;
  670. } // if(ERROR_FILE_NOT_FOUND == lError)
  671. // MyLogError("WIA Migration: MigNtIsWin9xImagingExisting: ERROR!! GetFileVersionInfoSize() failed. Err=0x%x\n", lError);
  672. goto MigNtIsWin9xImagingExisting_return;
  673. } // if(0 == dwVersionInfoSize)
  674. //
  675. // Allocate required size of buffer.
  676. //
  677. pVersion = AllocMem(dwVersionInfoSize);
  678. if(NULL == pVersion){
  679. lError = ERROR_INSUFFICIENT_BUFFER;
  680. MyLogError("WIA Migration: MigNtIsWin9xImagingExisting: ERROR!! InsufficientBuffer. Err=0x%x\n", lError);
  681. goto MigNtIsWin9xImagingExisting_return;
  682. } // if(NULL == pVersion)
  683. //
  684. // Get version info.
  685. //
  686. if(FALSE == GetFileVersionInfo(szKodakImaging, 0, dwVersionInfoSize, pVersion)){
  687. lError = GetLastError();
  688. MyLogError("WIA Migration: MigNtIsWin9xImagingExisting: ERROR!! GetVersionInfo() failed. Err=0x%x\n", lError);
  689. goto MigNtIsWin9xImagingExisting_return;
  690. } // if(FALSE == GetVersionInfo(szKodakImaging, 0, dwVersionInfoSize, pVersion))
  691. //
  692. // See if the binary is Win9x inbox.
  693. //
  694. if(FALSE == VerQueryValue(pVersion, TEXT("\\"), &pFileVersionInfo, &dwFileVersionInfoSize)){
  695. lError = GetLastError();
  696. MyLogError("WIA Migration: MigNtIsWin9xImagingExisting: ERROR!! VerQueryValue() failed. Err=0x%x\n", lError);
  697. goto MigNtIsWin9xImagingExisting_return;
  698. } // if(FALSE == VerQueryValue(pVersion, TEXT("\\"), &pFileVersionInfo, &dwFileVersionInfoSize))
  699. if( (FILEVER_KODAKIMAGING_WIN98_MS == ((VS_FIXEDFILEINFO *)pFileVersionInfo)->dwFileVersionMS)
  700. && (FILEVER_KODAKIMAGING_WIN98_LS == ((VS_FIXEDFILEINFO *)pFileVersionInfo)->dwFileVersionLS)
  701. && (PRODVER_KODAKIMAGING_WIN98_MS == ((VS_FIXEDFILEINFO *)pFileVersionInfo)->dwProductVersionMS)
  702. && (PRODVER_KODAKIMAGING_WIN98_LS == ((VS_FIXEDFILEINFO *)pFileVersionInfo)->dwProductVersionLS) )
  703. {
  704. //
  705. // This is Win98 inbox Kodak Imaging. Process regkey removal.
  706. //
  707. bRet = TRUE;
  708. } else if( (FILEVER_KODAKIMAGING_WINME_MS == ((VS_FIXEDFILEINFO *)pFileVersionInfo)->dwFileVersionMS)
  709. && (FILEVER_KODAKIMAGING_WINME_LS == ((VS_FIXEDFILEINFO *)pFileVersionInfo)->dwFileVersionLS)
  710. && (PRODVER_KODAKIMAGING_WINME_MS == ((VS_FIXEDFILEINFO *)pFileVersionInfo)->dwProductVersionMS)
  711. && (PRODVER_KODAKIMAGING_WINME_LS == ((VS_FIXEDFILEINFO *)pFileVersionInfo)->dwProductVersionLS) )
  712. {
  713. //
  714. // This is WinMe inbox Kodak Imaging. Process regkey removal.
  715. //
  716. bRet = TRUE;
  717. }
  718. MigNtIsWin9xImagingExisting_return:
  719. //
  720. // Cleanup.
  721. //
  722. if(NULL != pVersion){
  723. FreeMem(pVersion);
  724. } // if(NULL != pVersion)
  725. return bRet;
  726. } // MigNtIsWin9xImagingExisting()
  727. VOID
  728. CALLBACK
  729. MigNtRemoveKodakImagingKey(
  730. VOID
  731. )
  732. {
  733. HMODULE hmShlwapi;
  734. PSHDELETEKEY pfnSHDeleteKey;
  735. //
  736. // Initialize local.
  737. //
  738. hmShlwapi = (HMODULE)NULL;
  739. pfnSHDeleteKey = (PSHDELETEKEY)NULL;
  740. //
  741. // Load shlwapi.dll.
  742. //
  743. hmShlwapi = LoadLibrary(TEXT("shlwapi.dll"));
  744. if(NULL == hmShlwapi){
  745. MyLogError("WIA Migration: MigNtRemoveKodakImagingKey: ERROR!! Unable to load hmShlwapi.dll. Err=0x%x.\n", GetLastError());
  746. goto MigNtRemoveKodakImagingKey_return;
  747. } // if(NULL == hmShlwapi)
  748. //
  749. // Get proc address of SHDeleteKey.
  750. //
  751. pfnSHDeleteKey = (PSHDELETEKEY)GetProcAddress(hmShlwapi, TEXT("SHDeleteKeyA"));
  752. if(NULL == pfnSHDeleteKey){
  753. MyLogError("WIA Migration: MigNtRemoveKodakImagingKey: ERROR!! Unable to find SHDeleteKeyA. Err=0x%x.\n", GetLastError());
  754. goto MigNtRemoveKodakImagingKey_return;
  755. } // if(NULL == hmShlwapi)
  756. //
  757. // Delete key.
  758. //
  759. if(ERROR_SUCCESS != pfnSHDeleteKey(HKEY_LOCAL_MACHINE, REGSTR_PATH_KODAKEVENT_A)){
  760. MyLogError("WIA Migration: MigNtRemoveKodakImagingKey: ERROR!! Unable to delete key. Err=0x%x.\n", GetLastError());
  761. goto MigNtRemoveKodakImagingKey_return;
  762. } // if(ERROR_SUCCESS != pfnSHDeleteKey(HKEY_LOCAL_MACHINE, REGSTR_PATH_KODAKEVENT_A))
  763. MigNtRemoveKodakImagingKey_return:
  764. if(NULL != hmShlwapi){
  765. FreeLibrary(hmShlwapi);
  766. hmShlwapi = NULL;
  767. } // if(NULL != hmShlwapi)
  768. } // MigNtRemoveKodakImagingKey()
  769. //
  770. // The following are to make sure if setup changes the header file they
  771. // first tell me (otherwise they will break build of this)
  772. //
  773. P_INITIALIZE_NT pfnInitializeNT = InitializeNT;
  774. P_MIGRATE_USER_NT pfnMigrateUserNt = MigrateUserNT;
  775. P_MIGRATE_SYSTEM_NT pfnMigrateSystemNT = MigrateSystemNT;