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.

893 lines
23 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998.
  5. //
  6. // File: apmdetct.cpp
  7. //
  8. // Contents: Private functions for detection and disabling of APM drivers and
  9. // services from various vendors
  10. //
  11. // Notes:
  12. //
  13. // Author: t-sdey 29 June 98
  14. //
  15. //----------------------------------------------------------------------------
  16. #include <winnt32.h>
  17. #include "apmupgrd.h"
  18. #include "apmrsrc.h"
  19. /******************************************************************************
  20. *
  21. * SYSTEMSOFT DRIVERS
  22. *
  23. ******************************************************************************/
  24. //+---------------------------------------------------------------------------
  25. //
  26. // Function: HrDetectAndDisableSystemSoftAPMDrivers
  27. //
  28. // Purpose: Detect SystemSoft drivers/services which will not work under
  29. // NT 5.0 and disable them.
  30. //
  31. // Arguments:
  32. //
  33. // Returns: S_OK if detect/disable was successful
  34. // S_FALSE if unsuccessful/cancelled -- must ABORT SETUP!
  35. //
  36. // Author: t-sdey 29 June 98
  37. //
  38. // Notes: Services detected: PowerProfiler, CardWizard
  39. //
  40. HRESULT HrDetectAndDisableSystemSoftAPMDrivers()
  41. {
  42. HRESULT hrStatus = S_OK;
  43. // If PowerProfiler is present, pop up a dialog box warning the
  44. // user that it is about to be disabled, and then disable it.
  45. while ((hrStatus == S_OK) && DetectSystemSoftPowerProfiler()) {
  46. int button = DisplayAPMDisableWarningDialog(APM_STR_WARNING_DIALOG_CAPTION,
  47. APM_STR_SYSTEMSOFTPP_DISABLE);
  48. // Check to see if the user clicked "OK"
  49. if (button == IDOK) {
  50. // Disable PowerProfiler
  51. hrStatus = HrDisableSystemSoftPowerProfiler();
  52. } else {
  53. // The user clicked "Cancel"
  54. hrStatus = S_FALSE;
  55. }
  56. }
  57. // If CardWizard is present, pop up a dialog box warning the
  58. // user that it is about to be disabled, and then disable it.
  59. while ((hrStatus == S_OK) && DetectSystemSoftCardWizard()) {
  60. int button = DisplayAPMDisableWarningDialog(APM_STR_WARNING_DIALOG_CAPTION,
  61. APM_STR_SYSTEMSOFTCW_DISABLE);
  62. // Check to see if the user clicked "OK"
  63. if (button == IDOK) {
  64. // Disable PowerProfiler
  65. hrStatus = HrDisableSystemSoftCardWizard();
  66. } else {
  67. // The user clicked "Cancel"
  68. hrStatus = S_FALSE;
  69. }
  70. }
  71. return hrStatus;
  72. }
  73. //+---------------------------------------------------------------------------
  74. //
  75. // Function: DetectSystemSoftPowerProfiler
  76. //
  77. // Purpose: Detect SystemSoft PowerProfiler, which will not work under NT 5.0.
  78. //
  79. // Arguments:
  80. //
  81. // Returns: TRUE if PowerProfiler is detected
  82. // FALSE otherwise
  83. //
  84. // Author: t-sdey 2 July 98
  85. //
  86. // Notes:
  87. //
  88. BOOL DetectSystemSoftPowerProfiler()
  89. {
  90. BOOL fFound = FALSE;
  91. // Look in the registry to see if PowerProfiler is present
  92. HKEY hkPP = NULL;
  93. HKEY hkPPUninst = NULL;
  94. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  95. TEXT("SOFTWARE\\SystemSoft\\PowerProfiler"),
  96. 0,
  97. KEY_READ,
  98. &hkPP) == ERROR_SUCCESS) {
  99. /* Also look for the uninstall utility, because sometimes "ghosts" of
  100. PowerProfiler stay in the registry at
  101. HKLM\Software\SystemSoft\PowerProfiler after it has been uninstalled.
  102. If the uninstall utility is present, then we assume that PowerProfiler
  103. really is there. -- Do we need to triple-check???
  104. */
  105. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  106. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\PowerProNT1DeinstKey"),
  107. 0,
  108. KEY_READ,
  109. &hkPP) == ERROR_SUCCESS) {
  110. // Found PowerProfiler
  111. fFound = TRUE;
  112. }
  113. }
  114. if (hkPP)
  115. RegCloseKey(hkPP);
  116. if (hkPPUninst)
  117. RegCloseKey(hkPPUninst);
  118. return fFound;
  119. }
  120. //+---------------------------------------------------------------------------
  121. //
  122. // Function: HrDisableSystemSoftPowerProfiler
  123. //
  124. // Purpose: Disable SystemSoft PowerProfiler, which will not work under NT 5.0.
  125. //
  126. // Arguments:
  127. //
  128. // Returns: S_OK if disable was successful
  129. // S_FALSE if unsuccessful -- must ABORT SETUP!
  130. //
  131. // Author: t-sdey 29 June 98
  132. //
  133. // Notes:
  134. //
  135. HRESULT HrDisableSystemSoftPowerProfiler()
  136. {
  137. // Call the uninstall function in the registry
  138. if (CallUninstallFunction(TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\PowerProNT1DeinstKey"),
  139. TEXT("\" -a")) == S_OK) {
  140. // Uninstall worked
  141. return S_OK;
  142. } else {
  143. // An error occurred
  144. return S_FALSE;
  145. }
  146. }
  147. //+---------------------------------------------------------------------------
  148. //
  149. // Function: DetectSystemSoftCardWizard
  150. //
  151. // Purpose: Detect SystemSoft CardWizard, which will not work under NT 5.0.
  152. //
  153. // Arguments:
  154. //
  155. // Returns: TRUE if CardWizard is detected
  156. // FALSE otherwise
  157. //
  158. // Author: t-sdey 7 July 98
  159. //
  160. // Notes:
  161. //
  162. BOOL DetectSystemSoftCardWizard()
  163. {
  164. BOOL fFound = FALSE;
  165. // Look in the registry to see if CardWizard is present
  166. HKEY hkCW = NULL;
  167. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  168. TEXT("SOFTWARE\\SystemSoft\\CardWizard for Windows NT"),
  169. 0,
  170. KEY_READ,
  171. &hkCW) == ERROR_SUCCESS) {
  172. // Found CardWizard
  173. fFound = TRUE;
  174. }
  175. if (hkCW)
  176. RegCloseKey(hkCW);
  177. return fFound;
  178. }
  179. //+---------------------------------------------------------------------------
  180. //
  181. // Function: HrDisableSystemSoftCardWizard
  182. //
  183. // Purpose: Disable SystemSoft CardWizard, which will not work under NT 5.0.
  184. //
  185. // Arguments:
  186. //
  187. // Returns: S_OK if disable was successful
  188. // S_FALSE if unsuccessful -- must ABORT SETUP!
  189. //
  190. // Author: t-sdey 7 July 98
  191. //
  192. // Notes:
  193. //
  194. HRESULT HrDisableSystemSoftCardWizard()
  195. {
  196. HRESULT hrStatus = S_OK;
  197. // Use the registry to locate the CardWizard uninstall utility
  198. if (CallUninstallFunction(TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\CardWizard for Windows NT"),
  199. TEXT(" -a")) == S_OK) {
  200. // Uninstall worked
  201. return S_OK;
  202. } else {
  203. // Could not find (or could not run) CardWizard uninstall utility -
  204. // do it by hand :(
  205. // This case happens if someone has CardWizard 2.0, which has no uninstall
  206. /*
  207. * REMOVE ALL CARDWIZARD KEYS FROM THE REGISTRY
  208. */
  209. HKEY hkCW = NULL;
  210. // Go down the list of registry keys that are supposed to be there and
  211. // delete them if they are present.
  212. if (RegOpenKeyEx(HKEY_USERS,
  213. TEXT(".DEFAULT\\Software\\SystemSoft"),
  214. 0,
  215. KEY_WRITE,
  216. &hkCW) == ERROR_SUCCESS) {
  217. DeleteRegKeyAndSubkeys(hkCW, TEXT("CardWizard for Windows NT"));
  218. RegCloseKey(hkCW);
  219. }
  220. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  221. TEXT("SOFTWARE\\SystemSoft"),
  222. 0,
  223. KEY_ALL_ACCESS,
  224. &hkCW) == ERROR_SUCCESS) {
  225. DeleteRegKeyAndSubkeys(hkCW, TEXT("CardWizard for Windows NT"));
  226. }
  227. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  228. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
  229. 0,
  230. KEY_WRITE,
  231. &hkCW) == ERROR_SUCCESS) {
  232. RegDeleteValue(hkCW, TEXT("CardView"));
  233. RegCloseKey(hkCW);
  234. }
  235. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  236. TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon"),
  237. 0,
  238. KEY_ALL_ACCESS,
  239. &hkCW) == ERROR_SUCCESS) {
  240. // Flag to stop this key adjustment without stopping the whole removal process
  241. BOOL fStop = FALSE;
  242. // First, we get the string
  243. const long c_lMax = (65535 / sizeof(TCHAR)) + 1;
  244. TCHAR* szVal;
  245. szVal = new TCHAR[c_lMax];
  246. if (!szVal) {
  247. // Out of memory
  248. hrStatus = S_FALSE;
  249. fStop = TRUE;
  250. }
  251. DWORD dwValType;
  252. DWORD dwValSz = c_lMax;
  253. if ((!fStop) && (RegQueryValueEx(hkCW,
  254. TEXT("UserInit"),
  255. NULL,
  256. &dwValType,
  257. (LPBYTE)szVal,
  258. &dwValSz) != ERROR_SUCCESS)) {
  259. // Some error occurred
  260. hrStatus = S_FALSE;
  261. fStop = TRUE;
  262. }
  263. // Construct our substring to be removed. It will be something like
  264. // ",C:\Program Files\SystemSoft\CardWizard\WizNT.exe -L". But we can't
  265. // be sure it's in that directory, so we have to look for the beginning
  266. // comma and the "WizNT.exe -L".
  267. TCHAR* szSubString = NULL;
  268. if (!fStop) {
  269. // Find the start and end characters
  270. TCHAR* pszStart = NULL;
  271. TCHAR* pszEnd = NULL;
  272. pszEnd = _tcsstr(szVal, TEXT("WizNT.exe -L"));
  273. if (pszEnd) {
  274. pszEnd = pszEnd + 12;
  275. } else {
  276. // Did not find the string; don't continue trying to remove it
  277. fStop = TRUE;
  278. }
  279. if (!fStop) {
  280. TCHAR* pszTemp = szVal;
  281. while (pszTemp < pszEnd) {
  282. pszStart = pszTemp;
  283. pszTemp = _tcsstr(pszStart + 1, TEXT(","));
  284. if (!pszTemp)
  285. break;
  286. }
  287. if (pszStart == NULL) {
  288. // There was some error
  289. fStop = TRUE;
  290. }
  291. }
  292. // Copy into a new string
  293. if (!fStop) {
  294. int sslen = (int)(pszEnd - pszStart);
  295. szSubString = new TCHAR[sslen + 1];
  296. for (int i = 0; i < sslen; i++) {
  297. szSubString[i] = pszStart[i];
  298. }
  299. szSubString[i] = '\0';
  300. }
  301. }
  302. // Finally we search the string to find our substring and construct a new
  303. // one with the substring removed
  304. TCHAR* szRemoved = NULL;
  305. if (!fStop) {
  306. // We can't really assume this is the exact string, can we??
  307. if (RemoveSubString(szVal, szSubString, &szRemoved)) {
  308. // Store the result in the registry
  309. RegSetValueEx(hkCW,
  310. TEXT("UserInit"),
  311. NULL,
  312. REG_SZ,
  313. (LPBYTE)szRemoved,
  314. (lstrlen(szRemoved) + 1) * sizeof(TCHAR));
  315. }
  316. }
  317. // Clean up
  318. if (szVal)
  319. delete[] szVal;
  320. if (szSubString)
  321. delete[] szSubString;
  322. if (szRemoved)
  323. delete[] szRemoved;
  324. RegCloseKey(hkCW);
  325. }
  326. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  327. TEXT("SYSTEM\\CurrentControlSet\\Control\\GroupOrderList"),
  328. 0,
  329. KEY_WRITE,
  330. &hkCW) == ERROR_SUCCESS) {
  331. // Is it safe to delete this value?
  332. RegDeleteValue(hkCW, TEXT("System Bus Extender"));
  333. RegCloseKey(hkCW);
  334. }
  335. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  336. TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application"),
  337. 0,
  338. KEY_WRITE,
  339. &hkCW) == ERROR_SUCCESS) {
  340. RegDeleteKey(hkCW, TEXT("DrvMgr"));
  341. RegCloseKey(hkCW);
  342. }
  343. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  344. TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\System"),
  345. 0,
  346. KEY_WRITE,
  347. &hkCW) == ERROR_SUCCESS) {
  348. RegDeleteKey(hkCW, TEXT("FlashCrd"));
  349. RegDeleteKey(hkCW, TEXT("PatDisk"));
  350. RegDeleteKey(hkCW, TEXT("PCCard"));
  351. RegDeleteKey(hkCW, TEXT("PCICnfg"));
  352. RegDeleteKey(hkCW, TEXT("Platform"));
  353. RegDeleteKey(hkCW, TEXT("PSerial"));
  354. RegDeleteKey(hkCW, TEXT("Resman"));
  355. RegDeleteKey(hkCW, TEXT("SRAMCard"));
  356. RegDeleteKey(hkCW, TEXT("SSCrdBus"));
  357. RegDeleteKey(hkCW, TEXT("SSI365"));
  358. RegCloseKey(hkCW);
  359. }
  360. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  361. TEXT("SYSTEM\\CurrentControlSet\\Services"),
  362. 0,
  363. KEY_WRITE,
  364. &hkCW) == ERROR_SUCCESS) {
  365. DeleteRegKeyAndSubkeys(hkCW, TEXT("FlashCrd"));
  366. DeleteRegKeyAndSubkeys(hkCW, TEXT("patdisk"));
  367. DeleteRegKeyAndSubkeys(hkCW, TEXT("PCCard"));
  368. DeleteRegKeyAndSubkeys(hkCW, TEXT("PCICnfg"));
  369. DeleteRegKeyAndSubkeys(hkCW, TEXT("Platform"));
  370. DeleteRegKeyAndSubkeys(hkCW, TEXT("pndis"));
  371. DeleteRegKeyAndSubkeys(hkCW, TEXT("pserial"));
  372. DeleteRegKeyAndSubkeys(hkCW, TEXT("resman"));
  373. DeleteRegKeyAndSubkeys(hkCW, TEXT("SRAMCard"));
  374. DeleteRegKeyAndSubkeys(hkCW, TEXT("SSCrdBus"));
  375. DeleteRegKeyAndSubkeys(hkCW, TEXT("SSI365"));
  376. RegCloseKey(hkCW);
  377. }
  378. /*
  379. * REMOVE CARDWIZARD FROM THE SYSTEM TRAY??
  380. */
  381. /*
  382. * REMOVE CARDWIZARD LINKS FROM THE START MENU
  383. */
  384. /*
  385. * REMOVE CARDWIZARD FILES FROM THE COMPUTER
  386. */
  387. // Now, no matter how much of the above failed, CardWizard is disabled
  388. hrStatus = S_OK;
  389. }
  390. return hrStatus;
  391. }
  392. /******************************************************************************
  393. *
  394. * AWARD DRIVERS
  395. *
  396. ******************************************************************************/
  397. //+---------------------------------------------------------------------------
  398. //
  399. // Function: HrDetectAndDisableAwardAPMDrivers
  400. //
  401. // Purpose: Detect Award APM drivers/services which will not work under
  402. // NT 5.0 and disable them.
  403. //
  404. // Arguments:
  405. //
  406. // Returns: S_OK if detect/disable was successful
  407. // S_FALSE if unsuccessful/cancelled -- must ABORT SETUP!
  408. //
  409. // Author: t-sdey 6 July 98
  410. //
  411. // Notes: Services detected: CardWare
  412. //
  413. HRESULT HrDetectAndDisableAwardAPMDrivers()
  414. {
  415. HRESULT hrStatus = S_OK;
  416. // If Award CardWare is present, pop up a dialog box warning the
  417. // user that it is about to be disabled, and then disable it.
  418. while (DetectAwardCardWare() && (hrStatus == S_OK)) {
  419. int button = DisplayAPMDisableWarningDialog(APM_STR_WARNING_DIALOG_CAPTION,
  420. APM_STR_AWARDCW_DISABLE);
  421. // Check to see if the user clicked "OK"
  422. if (button == IDOK) {
  423. // Disable PowerProfiler
  424. hrStatus = HrDisableAwardCardWare();
  425. } else {
  426. // The user clicked "Cancel"
  427. hrStatus = S_FALSE;
  428. }
  429. }
  430. return hrStatus;
  431. }
  432. //+---------------------------------------------------------------------------
  433. //
  434. // Function: DetectAwardCardWare
  435. //
  436. // Purpose: Detect Award CardWare, which will not work under NT 5.0.
  437. //
  438. // Arguments:
  439. //
  440. // Returns: TRUE if CardWare is detected
  441. // FALSE otherwise
  442. //
  443. // Author: t-sdey 6 July 98
  444. //
  445. // Notes:
  446. //
  447. BOOL DetectAwardCardWare()
  448. {
  449. BOOL fFound = FALSE;
  450. // Look in the registry to see if CardWare is present
  451. HKEY hkCWUninst = NULL;
  452. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  453. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\CardWare"),
  454. 0,
  455. KEY_READ,
  456. &hkCWUninst) == ERROR_SUCCESS) {
  457. // Found CardWare
  458. fFound = TRUE;
  459. }
  460. if (hkCWUninst)
  461. RegCloseKey(hkCWUninst);
  462. return fFound;
  463. }
  464. //+---------------------------------------------------------------------------
  465. //
  466. // Function: HrDisableAwardCardWare
  467. //
  468. // Purpose: Disable Award CardWare, which will not work under NT 5.0.
  469. //
  470. // Arguments:
  471. //
  472. // Returns: S_OK if disable was successful
  473. // S_FALSE if unsuccessful -- must ABORT SETUP!
  474. //
  475. // Author: t-sdey 6 July 98
  476. //
  477. // Notes:
  478. //
  479. HRESULT HrDisableAwardCardWare()
  480. {
  481. if (CallUninstallFunction(TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\CardWare"),
  482. TEXT(" -a")) == S_OK) {
  483. // Uninstall worked
  484. return S_OK;
  485. } else {
  486. // An error occurred
  487. return S_FALSE;
  488. }
  489. }
  490. /******************************************************************************
  491. *
  492. * SOFTEX DRIVERS
  493. *
  494. ******************************************************************************/
  495. //+---------------------------------------------------------------------------
  496. //
  497. // Function: HrDetectAndDisableSoftexAPMDrivers
  498. //
  499. // Purpose: Detect Softex drivers/services which will not work under
  500. // NT 5.0 and disable them.
  501. //
  502. // Arguments:
  503. //
  504. // Returns: S_OK if detect/disable was successful
  505. // S_FALSE if unsuccessful/cancelled -- must ABORT SETUP!
  506. //
  507. // Author: t-sdey 6 July 98
  508. //
  509. // Notes: Services detected: Phoenix
  510. //
  511. HRESULT HrDetectAndDisableSoftexAPMDrivers()
  512. {
  513. HRESULT hrStatus = S_OK;
  514. // If Softex Phoenix is present, pop up a dialog box warning the
  515. // user that it is about to be disabled, and then disable it.
  516. while (DetectSoftexPhoenix() && (hrStatus == S_OK)) {
  517. int button = DisplayAPMDisableWarningDialog(APM_STR_WARNING_DIALOG_CAPTION,
  518. APM_STR_SOFTEXP_DISABLE);
  519. // Check to see if the user clicked "OK"
  520. if (button == IDOK) {
  521. // Disable Phoenix
  522. hrStatus = HrDisableSoftexPhoenix();
  523. } else {
  524. // The user clicked "Cancel"
  525. hrStatus = S_FALSE;
  526. }
  527. }
  528. return hrStatus;
  529. }
  530. //+---------------------------------------------------------------------------
  531. //
  532. // Function: DetectSoftexPhoenix
  533. //
  534. // Purpose: Detect Softex Phoenix, which will not work under NT 5.0.
  535. //
  536. // Arguments:
  537. //
  538. // Returns: TRUE if Softex Phoenix is detected
  539. // FALSE otherwise
  540. //
  541. // Author: t-sdey 6 July 98
  542. //
  543. // Notes:
  544. //
  545. BOOL DetectSoftexPhoenix()
  546. {
  547. BOOL fFound = FALSE;
  548. // Look for a couple of keys in the registry
  549. HKEY hkPhoenix = NULL;
  550. if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  551. TEXT("SYSTEM\\CurrentControlSet\\Services\\pwrstart"),
  552. 0,
  553. KEY_READ,
  554. &hkPhoenix) == ERROR_SUCCESS) ||
  555. (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  556. TEXT("SYSTEM\\CurrentControlSet\\Services\\power"),
  557. 0,
  558. KEY_READ,
  559. &hkPhoenix) == ERROR_SUCCESS)) {
  560. fFound = TRUE;
  561. }
  562. if (hkPhoenix)
  563. RegCloseKey(hkPhoenix);
  564. return fFound;
  565. }
  566. //+---------------------------------------------------------------------------
  567. //
  568. // Function: HrDisableSoftexPhoenix
  569. //
  570. // Purpose: Disable Softex Phoenix, which will not work under NT 5.0.
  571. //
  572. // Arguments:
  573. //
  574. // Returns: S_OK if disable was successful
  575. // S_FALSE if unsuccessful -- must ABORT SETUP!
  576. //
  577. // Author: t-sdey 6 July 98
  578. //
  579. // Notes:
  580. //
  581. HRESULT HrDisableSoftexPhoenix()
  582. {
  583. // Call the uninstall function in the registry
  584. if (CallUninstallFunction(TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Softex APM Software"),
  585. NULL) == S_OK) {
  586. // Uninstall worked
  587. return S_OK;
  588. }
  589. // Could not find (or could not run) Phoenix uninstall - do it by hand :(
  590. HRESULT hrStatus = S_OK;
  591. // Delete registry entries
  592. HKEY hkPhoenix = NULL;
  593. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  594. TEXT("SYSTEM\\CurrentControlSet\\Services"),
  595. 0,
  596. KEY_WRITE,
  597. &hkPhoenix) == ERROR_SUCCESS) {
  598. DeleteRegKeyAndSubkeys(hkPhoenix, TEXT("pwrstart"));
  599. DeleteRegKeyAndSubkeys(hkPhoenix, TEXT("power"));
  600. RegCloseKey(hkPhoenix);
  601. }
  602. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  603. TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon"),
  604. 0,
  605. KEY_WRITE,
  606. &hkPhoenix) == ERROR_SUCCESS) {
  607. // First, we get the string
  608. DWORD dwValType;
  609. const long c_lMax = (65535 / sizeof(TCHAR)) + 1;
  610. DWORD dwValSz = c_lMax;
  611. TCHAR* szComplete = new TCHAR[c_lMax];
  612. if (!szComplete) {
  613. // Out of memory
  614. RegCloseKey(hkPhoenix);
  615. return (S_FALSE);
  616. }
  617. if (RegQueryValueEx(hkPhoenix,
  618. TEXT("UserInit"),
  619. NULL,
  620. &dwValType,
  621. (LPBYTE) szComplete,
  622. &dwValSz) != ERROR_SUCCESS) {
  623. // Some error occurred
  624. hrStatus = S_FALSE;
  625. }
  626. // Now we search the string to find our substring and construct a new
  627. // one with the substring removed
  628. TCHAR* szRemoved = NULL;
  629. if (hrStatus == S_OK) {
  630. if (!RemoveSubString(szComplete, TEXT(",power"), &szRemoved))
  631. hrStatus = S_FALSE;
  632. else {
  633. // Store the result in the registry
  634. hrStatus = RegSetValueEx(hkPhoenix,
  635. TEXT("UserInit"),
  636. NULL,
  637. REG_SZ,
  638. (LPBYTE)szRemoved,
  639. (lstrlen(szRemoved) + 1) * sizeof(TCHAR));
  640. }
  641. }
  642. // Clean up
  643. if (szRemoved)
  644. delete[] szRemoved;
  645. if (szComplete)
  646. delete[] szComplete;
  647. RegCloseKey(hkPhoenix);
  648. }
  649. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  650. TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon"),
  651. 0,
  652. KEY_WRITE,
  653. &hkPhoenix) == ERROR_SUCCESS) {
  654. RegSetValueEx(hkPhoenix,
  655. TEXT("PowerdownAfterShutdown"),
  656. NULL,
  657. REG_SZ,
  658. (LPBYTE)TEXT("0"),
  659. 2*sizeof(TCHAR));
  660. RegCloseKey(hkPhoenix);
  661. }
  662. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  663. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
  664. 0,
  665. KEY_WRITE,
  666. &hkPhoenix) == ERROR_SUCCESS) {
  667. RegDeleteValue(hkPhoenix, TEXT("power"));
  668. RegCloseKey(hkPhoenix);
  669. }
  670. // Delete files in system directory
  671. /*
  672. ' delete .cpl file
  673. On Error Resume Next
  674. Kill gstrWinSysDir & "power.cpl"
  675. On Error Resume Next
  676. Name (gstrWinSysDir & "power.cpl") As (gstrWinSysDir & "power.cpk")
  677. */
  678. return hrStatus;
  679. }
  680. /******************************************************************************
  681. *
  682. * IBM DRIVERS
  683. *
  684. ******************************************************************************/
  685. //+---------------------------------------------------------------------------
  686. //
  687. // Function: HrDetectAndDisableIBMAPMDrivers
  688. //
  689. // Purpose: Detect IBM APM drivers/services which will not work under
  690. // NT 5.0 and disable them.
  691. //
  692. // Arguments:
  693. //
  694. // Returns: S_OK if detect/disable was successful
  695. // S_FALSE if unsuccessful/cancelled -- must ABORT SETUP!
  696. //
  697. // Author: t-sdey 13 July 98
  698. //
  699. // Notes:
  700. //
  701. HRESULT HrDetectAndDisableIBMAPMDrivers()
  702. {
  703. HRESULT hrStatus = S_OK;
  704. // If IBM drivers are present, pop up a dialog box warning the
  705. // user that they are about to be disabled, and then disable them.
  706. while (DetectIBMDrivers() && (hrStatus == S_OK)) {
  707. int button = DisplayAPMDisableWarningDialog(APM_STR_WARNING_DIALOG_CAPTION,
  708. APM_STR_IBM_DISABLE);
  709. // Check to see if the user clicked "OK"
  710. if (button == IDOK) {
  711. // Disable PowerProfiler
  712. hrStatus = HrDisableIBMDrivers();
  713. } else {
  714. // The user clicked "Cancel"
  715. hrStatus = S_FALSE;
  716. }
  717. }
  718. return hrStatus;
  719. }
  720. //+---------------------------------------------------------------------------
  721. //
  722. // Function: DetectIBMDrivers
  723. //
  724. // Purpose: Detect IBM APM drivers which will not work under NT 5.0.
  725. //
  726. // Arguments:
  727. //
  728. // Returns: TRUE if drivers are detected
  729. // FALSE otherwise
  730. //
  731. // Author: t-sdey 13 July 98
  732. //
  733. // Notes:
  734. //
  735. BOOL DetectIBMDrivers()
  736. {
  737. BOOL fFound = FALSE;
  738. // Look in the registry to see if IBM drivers are present
  739. HKEY hkIBM = NULL;
  740. if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  741. TEXT("SYSTEM\\CurrentControlSet\\Services\\TpChrSrv"),
  742. 0,
  743. KEY_READ,
  744. &hkIBM) == ERROR_SUCCESS) ||
  745. (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  746. TEXT("SYSTEM\\CurrentControlSet\\Services\\TpPmPort"),
  747. 0,
  748. KEY_READ,
  749. &hkIBM) == ERROR_SUCCESS)) {
  750. // Found driver(s)
  751. fFound = TRUE;
  752. }
  753. if (hkIBM)
  754. RegCloseKey(hkIBM);
  755. return fFound;
  756. }
  757. //+---------------------------------------------------------------------------
  758. //
  759. // Function: HrDisableIBMDrivers
  760. //
  761. // Purpose: Disable IBM APM drivers which will not work under NT 5.0.
  762. //
  763. // Arguments:
  764. //
  765. // Returns: S_OK if disable was successful
  766. // S_FALSE if unsuccessful -- must ABORT SETUP!
  767. //
  768. // Author: t-sdey 13 July 98
  769. //
  770. // Notes:
  771. //
  772. HRESULT HrDisableIBMDrivers()
  773. {
  774. HRESULT hrStatus = S_OK;
  775. HKEY hkIBM = NULL;
  776. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  777. TEXT("SYSTEM\\CurrentControlSet\\Services"),
  778. 0,
  779. KEY_WRITE,
  780. &hkIBM) == ERROR_SUCCESS) {
  781. DeleteRegKeyAndSubkeys(hkIBM, TEXT("TpChrSrv"));
  782. DeleteRegKeyAndSubkeys(hkIBM, TEXT("TpPmPort"));
  783. RegCloseKey(hkIBM);
  784. } else {
  785. hrStatus = S_FALSE;
  786. }
  787. return hrStatus;
  788. }