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.

2160 lines
70 KiB

  1. //-------------------------------------------------------------------
  2. //
  3. // File:
  4. //
  5. // Summary;
  6. //
  7. // Notes;
  8. //
  9. // History
  10. //
  11. //-------------------------------------------------------------------
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <setupapi.h>
  15. #include <syssetup.h>
  16. #include "resource.h"
  17. #include "ctls.h"
  18. #ifdef UNICODE
  19. # define TSTR_FMT "%ls"
  20. #else
  21. # define TSTR_FMT "%s"
  22. #endif
  23. static
  24. BOOL
  25. TestInteractive(
  26. NETSETUPPAGEREQUESTPROC pfnRequestPages );
  27. static
  28. BOOL
  29. TestBatch(
  30. NETSETUPPAGEREQUESTPROC pfnRequestPages );
  31. static
  32. BOOL
  33. CALLBACK
  34. StartPageDlgProc(
  35. HWND hdlg,
  36. UINT msg,
  37. WPARAM wParam,
  38. LPARAM lParam );
  39. static
  40. BOOL
  41. CALLBACK
  42. FinishPageDlgProc(
  43. HWND hdlg,
  44. UINT msg,
  45. WPARAM wParam,
  46. LPARAM lParam );
  47. static
  48. void
  49. SetLargeDialogFont(
  50. HWND hdlg,
  51. UINT ControlId );
  52. static
  53. BOOL
  54. LicenseKeysSave();
  55. static
  56. BOOL
  57. LicenseKeysDelete();
  58. static
  59. BOOL
  60. LicenseKeysRestore();
  61. static
  62. BOOL
  63. LicenseKeysVerify(
  64. BOOL fShouldBePresent,
  65. BOOL fLicensePerServer,
  66. DWORD cPerServerLicenses );
  67. static
  68. DWORD
  69. MyRegDeleteKey(
  70. HKEY hKeyParent,
  71. LPCTSTR pcszKeyName );
  72. TCHAR g_szWizardTitle[] = TEXT( "License Setup Test" );
  73. TCHAR g_szKeyLicenseService[] = TEXT( "System\\CurrentControlSet\\Services\\LicenseService" );
  74. TCHAR g_szKeyLicenseInfo[] = TEXT( "System\\CurrentControlSet\\Services\\LicenseInfo" );
  75. TCHAR g_szKeyEventLog[] = TEXT( "System\\CurrentControlSet\\Services\\EventLog\\Application\\LicenseService" );
  76. LPTSTR g_apszKeys[] =
  77. {
  78. g_szKeyLicenseService,
  79. g_szKeyLicenseInfo,
  80. g_szKeyEventLog,
  81. NULL
  82. };
  83. TCHAR g_szTempPath[ 1 + MAX_PATH ];
  84. // paths to file in which to save license registry information
  85. TCHAR g_szKeyFileLicenseService[ 1 + MAX_PATH ];
  86. TCHAR g_szKeyFileLicenseInfo[ 1 + MAX_PATH ];
  87. TCHAR g_szKeyFileEventLog[ 1 + MAX_PATH ];
  88. int _cdecl main( int argc, char *argv[ ], char *envp[ ] )
  89. {
  90. BOOL fSuccess;
  91. HINSTANCE hLicCpa;
  92. NETSETUPPAGEREQUESTPROC pfnRequestPages;
  93. BOOL fIsInteractive;
  94. BOOL fIsUsage;
  95. BOOL fIsRestore;
  96. LPSTR pszBadArg;
  97. printf( "\nLicense Setup Wizard Page Test for LICCPA.CPL\n\n" );
  98. fIsInteractive = FALSE;
  99. fIsUsage = FALSE;
  100. fIsRestore = FALSE;
  101. pszBadArg = NULL;
  102. if ( 1 == argc )
  103. {
  104. printf( "Use \"%s /?\" for a list of command-line options.\n\n", argv[ 0 ] );
  105. }
  106. else
  107. {
  108. int cCurArg;
  109. LPSTR * ppszCurArg;
  110. for ( cCurArg = 1, ppszCurArg = argv;
  111. ( ( !fIsUsage )
  112. && ( NULL == pszBadArg )
  113. && ( cCurArg < argc ) );
  114. cCurArg++ )
  115. {
  116. ++ppszCurArg;
  117. if ( ( ( '-' == (*ppszCurArg)[ 0 ] )
  118. || ( '/' == (*ppszCurArg)[ 0 ] ) )
  119. && ( '\0' != (*ppszCurArg)[ 1 ] ) )
  120. {
  121. DWORD cchOption;
  122. cchOption = strlen( &( (*ppszCurArg)[ 1 ] ) );
  123. if ( !_strnicmp( &( (*ppszCurArg)[ 1 ] ), "interactive", min( cchOption, strlen( "interactive" ) ) ) )
  124. {
  125. fIsInteractive = TRUE;
  126. }
  127. else if ( !_strnicmp( &( (*ppszCurArg)[ 1 ] ), "help", min( cchOption, strlen( "help" ) ) )
  128. || !_strnicmp( &( (*ppszCurArg)[ 1 ] ), "?", min( cchOption, strlen( "?" ) ) ) )
  129. {
  130. fIsUsage = TRUE;
  131. }
  132. else if ( !_strnicmp( &( (*ppszCurArg)[ 1 ] ), "restore", min( cchOption, strlen( "restore" ) ) ) )
  133. {
  134. fIsRestore = TRUE;
  135. }
  136. else
  137. {
  138. pszBadArg = *ppszCurArg;
  139. }
  140. }
  141. else
  142. {
  143. pszBadArg = *ppszCurArg;
  144. }
  145. }
  146. }
  147. if ( NULL != pszBadArg )
  148. {
  149. printf( "The argument \"%s\" is unrecognized.\n"
  150. "Use \"%s /?\" for a list of command-line options.\n",
  151. pszBadArg,
  152. argv[ 0 ] );
  153. fSuccess = FALSE;
  154. }
  155. else if ( fIsUsage )
  156. {
  157. printf( "Options: [ /? | /H | /HELP ] Display option list.\n"
  158. " [ /INTERACTIVE ] Test the wizard page interactively.\n"
  159. " [ /RESTORE ] Restore licensing registry keys in the\n"
  160. " event that a program error kept them from\n"
  161. " being restored in a previous run.\n" );
  162. fSuccess = TRUE;
  163. }
  164. else
  165. {
  166. DWORD cchTempPath;
  167. fSuccess = FALSE;
  168. cchTempPath = GetTempPath( sizeof( g_szTempPath ) / sizeof( *g_szTempPath ), g_szTempPath );
  169. if ( 0 == cchTempPath )
  170. {
  171. printf( "GetTempPath() failed, error %lu.\n", GetLastError() );
  172. }
  173. else
  174. {
  175. lstrcpy( g_szKeyFileLicenseService, g_szTempPath );
  176. lstrcpy( g_szKeyFileLicenseInfo, g_szTempPath );
  177. lstrcpy( g_szKeyFileEventLog, g_szTempPath );
  178. lstrcat( g_szKeyFileLicenseService, TEXT( "jbplskey" ) );
  179. lstrcat( g_szKeyFileLicenseInfo, TEXT( "jbplikey" ) );
  180. lstrcat( g_szKeyFileEventLog, TEXT( "jbpelkey" ) );
  181. if ( fIsRestore )
  182. {
  183. fSuccess = LicenseKeysRestore();
  184. }
  185. else
  186. {
  187. BOOL ok;
  188. fSuccess = FALSE;
  189. // init common control library
  190. InitCommonControls();
  191. ok = InitializeBmpClass();
  192. if ( !ok )
  193. {
  194. printf( "InitializeBmpClass() Failed!\n" );
  195. }
  196. else
  197. {
  198. hLicCpa = LoadLibrary( TEXT( "LicCpa.Cpl" ) );
  199. if ( NULL == hLicCpa )
  200. {
  201. printf( "LoadLibary() Failed!\n" );
  202. }
  203. else
  204. {
  205. pfnRequestPages = (NETSETUPPAGEREQUESTPROC) GetProcAddress( hLicCpa, "LicenseSetupRequestWizardPages" );
  206. if ( NULL == pfnRequestPages )
  207. {
  208. printf( "GetProcAddress() Failed!\n" );
  209. }
  210. else if ( fIsInteractive )
  211. {
  212. fSuccess = TestInteractive( pfnRequestPages );
  213. }
  214. else
  215. {
  216. fSuccess = TestBatch( pfnRequestPages );
  217. }
  218. FreeLibrary( hLicCpa );
  219. }
  220. }
  221. if ( fSuccess )
  222. {
  223. printf( "\nTest completed successfully.\n" );
  224. }
  225. else
  226. {
  227. printf( "\nTest failed!\n" );
  228. }
  229. }
  230. }
  231. }
  232. return fSuccess ? 0 : -1;
  233. }
  234. static
  235. BOOL
  236. TestInteractive(
  237. NETSETUPPAGEREQUESTPROC pfnRequestPages )
  238. {
  239. BOOL fSuccess;
  240. UINT chpages;
  241. INTERNAL_SETUP_DATA SetupData;
  242. BOOL ok;
  243. fSuccess = LicenseKeysSave();
  244. if ( fSuccess )
  245. {
  246. SetupData.dwSizeOf = sizeof( SetupData );
  247. SetupData.SetupMode = SETUPMODE_CUSTOM;
  248. SetupData.ProductType = PRODUCT_SERVER_PRIMARY;
  249. SetupData.OperationFlags = 0; // SETUPOPER_NTUPGRADE;
  250. SetupData.WizardTitle = g_szWizardTitle;
  251. SetupData.SourcePath = NULL;
  252. SetupData.UnattendFile = NULL;
  253. SetupData.LegacySourcePath = NULL;
  254. // get number pages the wizard needs
  255. ok = (*pfnRequestPages)( NULL, &chpages, &SetupData );
  256. if ( !ok )
  257. {
  258. // request number of pages failure
  259. printf( "Cannot retrieve number of pages!\n" );
  260. }
  261. else
  262. {
  263. HPROPSHEETPAGE * phpage;
  264. // we will add anm intro and a finish page
  265. phpage = new HPROPSHEETPAGE[ chpages + 2 ];
  266. if ( NULL == phpage )
  267. {
  268. // memory allocation failue
  269. printf( "Cannot allocate memory!\n" );
  270. }
  271. else
  272. {
  273. ok = (*pfnRequestPages)( &phpage[ 1 ], &chpages, &SetupData );
  274. if ( !ok )
  275. {
  276. // request number of pages failure
  277. printf( "Cannot retrieve pages!\n" );
  278. }
  279. else
  280. {
  281. PROPSHEETPAGE psp;
  282. psp.dwSize = sizeof( psp );
  283. psp.dwFlags = PSP_USETITLE;
  284. psp.hInstance = GetModuleHandle( NULL );
  285. psp.pszTemplate = MAKEINTRESOURCE( IDD_START_PAGE );
  286. psp.hIcon = NULL;
  287. psp.pfnDlgProc = StartPageDlgProc;
  288. psp.pszTitle = SetupData.WizardTitle;
  289. psp.lParam = 0;
  290. psp.pfnCallback = NULL;
  291. phpage[ 0 ] = CreatePropertySheetPage( &psp );
  292. if ( NULL == phpage[ 0 ] )
  293. {
  294. printf( "Cannot create start page!\n" );
  295. }
  296. else
  297. {
  298. psp.dwSize = sizeof( psp );
  299. psp.dwFlags = PSP_USETITLE;
  300. psp.hInstance = GetModuleHandle( NULL );
  301. psp.pszTemplate = MAKEINTRESOURCE( IDD_FINISH_PAGE );
  302. psp.hIcon = NULL;
  303. psp.pfnDlgProc = FinishPageDlgProc;
  304. psp.pszTitle = SetupData.WizardTitle;
  305. psp.lParam = 0;
  306. psp.pfnCallback = NULL;
  307. phpage[ chpages + 1 ] = CreatePropertySheetPage( &psp );
  308. if ( NULL == phpage[ chpages + 1 ] )
  309. {
  310. printf( "Cannot create finish page!\n" );
  311. }
  312. else
  313. {
  314. PROPSHEETHEADER psh;
  315. int nResult;
  316. // prep frame header
  317. psh.dwSize = sizeof( psh );
  318. psh.dwFlags = PSH_WIZARD;
  319. psh.hwndParent = NULL;
  320. psh.hInstance = GetModuleHandle( NULL );
  321. psh.hIcon = NULL;
  322. psh.pszCaption = NULL;
  323. psh.nPages = chpages + 2;
  324. psh.nStartPage = 0;
  325. psh.phpage = phpage;
  326. psh.pfnCallback = NULL;
  327. // raise frame
  328. PropertySheet( &psh );
  329. fSuccess = TRUE;
  330. }
  331. }
  332. }
  333. delete [] phpage;
  334. }
  335. }
  336. fSuccess = LicenseKeysRestore() && fSuccess;
  337. }
  338. return fSuccess;
  339. }
  340. static
  341. BOOL
  342. CALLBACK
  343. StartPageDlgProc(
  344. HWND hdlg,
  345. UINT msg,
  346. WPARAM wParam,
  347. LPARAM lParam )
  348. {
  349. static BOOL fIsBatch;
  350. BOOL ok = TRUE;
  351. LPNMHDR pnmh;
  352. switch ( msg )
  353. {
  354. case WM_INITDIALOG:
  355. fIsBatch = ( (LPPROPSHEETPAGE)lParam )->lParam;
  356. SetLargeDialogFont( hdlg, IDC_STATICTITLE );
  357. break;
  358. case WM_NOTIFY:
  359. pnmh = (LPNMHDR)lParam;
  360. switch (pnmh->code)
  361. {
  362. // propsheet notification
  363. case PSN_HELP:
  364. break;
  365. case PSN_SETACTIVE:
  366. // hide Cancel button
  367. EnableWindow( GetDlgItem( GetParent( hdlg ), IDCANCEL ), FALSE);
  368. ShowWindow( GetDlgItem( GetParent( hdlg ), IDCANCEL ), SW_HIDE);
  369. PropSheet_SetWizButtons( GetParent( hdlg ), PSWIZB_NEXT );
  370. if ( fIsBatch )
  371. {
  372. // batch mode
  373. PostMessage( GetParent( hdlg ), PSM_PRESSBUTTON, (WPARAM)PSBTN_NEXT, 0 );
  374. }
  375. SetWindowLong( hdlg, DWL_MSGRESULT, 0 );
  376. break;
  377. case PSN_KILLACTIVE:
  378. SetWindowLong( hdlg, DWL_MSGRESULT, 0 );
  379. break;
  380. case PSN_WIZFINISH:
  381. SetWindowLong( hdlg, DWL_MSGRESULT, 0 );
  382. break;
  383. default:
  384. ok = TRUE;
  385. break;
  386. }
  387. break;
  388. default:
  389. ok = FALSE;
  390. }
  391. return ok;
  392. }
  393. static
  394. BOOL
  395. CALLBACK
  396. FinishPageDlgProc(
  397. HWND hdlg,
  398. UINT msg,
  399. WPARAM wParam,
  400. LPARAM lParam )
  401. {
  402. static BOOL fIsBatch;
  403. BOOL ok = TRUE;
  404. LPNMHDR pnmh;
  405. switch ( msg )
  406. {
  407. case WM_INITDIALOG:
  408. fIsBatch = ( (LPPROPSHEETPAGE)lParam )->lParam;
  409. SetLargeDialogFont( hdlg, IDC_STATICTITLE );
  410. break;
  411. case WM_NOTIFY:
  412. pnmh = (LPNMHDR)lParam;
  413. switch (pnmh->code)
  414. {
  415. // propsheet notification
  416. case PSN_HELP:
  417. break;
  418. case PSN_SETACTIVE:
  419. // hide Cancel button
  420. EnableWindow( GetDlgItem( GetParent( hdlg ), IDCANCEL ), FALSE);
  421. ShowWindow( GetDlgItem( GetParent( hdlg ), IDCANCEL ), SW_HIDE);
  422. PropSheet_SetWizButtons( GetParent( hdlg ), PSWIZB_BACK | PSWIZB_FINISH );
  423. if ( fIsBatch )
  424. {
  425. // batch mode
  426. PostMessage( GetParent( hdlg ), PSM_PRESSBUTTON, (WPARAM)PSBTN_FINISH, 0 );
  427. }
  428. SetWindowLong( hdlg, DWL_MSGRESULT, 0 );
  429. break;
  430. case PSN_KILLACTIVE:
  431. SetWindowLong( hdlg, DWL_MSGRESULT, 0 );
  432. break;
  433. case PSN_WIZFINISH:
  434. SetWindowLong( hdlg, DWL_MSGRESULT, 0 );
  435. break;
  436. default:
  437. ok = TRUE;
  438. break;
  439. }
  440. break;
  441. default:
  442. ok = FALSE;
  443. }
  444. return ok;
  445. }
  446. static
  447. void
  448. SetLargeDialogFont(
  449. HWND hdlg,
  450. UINT ControlId )
  451. /*++
  452. Routine Description:
  453. Sets the font of a given control in a dialog to a
  454. larger point size.
  455. (Lifted from SetupSetLargeDialogFont() in
  456. \nt\private\windows\setup\syssetup\wizard.c.)
  457. Arguments:
  458. hwnd - supplies window handle of the dialog containing
  459. the control.
  460. ControlId - supplies the id of the control whose font is
  461. to be made larger.
  462. Return Value:
  463. None.
  464. --*/
  465. {
  466. //
  467. // We keep one log font around to satisfy the request.
  468. //
  469. static HFONT BigFont = NULL;
  470. HFONT Font;
  471. LOGFONT LogFont;
  472. WCHAR str[24];
  473. int Height;
  474. HDC hdc;
  475. if ( !BigFont )
  476. {
  477. Font = (HFONT)SendDlgItemMessage( hdlg, ControlId, WM_GETFONT, 0, 0 );
  478. if ( NULL != Font )
  479. {
  480. if ( GetObject( Font, sizeof(LOGFONT), &LogFont ) )
  481. {
  482. //
  483. // Use a larger font in boldface. Get the face name and size in points
  484. // from the resources. We use 18 point in the U.S. but in the Far East
  485. // they will want to use a different size since the standard dialog font
  486. // is larger than the one we use in the U.S..
  487. //
  488. LogFont.lfWeight = FW_BOLD;
  489. lstrcpy( LogFont.lfFaceName, TEXT( "MS Serif" ) );
  490. Height = 18;
  491. hdc = GetDC( hdlg );
  492. if ( NULL != hdc )
  493. {
  494. // create font
  495. LogFont.lfHeight = 0 - ( GetDeviceCaps( hdc, LOGPIXELSY ) * Height / 72 );
  496. BigFont = CreateFontIndirect( &LogFont );
  497. ReleaseDC( hdlg, hdc );
  498. }
  499. }
  500. }
  501. }
  502. if ( NULL != BigFont )
  503. {
  504. // change font of ControlId to BigFont
  505. SendDlgItemMessage( hdlg, ControlId, WM_SETFONT, (WPARAM)BigFont, MAKELPARAM( TRUE, 0 ) );
  506. }
  507. }
  508. static
  509. BOOL
  510. TestBatch(
  511. NETSETUPPAGEREQUESTPROC pfnRequestPages )
  512. {
  513. BOOL fSuccess;
  514. fSuccess = FALSE;
  515. // save registry keys before we go and overwrite them
  516. fSuccess = LicenseKeysSave();
  517. if ( fSuccess )
  518. {
  519. TCHAR szTempFile[ 1 + MAX_PATH ];
  520. DWORD cchTempFile;
  521. cchTempFile = GetTempFileName( g_szTempPath, TEXT( "JBP" ), 0, szTempFile );
  522. if ( 0 == cchTempFile )
  523. {
  524. printf( "GetTempFileName() failed, error %lu.\n", GetLastError() );
  525. }
  526. else
  527. {
  528. HANDLE hUnattendFile;
  529. hUnattendFile = CreateFile( szTempFile,
  530. GENERIC_WRITE,
  531. FILE_SHARE_READ,
  532. NULL,
  533. CREATE_ALWAYS,
  534. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
  535. NULL );
  536. if ( NULL == hUnattendFile )
  537. {
  538. printf( "CreateFile() on \""TSTR_FMT"\" failed, error %lu.\n",
  539. szTempFile,
  540. GetLastError() );
  541. }
  542. else
  543. {
  544. struct UnattendEntry
  545. {
  546. LPSTR pszFileContents;
  547. BOOL fLicensePerServer;
  548. DWORD cPerServerLicenses;
  549. };
  550. static UnattendEntry aUnattendEntries[] =
  551. {
  552. { "[licensefileprintdata]\nautomode=perseat\nautousers=0\n", FALSE, 0 },
  553. { "[licensefileprintdata]\nautomode=perseat\nautousers=100\n", FALSE, 100 },
  554. { "[licensefileprintdata]\nautomode=perserver\nautousers=42\n", TRUE, 42 },
  555. { "[licensefileprintdata]\nautomode=perserver\nautousers=0\n", TRUE, 0 },
  556. { NULL, FALSE, 0 }
  557. };
  558. DWORD iEntry;
  559. for ( iEntry=0;
  560. fSuccess && ( NULL != aUnattendEntries[ iEntry ].pszFileContents );
  561. iEntry++ )
  562. {
  563. // delete current licensing info in registry
  564. fSuccess = LicenseKeysDelete();
  565. if ( fSuccess )
  566. {
  567. DWORD cbFilePos;
  568. // erase file
  569. cbFilePos = SetFilePointer( hUnattendFile, 0, NULL, FILE_BEGIN );
  570. if ( 0xFFFFFFFF == cbFilePos )
  571. {
  572. printf( "SetFilePointer() failed, error %lu.\n", GetLastError() );
  573. }
  574. else
  575. {
  576. BOOL ok;
  577. ok = SetEndOfFile( hUnattendFile );
  578. if ( !ok )
  579. {
  580. printf( "SetEndOfFile() failed, error %lu.\n", GetLastError() );
  581. }
  582. else
  583. {
  584. DWORD cbBytesWritten;
  585. // write new unattend file contents
  586. ok = WriteFile( hUnattendFile,
  587. aUnattendEntries[ iEntry ].pszFileContents,
  588. lstrlenA( aUnattendEntries[ iEntry ].pszFileContents ),
  589. &cbBytesWritten,
  590. NULL );
  591. if ( !ok )
  592. {
  593. printf( "WriteFile() failed, error %lu.\n", GetLastError() );
  594. }
  595. else
  596. {
  597. // run setup with this unattend file
  598. UINT chpages;
  599. INTERNAL_SETUP_DATA SetupData;
  600. BOOL ok;
  601. fSuccess = FALSE;
  602. SetupData.dwSizeOf = sizeof( SetupData );
  603. SetupData.SetupMode = SETUPMODE_CUSTOM;
  604. SetupData.ProductType = PRODUCT_SERVER_PRIMARY;
  605. SetupData.OperationFlags = SETUPOPER_BATCH;
  606. SetupData.WizardTitle = g_szWizardTitle;
  607. SetupData.SourcePath = NULL;
  608. SetupData.UnattendFile = szTempFile;
  609. SetupData.LegacySourcePath = NULL;
  610. // get number pages the wizard needs
  611. ok = (*pfnRequestPages)( NULL, &chpages, &SetupData );
  612. if ( !ok )
  613. {
  614. // request number of pages failure
  615. printf( "Cannot retrieve number of pages!\n" );
  616. }
  617. else
  618. {
  619. HPROPSHEETPAGE * phpage;
  620. phpage = new HPROPSHEETPAGE[ chpages + 2 ];
  621. if ( NULL == phpage )
  622. {
  623. // memory allocation failue
  624. printf( "Cannot allocate memory!\n" );
  625. }
  626. else
  627. {
  628. ok = (*pfnRequestPages)( &phpage[ 1 ], &chpages, &SetupData );
  629. if ( !ok )
  630. {
  631. // request number of pages failure
  632. printf( "Cannot retrieve pages!\n" );
  633. }
  634. else
  635. {
  636. PROPSHEETPAGE psp;
  637. psp.dwSize = sizeof( psp );
  638. psp.dwFlags = PSP_USETITLE;
  639. psp.hInstance = GetModuleHandle( NULL );
  640. psp.pszTemplate = MAKEINTRESOURCE( IDD_START_PAGE );
  641. psp.hIcon = NULL;
  642. psp.pfnDlgProc = StartPageDlgProc;
  643. psp.pszTitle = SetupData.WizardTitle;
  644. psp.lParam = 1;
  645. psp.pfnCallback = NULL;
  646. phpage[ 0 ] = CreatePropertySheetPage( &psp );
  647. if ( NULL == phpage[ 0 ] )
  648. {
  649. printf( "Cannot create start page!\n" );
  650. }
  651. else
  652. {
  653. psp.dwSize = sizeof( psp );
  654. psp.dwFlags = PSP_USETITLE;
  655. psp.hInstance = GetModuleHandle( NULL );
  656. psp.pszTemplate = MAKEINTRESOURCE( IDD_FINISH_PAGE );
  657. psp.hIcon = NULL;
  658. psp.pfnDlgProc = FinishPageDlgProc;
  659. psp.pszTitle = SetupData.WizardTitle;
  660. psp.lParam = 1;
  661. psp.pfnCallback = NULL;
  662. phpage[ chpages + 1 ] = CreatePropertySheetPage( &psp );
  663. if ( NULL == phpage[ chpages + 1 ] )
  664. {
  665. printf( "Cannot create finish page!\n" );
  666. }
  667. else
  668. {
  669. PROPSHEETHEADER psh;
  670. int nResult;
  671. // prep frame header
  672. psh.dwSize = sizeof( psh );
  673. psh.dwFlags = PSH_WIZARD;
  674. psh.hwndParent = NULL;
  675. psh.hInstance = GetModuleHandle( NULL );
  676. psh.hIcon = NULL;
  677. psh.pszCaption = NULL;
  678. psh.nPages = chpages + 2;
  679. psh.nStartPage = 0;
  680. psh.phpage = phpage;
  681. psh.pfnCallback = NULL;
  682. // raise frame
  683. PropertySheet( &psh );
  684. fSuccess = LicenseKeysVerify( TRUE,
  685. aUnattendEntries[ iEntry ].fLicensePerServer,
  686. aUnattendEntries[ iEntry ].cPerServerLicenses );
  687. }
  688. }
  689. }
  690. delete [] phpage;
  691. }
  692. }
  693. }
  694. }
  695. }
  696. }
  697. }
  698. CloseHandle( hUnattendFile );
  699. }
  700. }
  701. fSuccess = LicenseKeysRestore() && fSuccess;
  702. }
  703. return fSuccess;
  704. }
  705. static
  706. BOOL
  707. LicenseKeysSave()
  708. {
  709. DWORD winStatus;
  710. HANDLE hToken;
  711. TOKEN_PRIVILEGES tp;
  712. LUID luid;
  713. BOOL ok;
  714. // Enable backup privilege.
  715. ok = OpenProcessToken( GetCurrentProcess(),
  716. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
  717. &hToken ) ;
  718. if ( !ok )
  719. {
  720. winStatus = GetLastError();
  721. printf( "OpenProcessToken() failed, error %lu.\n", winStatus );
  722. }
  723. else
  724. {
  725. ok = LookupPrivilegeValue( NULL, SE_BACKUP_NAME, &luid );
  726. if ( !ok )
  727. {
  728. winStatus = GetLastError();
  729. printf( "LookupPrivilegeValue() failed, error %lu.\n", winStatus );
  730. }
  731. else
  732. {
  733. tp.PrivilegeCount = 1;
  734. tp.Privileges[0].Luid = luid;
  735. tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  736. ok = AdjustTokenPrivileges( hToken,
  737. FALSE,
  738. &tp,
  739. sizeof(TOKEN_PRIVILEGES),
  740. NULL,
  741. NULL );
  742. if ( !ok )
  743. {
  744. winStatus = GetLastError();
  745. printf( "AdjustTokenPrivileges() failed, error %lu.\n", winStatus );
  746. }
  747. else
  748. {
  749. HKEY hKeyLicenseService;
  750. HKEY hKeyLicenseInfo;
  751. HKEY hKeyEventLog;
  752. winStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  753. g_szKeyLicenseService,
  754. 0,
  755. KEY_ALL_ACCESS,
  756. &hKeyLicenseService );
  757. if ( ERROR_SUCCESS != winStatus )
  758. {
  759. printf( "RegOpenKeyEx() on \""TSTR_FMT"\" failed, error %lu.\n"
  760. " o Was the license service not properly installed?\n"
  761. " o Are you running on Workstation instead of Server?\n"
  762. " o Was the registry wiped and not restored in a previous run?\n"
  763. " (In this case, use the /RESTORE option!)\n",
  764. g_szKeyLicenseService,
  765. winStatus );
  766. }
  767. else
  768. {
  769. winStatus = RegSaveKey( hKeyLicenseService, g_szKeyFileLicenseService, NULL );
  770. if ( ERROR_SUCCESS != winStatus )
  771. {
  772. printf( "RegSaveKey() on \""TSTR_FMT"\" failed, error %lu.\n"
  773. " o Does the temp directory \""TSTR_FMT"\" not exist?\n"
  774. " o Does the file \""TSTR_FMT"\" already exist?\n",
  775. g_szKeyLicenseService,
  776. winStatus,
  777. g_szTempPath,
  778. g_szKeyFileLicenseService );
  779. }
  780. else
  781. {
  782. winStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  783. g_szKeyLicenseInfo,
  784. 0,
  785. KEY_ALL_ACCESS,
  786. &hKeyLicenseInfo );
  787. if ( ERROR_SUCCESS != winStatus )
  788. {
  789. printf( "RegOpenKeyEx() on \""TSTR_FMT"\" failed, error %lu.\n"
  790. " o Was the license service not properly installed?\n"
  791. " o Are you running on Workstation instead of Server?\n",
  792. " o Was the registry wiped and not restored in a previous run?\n"
  793. " (In this case, use the /RESTORE option!)\n",
  794. g_szKeyLicenseInfo,
  795. winStatus );
  796. DeleteFile( g_szKeyFileLicenseService );
  797. }
  798. else
  799. {
  800. winStatus = RegSaveKey( hKeyLicenseInfo, g_szKeyFileLicenseInfo, NULL );
  801. if ( ERROR_SUCCESS != winStatus )
  802. {
  803. printf( "RegSaveKey() on \""TSTR_FMT"\" failed, error %lu.\n"
  804. " o Does the temp directory \""TSTR_FMT"\" not exist?\n"
  805. " o Does the file \""TSTR_FMT"\" already exist?\n",
  806. g_szKeyLicenseInfo,
  807. winStatus,
  808. g_szTempPath,
  809. g_szKeyFileLicenseInfo );
  810. }
  811. else
  812. {
  813. winStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  814. g_szKeyEventLog,
  815. 0,
  816. KEY_ALL_ACCESS,
  817. &hKeyEventLog );
  818. if ( ERROR_SUCCESS != winStatus )
  819. {
  820. printf( "RegOpenKeyEx() on \""TSTR_FMT"\" failed, error %lu.\n"
  821. " o Was the license service not properly installed?\n"
  822. " o Are you running on Workstation instead of Server?\n",
  823. " o Was the registry wiped and not restored in a previous run?\n"
  824. " (In this case, use the /RESTORE option!)\n",
  825. g_szKeyEventLog,
  826. winStatus );
  827. DeleteFile( g_szKeyFileLicenseInfo );
  828. }
  829. else
  830. {
  831. winStatus = RegSaveKey( hKeyEventLog, g_szKeyFileEventLog, NULL );
  832. if ( ERROR_SUCCESS != winStatus )
  833. {
  834. printf( "RegSaveKey() on \""TSTR_FMT"\" failed, error %lu.\n"
  835. " o Does the temp directory \""TSTR_FMT"\" not exist?\n"
  836. " o Does the file \""TSTR_FMT"\" already exist?\n",
  837. g_szKeyEventLog,
  838. winStatus,
  839. g_szTempPath,
  840. g_szKeyFileEventLog );
  841. }
  842. RegCloseKey( hKeyEventLog );
  843. }
  844. }
  845. RegCloseKey( hKeyLicenseInfo );
  846. }
  847. }
  848. RegCloseKey( hKeyLicenseService );
  849. }
  850. // Disable backup privilege.
  851. AdjustTokenPrivileges( hToken,
  852. TRUE,
  853. &tp,
  854. sizeof(TOKEN_PRIVILEGES),
  855. NULL,
  856. NULL );
  857. }
  858. }
  859. }
  860. if ( ERROR_SUCCESS != winStatus )
  861. {
  862. printf( "The license info in the registry could not be saved!\n" );
  863. return FALSE;
  864. }
  865. else
  866. {
  867. printf( "The license info in the registry has been saved.\n" );
  868. return TRUE;
  869. }
  870. }
  871. static
  872. BOOL
  873. LicenseKeysDelete()
  874. {
  875. DWORD winStatus;
  876. DWORD iKey;
  877. DWORD iLastBackslash;
  878. SC_HANDLE hSC;
  879. winStatus = ERROR_SUCCESS;
  880. hSC = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
  881. if ( NULL == hSC )
  882. {
  883. winStatus = GetLastError();
  884. printf( "OpenSCManager() failed, error %lu.\n", winStatus );
  885. }
  886. else
  887. {
  888. SC_HANDLE hLicenseService;
  889. hLicenseService = OpenService( hSC, TEXT( "LicenseService" ), SERVICE_ALL_ACCESS );
  890. if ( NULL == hLicenseService )
  891. {
  892. winStatus = GetLastError();
  893. if ( ERROR_SERVICE_DOES_NOT_EXIST == winStatus )
  894. {
  895. // license service not configured; no need to stop or delete
  896. winStatus = ERROR_SUCCESS;
  897. }
  898. else
  899. {
  900. printf( "OpenService() failed, error %lu.\n", winStatus );
  901. }
  902. }
  903. else
  904. {
  905. BOOL ok;
  906. SERVICE_STATUS SvcStatus;
  907. // stop license service
  908. ok = ControlService( hLicenseService,
  909. SERVICE_CONTROL_STOP,
  910. &SvcStatus );
  911. if ( !ok )
  912. {
  913. winStatus = GetLastError();
  914. if ( ERROR_SERVICE_NOT_ACTIVE == winStatus )
  915. {
  916. // license service not running; no need to stop
  917. winStatus = ERROR_SUCCESS;
  918. }
  919. else
  920. {
  921. printf( "ControlService() failed, error %lu.\n", winStatus );
  922. }
  923. }
  924. if ( ( ERROR_SUCCESS == winStatus )
  925. && ( SERVICE_STOP_PENDING == SvcStatus.dwCurrentState ) )
  926. {
  927. DWORD dwOldCheckPoint;
  928. printf( "License Service is stopping.." );
  929. ok = TRUE;
  930. while ( ok && ( SvcStatus.dwCurrentState == SERVICE_STOP_PENDING ) )
  931. {
  932. printf( "." );
  933. dwOldCheckPoint = SvcStatus.dwCheckPoint;
  934. Sleep( SvcStatus.dwWaitHint );
  935. ok = QueryServiceStatus( hLicenseService,
  936. &SvcStatus );
  937. if ( dwOldCheckPoint >= SvcStatus.dwCheckPoint )
  938. break;
  939. }
  940. printf( "\n" );
  941. if ( !ok )
  942. {
  943. winStatus = GetLastError();
  944. printf( "ControlService() failed, error %lu.\n", winStatus );
  945. }
  946. else if ( SvcStatus.dwCurrentState != SERVICE_STOPPED )
  947. {
  948. winStatus = ERROR_SERVICE_REQUEST_TIMEOUT;
  949. printf( "License Service failed to stop!\n" );
  950. }
  951. else
  952. {
  953. winStatus = ERROR_SUCCESS;
  954. printf( "License Service stopped.\n" );
  955. }
  956. }
  957. if ( ERROR_SUCCESS == winStatus )
  958. {
  959. // delete service
  960. ok = DeleteService( hLicenseService );
  961. if ( !ok )
  962. {
  963. winStatus = GetLastError();
  964. printf( "DeleteService() failed, error %lu.\n", winStatus );
  965. }
  966. else
  967. {
  968. winStatus = ERROR_SUCCESS;
  969. printf( "License Service deleted.\n" );
  970. }
  971. }
  972. CloseServiceHandle( hLicenseService );
  973. }
  974. CloseServiceHandle( hSC );
  975. }
  976. if ( ERROR_SUCCESS == winStatus )
  977. {
  978. // delete keys
  979. for ( iKey=0, winStatus = ERROR_SUCCESS;
  980. ( NULL != g_apszKeys[ iKey ] ) && ( ERROR_SUCCESS == winStatus );
  981. iKey++ )
  982. {
  983. TCHAR szKeyParent[ 1 + MAX_PATH ];
  984. TCHAR szKey[ 1 + MAX_PATH ];
  985. HKEY hKeyParent;
  986. lstrcpy( szKeyParent, g_apszKeys[ iKey ] );
  987. for ( iLastBackslash = lstrlen( szKeyParent ) - 1;
  988. TEXT( '\\' ) != szKeyParent[ iLastBackslash ];
  989. iLastBackslash-- )
  990. {
  991. ;
  992. }
  993. szKeyParent[ iLastBackslash ] = TEXT( '\0' );
  994. lstrcpy( szKey, &szKeyParent[ iLastBackslash + 1 ] );
  995. winStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  996. szKeyParent,
  997. 0,
  998. KEY_ALL_ACCESS,
  999. &hKeyParent );
  1000. if ( ERROR_SUCCESS != winStatus )
  1001. {
  1002. printf( "RegOpenKeyEx() on \""TSTR_FMT"\" failed, error %lu.\n",
  1003. szKeyParent,
  1004. winStatus );
  1005. }
  1006. else
  1007. {
  1008. winStatus = MyRegDeleteKey( hKeyParent, szKey );
  1009. if ( ERROR_FILE_NOT_FOUND == winStatus )
  1010. {
  1011. winStatus = ERROR_SUCCESS;
  1012. }
  1013. else if ( ERROR_SUCCESS != winStatus )
  1014. {
  1015. printf( "MyRegDeleteKey() on \""TSTR_FMT"\" failed, error %lu.\n",
  1016. g_apszKeys[ iKey ],
  1017. winStatus );
  1018. }
  1019. RegCloseKey( hKeyParent );
  1020. }
  1021. }
  1022. }
  1023. if ( ERROR_SUCCESS != winStatus )
  1024. {
  1025. printf( "Could not delete licensing registry keys!\n" );
  1026. return FALSE;
  1027. }
  1028. else
  1029. {
  1030. printf( "Licensing registry keys deleted.\n" );
  1031. return TRUE;
  1032. }
  1033. }
  1034. static
  1035. BOOL
  1036. LicenseKeysRestore()
  1037. {
  1038. DWORD winStatus;
  1039. DWORD winStatusRestoreLicenseService;
  1040. DWORD winStatusRestoreLicenseInfo;
  1041. DWORD winStatusRestoreEventLog;
  1042. HANDLE hToken;
  1043. TOKEN_PRIVILEGES tp;
  1044. LUID luid;
  1045. BOOL ok;
  1046. winStatus = ERROR_SUCCESS;
  1047. // Enable backup privilege.
  1048. ok = OpenProcessToken( GetCurrentProcess(),
  1049. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
  1050. &hToken ) ;
  1051. if ( !ok )
  1052. {
  1053. winStatus = GetLastError();
  1054. printf( "OpenProcessToken() failed, error %lu.\n", winStatus );
  1055. }
  1056. else
  1057. {
  1058. ok = LookupPrivilegeValue( NULL, SE_RESTORE_NAME, &luid );
  1059. if ( !ok )
  1060. {
  1061. winStatus = GetLastError();
  1062. printf( "LookupPrivilegeValue() failed, error %lu.\n", winStatus );
  1063. }
  1064. else
  1065. {
  1066. tp.PrivilegeCount = 1;
  1067. tp.Privileges[0].Luid = luid;
  1068. tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  1069. ok = AdjustTokenPrivileges( hToken,
  1070. FALSE,
  1071. &tp,
  1072. sizeof(TOKEN_PRIVILEGES),
  1073. NULL,
  1074. NULL );
  1075. if ( !ok )
  1076. {
  1077. winStatus = GetLastError();
  1078. printf( "AdjustTokenPrivileges() failed, error %lu.\n", winStatus );
  1079. }
  1080. else
  1081. {
  1082. HKEY hKeyLicenseService;
  1083. HKEY hKeyLicenseInfo;
  1084. HKEY hKeyEventLog;
  1085. DWORD dwDisposition;
  1086. winStatusRestoreLicenseService = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  1087. g_szKeyLicenseService,
  1088. 0,
  1089. NULL,
  1090. 0,
  1091. KEY_ALL_ACCESS,
  1092. NULL,
  1093. &hKeyLicenseService,
  1094. &dwDisposition );
  1095. if ( ERROR_SUCCESS != winStatusRestoreLicenseService )
  1096. {
  1097. printf( "RegCreateKeyEx() of \""TSTR_FMT"\" failed, error %lu.\n",
  1098. g_szKeyLicenseService,
  1099. winStatusRestoreLicenseService );
  1100. }
  1101. else
  1102. {
  1103. winStatusRestoreLicenseService = RegRestoreKey( hKeyLicenseService, g_szKeyFileLicenseService, 0 );
  1104. if ( ERROR_SUCCESS != winStatusRestoreLicenseService )
  1105. {
  1106. printf( "RegRestoreKey() of \""TSTR_FMT"\" failed, error %lu.\n",
  1107. g_szKeyLicenseService,
  1108. winStatusRestoreLicenseService );
  1109. }
  1110. else
  1111. {
  1112. DeleteFile( g_szKeyFileLicenseService );
  1113. }
  1114. RegCloseKey( hKeyLicenseService );
  1115. }
  1116. winStatusRestoreLicenseInfo = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  1117. g_szKeyLicenseInfo,
  1118. 0,
  1119. NULL,
  1120. 0,
  1121. KEY_ALL_ACCESS,
  1122. NULL,
  1123. &hKeyLicenseInfo,
  1124. &dwDisposition );
  1125. if ( ERROR_SUCCESS != winStatusRestoreLicenseInfo )
  1126. {
  1127. printf( "RegCreateKeyEx() of \""TSTR_FMT"\" failed, error %lu.\n",
  1128. g_szKeyLicenseInfo,
  1129. winStatusRestoreLicenseInfo );
  1130. }
  1131. else
  1132. {
  1133. winStatusRestoreLicenseInfo = RegRestoreKey( hKeyLicenseInfo, g_szKeyFileLicenseInfo, 0 );
  1134. if ( ERROR_SUCCESS != winStatusRestoreLicenseInfo )
  1135. {
  1136. printf( "RegRestoreKey() of \""TSTR_FMT"\" failed, error %lu.\n",
  1137. g_szKeyLicenseInfo,
  1138. winStatusRestoreLicenseInfo );
  1139. }
  1140. else
  1141. {
  1142. DeleteFile( g_szKeyFileLicenseInfo );
  1143. }
  1144. RegCloseKey( hKeyLicenseInfo );
  1145. }
  1146. winStatusRestoreEventLog = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  1147. g_szKeyEventLog,
  1148. 0,
  1149. NULL,
  1150. 0,
  1151. KEY_ALL_ACCESS,
  1152. NULL,
  1153. &hKeyEventLog,
  1154. &dwDisposition );
  1155. if ( ERROR_SUCCESS != winStatusRestoreEventLog )
  1156. {
  1157. printf( "RegCreateKeyEx() of \""TSTR_FMT"\" failed, error %lu.\n",
  1158. g_szKeyEventLog,
  1159. winStatusRestoreEventLog );
  1160. }
  1161. else
  1162. {
  1163. winStatusRestoreEventLog = RegRestoreKey( hKeyEventLog, g_szKeyFileEventLog, 0 );
  1164. if ( ERROR_SUCCESS != winStatusRestoreEventLog )
  1165. {
  1166. printf( "RegRestoreKey() of \""TSTR_FMT"\" failed, error %lu.\n",
  1167. g_szKeyEventLog,
  1168. winStatusRestoreEventLog );
  1169. }
  1170. else
  1171. {
  1172. DeleteFile( g_szKeyFileEventLog );
  1173. }
  1174. RegCloseKey( hKeyEventLog );
  1175. }
  1176. // Disable backup privilege.
  1177. AdjustTokenPrivileges( hToken,
  1178. TRUE,
  1179. &tp,
  1180. sizeof(TOKEN_PRIVILEGES),
  1181. NULL,
  1182. NULL );
  1183. }
  1184. }
  1185. }
  1186. if ( ( ERROR_SUCCESS != winStatus )
  1187. || ( ERROR_SUCCESS != winStatusRestoreLicenseService )
  1188. || ( ERROR_SUCCESS != winStatusRestoreLicenseInfo )
  1189. || ( ERROR_SUCCESS != winStatusRestoreEventLog ) )
  1190. {
  1191. printf( "!! WARNING !! The license info in the registry has not been fully restored!\n" );
  1192. return FALSE;
  1193. }
  1194. else
  1195. {
  1196. printf( "The license info in the registry has been fully restored.\n" );
  1197. return TRUE;
  1198. }
  1199. }
  1200. static
  1201. DWORD
  1202. MyRegDeleteKey(
  1203. HKEY hKeyParent,
  1204. LPCTSTR pcszKeyName )
  1205. {
  1206. DWORD winStatus;
  1207. TCHAR szSubKeyToDelete[ 256 ];
  1208. HKEY hKey;
  1209. // try to delete it outright
  1210. winStatus = RegDeleteKey( hKeyParent, pcszKeyName );
  1211. if ( ERROR_SUCCESS != winStatus )
  1212. {
  1213. // could not delete it; perhaps the key has children
  1214. // that we must delete first?
  1215. winStatus = RegOpenKeyEx( hKeyParent,
  1216. pcszKeyName,
  1217. 0,
  1218. KEY_ALL_ACCESS,
  1219. &hKey );
  1220. if ( ERROR_SUCCESS == winStatus )
  1221. {
  1222. do
  1223. {
  1224. winStatus = RegEnumKey( hKey,
  1225. 0,
  1226. szSubKeyToDelete,
  1227. sizeof( szSubKeyToDelete ) / sizeof( *szSubKeyToDelete ) );
  1228. if ( ERROR_SUCCESS == winStatus )
  1229. {
  1230. // recursively try to delete this subkey
  1231. winStatus = MyRegDeleteKey( hKey, szSubKeyToDelete );
  1232. }
  1233. } while ( ERROR_SUCCESS == winStatus );
  1234. // we've tried tried to delete all the key's children;
  1235. // try deleting the key again
  1236. winStatus = RegDeleteKey( hKeyParent, pcszKeyName );
  1237. }
  1238. }
  1239. return winStatus;
  1240. }
  1241. static
  1242. BOOL
  1243. LicenseKeysVerify(
  1244. BOOL fShouldBePresent,
  1245. BOOL fLicensePerServer,
  1246. DWORD cPerServerLicenses )
  1247. //
  1248. // Verify service config:
  1249. //
  1250. // lpServiceName = "LicenseService"
  1251. // lpDisplayName = "License Logging Service"
  1252. // dwServiceType = SERVICE_WIN32_OWN_PROCESS
  1253. // dwStartType = LanManServerInstalled ? SERVICE_AUTO_START : SERVICE_DISABLED
  1254. // dwErrorControl = SERVICE_ERROR_NORMAL
  1255. // lpBinaryPathName = "%SystemRoot%\\System32\\llssrv.exe"
  1256. // lpLoadOrderGroup = NULL
  1257. // lpdwTagId = NULL
  1258. // lpDependencies = NULL
  1259. // lpServiceStartName = NULL
  1260. // lpPassword = NULL
  1261. //
  1262. // Verify registry values:
  1263. //
  1264. // HKEY_LOCAL_MACHINE
  1265. // \System
  1266. // \CurrentControlSet
  1267. // \Services
  1268. // \LicenseInfo
  1269. // ErrorControl : REG_DWORD : 1
  1270. // Start : REG_DWORD : 3
  1271. // Type : REG_DWORD : 4
  1272. // \FilePrint
  1273. // ConcurrentLimit : REG_DWORD : fLicensePerServer ? cPerServerLicenses : 0
  1274. // DisplayName : REG_SZ : "Windows NT Server"
  1275. // FamilyDisplayName : REG_SZ : "Windows NT Server"
  1276. // Mode : REG_DWORD : fLicensePerServer ? 1 : 0
  1277. // FlipAllow : REG_DWORD : fLicensePerServer ? 1 : 0
  1278. // \LicenseService
  1279. // \FilePrint
  1280. // \KSecDD
  1281. // \MSAfpSrv
  1282. // \SMBServer
  1283. // \TCP/IP Print Server
  1284. // \Parameters
  1285. // UseEnterprise : REG_DWORD : 0
  1286. // ReplicationType : REG_DWORD : 0
  1287. // ReplicationTime : REG_DWORD : 24 * 60 * 60
  1288. // EnterpriseServer : REG_SZ : ""
  1289. // \EventLog
  1290. // \Application
  1291. // \LicenseService
  1292. // EventMessageFile : REG_EXPAND_SZ : %SystemRoot%\System32\llsrpc.dll
  1293. // TypesSupported : REG_DWORD : 7
  1294. //
  1295. {
  1296. BOOL fSuccess;
  1297. DWORD winStatus;
  1298. // check service config
  1299. if ( !fShouldBePresent )
  1300. {
  1301. fSuccess = TRUE;
  1302. }
  1303. else
  1304. {
  1305. SC_HANDLE hSC;
  1306. fSuccess = FALSE;
  1307. hSC = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
  1308. if ( NULL == hSC )
  1309. {
  1310. printf( "OpenSCManager() failed, error %lu.\n", GetLastError() );
  1311. }
  1312. else
  1313. {
  1314. SC_HANDLE hLicenseService;
  1315. hLicenseService = OpenService( hSC, TEXT( "LicenseService" ), SERVICE_ALL_ACCESS );
  1316. if ( NULL == hLicenseService )
  1317. {
  1318. printf( "OpenService() failed, error %lu.\n", GetLastError() );
  1319. }
  1320. else
  1321. {
  1322. BOOL ok;
  1323. BYTE abLicenseServiceConfig[ 4096 ];
  1324. LPQUERY_SERVICE_CONFIG pLicenseServiceConfig;
  1325. DWORD cbLicenseServiceConfigNeeded;
  1326. pLicenseServiceConfig = (LPQUERY_SERVICE_CONFIG) abLicenseServiceConfig;
  1327. ok = QueryServiceConfig( hLicenseService,
  1328. pLicenseServiceConfig,
  1329. sizeof( abLicenseServiceConfig ),
  1330. &cbLicenseServiceConfigNeeded );
  1331. if ( !ok )
  1332. {
  1333. printf( "QueryServiceConfig() failed, error %lu.\n", GetLastError() );
  1334. }
  1335. else if ( ( SERVICE_WIN32_OWN_PROCESS != pLicenseServiceConfig->dwServiceType )
  1336. || ( SERVICE_AUTO_START != pLicenseServiceConfig->dwStartType )
  1337. || ( SERVICE_ERROR_NORMAL != pLicenseServiceConfig->dwErrorControl )
  1338. || lstrcmpi( TEXT( "" ), pLicenseServiceConfig->lpLoadOrderGroup )
  1339. || lstrcmpi( TEXT( "" ), pLicenseServiceConfig->lpDependencies )
  1340. || lstrcmpi( TEXT( "LocalSystem" ), pLicenseServiceConfig->lpServiceStartName )
  1341. //|| lstrcmpi( TEXT( "%SystemRoot%\\System32\\llssrv.exe" ), pLicenseServiceConfig->lpBinaryPathName )
  1342. //|| lstrcmp( TEXT( "License Logging Service" ), pLicenseServiceConfig->lpDisplayName )
  1343. )
  1344. {
  1345. printf( "LicenseService was incorrectly configured!\n" );
  1346. }
  1347. else
  1348. {
  1349. fSuccess = TRUE;
  1350. }
  1351. CloseServiceHandle( hLicenseService );
  1352. }
  1353. CloseServiceHandle( hSC );
  1354. }
  1355. }
  1356. if ( fSuccess )
  1357. {
  1358. // check LicenseService\FilePrint
  1359. HKEY hKeyFilePrint;
  1360. fSuccess = FALSE;
  1361. winStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  1362. TEXT( "System\\CurrentControlSet\\Services\\LicenseService\\FilePrint" ),
  1363. 0,
  1364. KEY_ALL_ACCESS,
  1365. &hKeyFilePrint );
  1366. if ( !fShouldBePresent )
  1367. {
  1368. if ( ERROR_SUCCESS == winStatus )
  1369. {
  1370. printf( "\"...\\Services\\LicenseService\\FilePrint\" exists but shouldn't!\n" );
  1371. }
  1372. else
  1373. {
  1374. fSuccess = TRUE;
  1375. }
  1376. }
  1377. else if ( ERROR_SUCCESS != winStatus )
  1378. {
  1379. printf( "RegOpenKeyEx() on \"...\\Services\\LicenseService\\FilePrint\" failed, error %lu.\n",
  1380. winStatus );
  1381. }
  1382. else
  1383. {
  1384. static LPTSTR apszFilePrintServices[] =
  1385. {
  1386. TEXT( "KSecDD" ),
  1387. TEXT( "MSAfpSrv" ),
  1388. TEXT( "SMBServer" ),
  1389. TEXT( "TCP/IP Print Server" ),
  1390. NULL
  1391. };
  1392. DWORD iService;
  1393. fSuccess = TRUE;
  1394. for ( iService=0; fSuccess && ( NULL != apszFilePrintServices[ iService ] ); iService++ )
  1395. {
  1396. HKEY hKeyFilePrintService;
  1397. winStatus = RegOpenKeyEx( hKeyFilePrint,
  1398. apszFilePrintServices[ iService ],
  1399. 0,
  1400. KEY_ALL_ACCESS,
  1401. &hKeyFilePrintService );
  1402. if ( ERROR_SUCCESS != winStatus )
  1403. {
  1404. printf( "RegOpenKeyEx() on \""TSTR_FMT"\" failed, error %lu.\n",
  1405. apszFilePrintServices[ iService ],
  1406. winStatus );
  1407. fSuccess = FALSE;
  1408. }
  1409. else
  1410. {
  1411. RegCloseKey( hKeyFilePrintService );
  1412. }
  1413. }
  1414. RegCloseKey( hKeyFilePrint );
  1415. }
  1416. }
  1417. if ( fSuccess )
  1418. {
  1419. // check LicenseService\Parameters
  1420. HKEY hKeyParameters;
  1421. fSuccess = FALSE;
  1422. winStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  1423. TEXT( "System\\CurrentControlSet\\Services\\LicenseService\\Parameters" ),
  1424. 0,
  1425. KEY_ALL_ACCESS,
  1426. &hKeyParameters );
  1427. if ( !fShouldBePresent )
  1428. {
  1429. if ( ERROR_SUCCESS == winStatus )
  1430. {
  1431. printf( "\"...\\Services\\LicenseService\\Parameters\" exists but shouldn't!\n" );
  1432. }
  1433. else
  1434. {
  1435. fSuccess = TRUE;
  1436. }
  1437. }
  1438. else if ( ERROR_SUCCESS != winStatus )
  1439. {
  1440. printf( "RegOpenKeyEx() on \"...\\Services\\LicenseService\\Parameters\" failed, error %lu.\n",
  1441. winStatus );
  1442. }
  1443. else
  1444. {
  1445. // UseEnterprise : REG_DWORD : 0
  1446. // ReplicationType : REG_DWORD : 0
  1447. // ReplicationTime : REG_DWORD : 24 * 60 * 60
  1448. // EnterpriseServer : REG_SZ : ""
  1449. DWORD dwType;
  1450. DWORD dwValue;
  1451. DWORD cbValue;
  1452. TCHAR szValue[ 1 + MAX_PATH ];
  1453. cbValue = sizeof( dwValue );
  1454. winStatus = RegQueryValueEx( hKeyParameters,
  1455. TEXT( "UseEnterprise" ),
  1456. NULL,
  1457. &dwType,
  1458. (LPBYTE) &dwValue,
  1459. &cbValue );
  1460. if ( ERROR_SUCCESS != winStatus )
  1461. {
  1462. printf( "RegQueryValueEx() on \"UseEnterprise\" failed, error %lu.\n",
  1463. winStatus );
  1464. }
  1465. else if ( ( REG_DWORD != dwType ) || ( 0 != dwValue ) )
  1466. {
  1467. printf( "\"UseEnterprise\" has incorrect value!\n" );
  1468. }
  1469. else
  1470. {
  1471. cbValue = sizeof( dwValue );
  1472. winStatus = RegQueryValueEx( hKeyParameters,
  1473. TEXT( "ReplicationType" ),
  1474. NULL,
  1475. &dwType,
  1476. (LPBYTE) &dwValue,
  1477. &cbValue );
  1478. if ( ERROR_SUCCESS != winStatus )
  1479. {
  1480. printf( "RegQueryValueEx() on \"ReplicationType\" failed, error %lu.\n",
  1481. winStatus );
  1482. }
  1483. else if ( ( REG_DWORD != dwType ) || ( 0 != dwValue ) )
  1484. {
  1485. printf( "\"ReplicationType\" has incorrect value!\n" );
  1486. }
  1487. else
  1488. {
  1489. cbValue = sizeof( dwValue );
  1490. winStatus = RegQueryValueEx( hKeyParameters,
  1491. TEXT( "ReplicationTime" ),
  1492. NULL,
  1493. &dwType,
  1494. (LPBYTE) &dwValue,
  1495. &cbValue );
  1496. if ( ERROR_SUCCESS != winStatus )
  1497. {
  1498. printf( "RegQueryValueEx() on \"ReplicationTime\" failed, error %lu.\n",
  1499. winStatus );
  1500. }
  1501. else if ( ( REG_DWORD != dwType ) || ( 24L * 60L * 60L != dwValue ) )
  1502. {
  1503. printf( "\"ReplicationTime\" has incorrect value!\n" );
  1504. }
  1505. else
  1506. {
  1507. cbValue = sizeof( szValue );
  1508. winStatus = RegQueryValueEx( hKeyParameters,
  1509. TEXT( "EnterpriseServer" ),
  1510. NULL,
  1511. &dwType,
  1512. (LPBYTE) szValue,
  1513. &cbValue );
  1514. if ( ERROR_SUCCESS != winStatus )
  1515. {
  1516. printf( "RegQueryValueEx() on \"EnterpriseServer\" failed, error %lu.\n",
  1517. winStatus );
  1518. }
  1519. else if ( ( REG_SZ != dwType ) || ( TEXT( '\0' ) != szValue[ 0 ] ) )
  1520. {
  1521. printf( "\"EnterpriseServer\" has incorrect value!\n" );
  1522. }
  1523. else
  1524. {
  1525. fSuccess = TRUE;
  1526. }
  1527. }
  1528. }
  1529. }
  1530. RegCloseKey( hKeyParameters );
  1531. }
  1532. }
  1533. if ( fSuccess )
  1534. {
  1535. // check LicenseInfo
  1536. HKEY hKeyLicenseInfo;
  1537. fSuccess = FALSE;
  1538. winStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  1539. TEXT( "System\\CurrentControlSet\\Services\\LicenseInfo" ),
  1540. 0,
  1541. KEY_ALL_ACCESS,
  1542. &hKeyLicenseInfo );
  1543. if ( !fShouldBePresent )
  1544. {
  1545. if ( ERROR_SUCCESS == winStatus )
  1546. {
  1547. printf( "\"...\\Services\\LicenseInfo\" exists but shouldn't!\n" );
  1548. }
  1549. else
  1550. {
  1551. fSuccess = TRUE;
  1552. }
  1553. }
  1554. else if ( ERROR_SUCCESS != winStatus )
  1555. {
  1556. printf( "RegOpenKeyEx() on \"...\\Services\\LicenseInfo\" failed, error %lu.\n",
  1557. winStatus );
  1558. }
  1559. else
  1560. {
  1561. // ErrorControl : REG_DWORD : 1
  1562. // Start : REG_DWORD : 3
  1563. // Type : REG_DWORD : 4
  1564. DWORD dwType;
  1565. DWORD dwValue;
  1566. DWORD cbValue;
  1567. cbValue = sizeof( dwValue );
  1568. winStatus = RegQueryValueEx( hKeyLicenseInfo,
  1569. TEXT( "ErrorControl" ),
  1570. NULL,
  1571. &dwType,
  1572. (LPBYTE) &dwValue,
  1573. &cbValue );
  1574. if ( ERROR_SUCCESS != winStatus )
  1575. {
  1576. printf( "RegQueryValueEx() on \"ErrorControl\" failed, error %lu.\n",
  1577. winStatus );
  1578. }
  1579. else if ( ( REG_DWORD != dwType ) || ( 1 != dwValue ) )
  1580. {
  1581. printf( "\"ErrorControl\" has incorrect value!\n" );
  1582. }
  1583. else
  1584. {
  1585. cbValue = sizeof( dwValue );
  1586. winStatus = RegQueryValueEx( hKeyLicenseInfo,
  1587. TEXT( "Start" ),
  1588. NULL,
  1589. &dwType,
  1590. (LPBYTE) &dwValue,
  1591. &cbValue );
  1592. if ( ERROR_SUCCESS != winStatus )
  1593. {
  1594. printf( "RegQueryValueEx() on \"Start\" failed, error %lu.\n",
  1595. winStatus );
  1596. }
  1597. else if ( ( REG_DWORD != dwType ) || ( 3 != dwValue ) )
  1598. {
  1599. printf( "\"Start\" has incorrect value!\n" );
  1600. }
  1601. else
  1602. {
  1603. cbValue = sizeof( dwValue );
  1604. winStatus = RegQueryValueEx( hKeyLicenseInfo,
  1605. TEXT( "Type" ),
  1606. NULL,
  1607. &dwType,
  1608. (LPBYTE) &dwValue,
  1609. &cbValue );
  1610. if ( ERROR_SUCCESS != winStatus )
  1611. {
  1612. printf( "RegQueryValueEx() on \"Type\" failed, error %lu.\n",
  1613. winStatus );
  1614. }
  1615. else if ( ( REG_DWORD != dwType ) || ( 4 != dwValue ) )
  1616. {
  1617. printf( "\"Type\" has incorrect value!\n" );
  1618. }
  1619. else
  1620. {
  1621. fSuccess = TRUE;
  1622. }
  1623. }
  1624. }
  1625. RegCloseKey( hKeyLicenseInfo );
  1626. }
  1627. }
  1628. if ( fSuccess )
  1629. {
  1630. // check LicenseInfo\FilePrint
  1631. HKEY hKeyFilePrint;
  1632. fSuccess = FALSE;
  1633. winStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  1634. TEXT( "System\\CurrentControlSet\\Services\\LicenseInfo\\FilePrint" ),
  1635. 0,
  1636. KEY_ALL_ACCESS,
  1637. &hKeyFilePrint );
  1638. if ( !fShouldBePresent )
  1639. {
  1640. if ( ERROR_SUCCESS == winStatus )
  1641. {
  1642. printf( "\"...\\EventLog\\Application\\LicenseInfo\\FilePrint\" exists but shouldn't!\n" );
  1643. }
  1644. else
  1645. {
  1646. fSuccess = TRUE;
  1647. }
  1648. }
  1649. else if ( ERROR_SUCCESS != winStatus )
  1650. {
  1651. printf( "RegOpenKeyEx() on \"...\\Services\\LicenseInfo\\FilePrint\" failed, error %lu.\n",
  1652. winStatus );
  1653. }
  1654. else
  1655. {
  1656. // ConcurrentLimit : REG_DWORD : fLicensePerServer ? cPerServerLicenses : 0
  1657. // DisplayName : REG_SZ : "Windows NT Server"
  1658. // FamilyDisplayName : REG_SZ : "Windows NT Server"
  1659. // Mode : REG_DWORD : fLicensePerServer ? 1 : 0
  1660. // FlipAllow : REG_DWORD : fLicensePerServer ? 1 : 0
  1661. DWORD dwType;
  1662. DWORD dwValue;
  1663. DWORD cbValue;
  1664. TCHAR szValue[ 1 + MAX_PATH ];
  1665. cbValue = sizeof( dwValue );
  1666. winStatus = RegQueryValueEx( hKeyFilePrint,
  1667. TEXT( "ConcurrentLimit" ),
  1668. NULL,
  1669. &dwType,
  1670. (LPBYTE) &dwValue,
  1671. &cbValue );
  1672. if ( ERROR_SUCCESS != winStatus )
  1673. {
  1674. printf( "RegQueryValueEx() on \"ConcurrentLimit\" failed, error %lu.\n",
  1675. winStatus );
  1676. }
  1677. else if ( ( REG_DWORD != dwType )
  1678. || ( ( fLicensePerServer ? cPerServerLicenses : 0 ) != dwValue ) )
  1679. {
  1680. printf( "\"ConcurrentLimit\" has incorrect value!\n" );
  1681. }
  1682. else
  1683. {
  1684. cbValue = sizeof( dwValue );
  1685. winStatus = RegQueryValueEx( hKeyFilePrint,
  1686. TEXT( "Mode" ),
  1687. NULL,
  1688. &dwType,
  1689. (LPBYTE) &dwValue,
  1690. &cbValue );
  1691. if ( ERROR_SUCCESS != winStatus )
  1692. {
  1693. printf( "RegQueryValueEx() on \"Mode\" failed, error %lu.\n",
  1694. winStatus );
  1695. }
  1696. else if ( ( REG_DWORD != dwType ) || ( (DWORD) fLicensePerServer != dwValue ) )
  1697. {
  1698. printf( "\"Mode\" has incorrect value!\n" );
  1699. }
  1700. else
  1701. {
  1702. cbValue = sizeof( dwValue );
  1703. winStatus = RegQueryValueEx( hKeyFilePrint,
  1704. TEXT( "FlipAllow" ),
  1705. NULL,
  1706. &dwType,
  1707. (LPBYTE) &dwValue,
  1708. &cbValue );
  1709. if ( ERROR_SUCCESS != winStatus )
  1710. {
  1711. printf( "RegQueryValueEx() on \"FlipAllow\" failed, error %lu.\n",
  1712. winStatus );
  1713. }
  1714. else if ( ( REG_DWORD != dwType ) || ( (DWORD) fLicensePerServer != dwValue ) )
  1715. {
  1716. printf( "\"FlipAllow\" has incorrect value!\n" );
  1717. }
  1718. else
  1719. {
  1720. cbValue = sizeof( szValue );
  1721. winStatus = RegQueryValueEx( hKeyFilePrint,
  1722. TEXT( "DisplayName" ),
  1723. NULL,
  1724. &dwType,
  1725. (LPBYTE) szValue,
  1726. &cbValue );
  1727. if ( ERROR_SUCCESS != winStatus )
  1728. {
  1729. printf( "RegQueryValueEx() on \"DisplayName\" failed, error %lu.\n",
  1730. winStatus );
  1731. }
  1732. else if ( ( REG_SZ != dwType ) || lstrcmp( TEXT( "Windows NT Server" ), szValue ) )
  1733. {
  1734. printf( "\"DisplayName\" has incorrect value!\n" );
  1735. }
  1736. else
  1737. {
  1738. cbValue = sizeof( szValue );
  1739. winStatus = RegQueryValueEx( hKeyFilePrint,
  1740. TEXT( "FamilyDisplayName" ),
  1741. NULL,
  1742. &dwType,
  1743. (LPBYTE) szValue,
  1744. &cbValue );
  1745. if ( ERROR_SUCCESS != winStatus )
  1746. {
  1747. printf( "RegQueryValueEx() on \"FamilyDisplayName\" failed, error %lu.\n",
  1748. winStatus );
  1749. }
  1750. else if ( ( REG_SZ != dwType ) || lstrcmp( TEXT( "Windows NT Server" ), szValue ) )
  1751. {
  1752. printf( "\"FamilyDisplayName\" has incorrect value!\n" );
  1753. }
  1754. else
  1755. {
  1756. fSuccess = TRUE;
  1757. }
  1758. }
  1759. }
  1760. }
  1761. }
  1762. RegCloseKey( hKeyFilePrint );
  1763. }
  1764. }
  1765. if ( fSuccess )
  1766. {
  1767. // check EventLog
  1768. HKEY hKeyEventLog;
  1769. fSuccess = FALSE;
  1770. winStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  1771. TEXT( "System\\CurrentControlSet\\Services\\EventLog\\Application\\LicenseService" ),
  1772. 0,
  1773. KEY_ALL_ACCESS,
  1774. &hKeyEventLog );
  1775. if ( !fShouldBePresent )
  1776. {
  1777. if ( ERROR_SUCCESS == winStatus )
  1778. {
  1779. printf( "\"...\\EventLog\\Application\\LicenseService\" exists but shouldn't!\n" );
  1780. }
  1781. else
  1782. {
  1783. fSuccess = TRUE;
  1784. }
  1785. }
  1786. else if ( ERROR_SUCCESS != winStatus )
  1787. {
  1788. printf( "RegOpenKeyEx() on \"...\\EventLog\\Application\\LicenseService\" failed, error %lu.\n",
  1789. winStatus );
  1790. }
  1791. else
  1792. {
  1793. // EventMessageFile : REG_EXPAND_SZ : %SystemRoot%\System32\llsrpc.dll
  1794. // TypesSupported : REG_DWORD : 7
  1795. DWORD dwType;
  1796. DWORD dwValue;
  1797. DWORD cbValue;
  1798. TCHAR szValue[ 1 + MAX_PATH ];
  1799. cbValue = sizeof( dwValue );
  1800. winStatus = RegQueryValueEx( hKeyEventLog,
  1801. TEXT( "TypesSupported" ),
  1802. NULL,
  1803. &dwType,
  1804. (LPBYTE) &dwValue,
  1805. &cbValue );
  1806. if ( ERROR_SUCCESS != winStatus )
  1807. {
  1808. printf( "RegQueryValueEx() on \"TypesSupported\" failed, error %lu.\n",
  1809. winStatus );
  1810. }
  1811. else if ( ( REG_DWORD != dwType ) || ( 7 != dwValue ) )
  1812. {
  1813. printf( "\"TypesSupported\" has incorrect value!\n" );
  1814. }
  1815. else
  1816. {
  1817. cbValue = sizeof( szValue );
  1818. winStatus = RegQueryValueEx( hKeyEventLog,
  1819. TEXT( "EventMessageFile" ),
  1820. NULL,
  1821. &dwType,
  1822. (LPBYTE) szValue,
  1823. &cbValue );
  1824. if ( ERROR_SUCCESS != winStatus )
  1825. {
  1826. printf( "RegQueryValueEx() on \"EventMessageFile\" failed, error %lu.\n",
  1827. winStatus );
  1828. }
  1829. else if ( ( REG_SZ != dwType ) || lstrcmpi( TEXT( "%SystemRoot%\\System32\\llsrpc.dll" ), szValue ) )
  1830. {
  1831. printf( "\"EventMessageFile\" has incorrect value!\n" );
  1832. }
  1833. else
  1834. {
  1835. fSuccess = TRUE;
  1836. }
  1837. }
  1838. RegCloseKey( hKeyEventLog );
  1839. }
  1840. }
  1841. if ( !fSuccess )
  1842. {
  1843. printf( "Configuration failed!\n" );
  1844. }
  1845. else
  1846. {
  1847. printf( "Configuration succeeded.\n" );
  1848. }
  1849. return fSuccess;
  1850. }