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.

123 lines
2.6 KiB

  1. #include "stdafx.h"
  2. #include "WizardSheet.h"
  3. LRESULT CWelcomePage::OnInitDialog( UINT, WPARAM, LPARAM, BOOL& )
  4. {
  5. // Set the fonts
  6. SetWindowFont( GetDlgItem( IDC_TITLE ), m_pTheSheet->m_fontTitles.get(), FALSE );
  7. SetWindowFont( GetDlgItem( IDC_TIP ), m_pTheSheet->m_fontBold.get(), FALSE );
  8. // Center the property sheet on the screen
  9. CWindow wnd( m_pTheSheet->m_hWnd );
  10. wnd.CenterWindow();
  11. return 0;
  12. }
  13. BOOL CWelcomePage::OnSetActive()
  14. {
  15. if ( CanRun() )
  16. {
  17. SetWizardButtons( PSWIZB_NEXT );
  18. }
  19. else
  20. {
  21. ::ShowWindow( GetDlgItem( IDC_ERRORICON ), SW_SHOW );
  22. ::ShowWindow( GetDlgItem( IDC_ERROR ), SW_SHOW );
  23. ::ShowWindow( GetDlgItem( IDC_TIP ), SW_HIDE );
  24. SetWizardButtons( 0 );
  25. }
  26. return TRUE;
  27. }
  28. bool CWelcomePage::CanRun()
  29. {
  30. UINT nResID = 0;
  31. if ( !IsAdmin() )
  32. {
  33. nResID = IDS_E_NOTADMIN;
  34. }
  35. else if ( !IsIISRunning() )
  36. {
  37. nResID = IDS_E_NOIIS;
  38. }
  39. if ( nResID != 0 )
  40. {
  41. CString strText;
  42. strText.LoadString( nResID );
  43. ::SetWindowText( GetDlgItem( IDC_ERROR ), strText );
  44. }
  45. return ( nResID == 0 );
  46. }
  47. bool CWelcomePage::IsAdmin()
  48. {
  49. BOOL bIsAdmin = FALSE;
  50. SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
  51. PSID AdminSid = { 0 };
  52. if ( ::AllocateAndInitializeSid( &NtAuthority,
  53. 2, // Number of subauthorities
  54. SECURITY_BUILTIN_DOMAIN_RID,
  55. DOMAIN_ALIAS_RID_ADMINS,
  56. 0,
  57. 0,
  58. 0,
  59. 0,
  60. 0,
  61. 0,
  62. &AdminSid ) )
  63. {
  64. if ( !::CheckTokenMembership( NULL, AdminSid, &bIsAdmin ) )
  65. {
  66. bIsAdmin = FALSE;
  67. }
  68. }
  69. ::GlobalFree( AdminSid );
  70. return ( bIsAdmin != FALSE );
  71. }
  72. bool CWelcomePage::IsIISRunning()
  73. {
  74. bool bResult = false;
  75. LPCWSTR SERVICE_NAME = L"IISADMIN";
  76. // Open the SCM on the local machine
  77. SC_HANDLE schSCManager = ::OpenSCManagerW( NULL, NULL, SC_MANAGER_ALL_ACCESS );
  78. _ASSERT( schSCManager != NULL ); // We alredy checked that we are Admins
  79. SC_HANDLE schService = ::OpenServiceW( schSCManager, SERVICE_NAME, SERVICE_QUERY_STATUS );
  80. // The service is not installed
  81. if ( schService != NULL )
  82. {
  83. SERVICE_STATUS ssStatus;
  84. VERIFY( ::QueryServiceStatus( schService, &ssStatus ) );
  85. bResult = ( ssStatus.dwCurrentState == SERVICE_RUNNING );
  86. VERIFY( ::CloseServiceHandle( schService ) );
  87. }
  88. VERIFY( ::CloseServiceHandle( schSCManager ) );
  89. return bResult;
  90. }