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.

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