home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / pserv.cpl / pserv-2.4.exe / source / PageStartup.cpp < prev    next >
C/C++ Source or Header  |  2005-01-05  |  9KB  |  270 lines

  1. // PageStartup.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "pserv2.h"
  6. #include "PageStartup.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CPageStartup property page
  16.  
  17. #define INTERNAL_PASSWORD_TEXT _T("\x18\x60\x08\x18\x60\x08\x18\x60\x08")
  18.  
  19. IMPLEMENT_DYNCREATE(CPageStartup, CPropertyPage)
  20.  
  21. void CPageStartup::SetService(CService* instance)
  22. {
  23.     m_pService = instance;
  24.     if( m_pService != NULL )
  25.     {
  26.         m_dwStartupType = m_pService->m_dwStartType;
  27.         m_strDescription = m_pService->m_strDescription;
  28.         m_strDisplayName = m_pService->m_strDisplayName;
  29.         m_strBinaryPathName = m_pService->m_strBinaryPathName;
  30.         m_strServiceName = m_pService->m_strServiceName;
  31.     }
  32. }
  33.  
  34. CPageStartup::CPageStartup()
  35.     :   CPropertyPage(CPageStartup::IDD),
  36.         m_pService( 0 )
  37. {
  38.     //{{AFX_DATA_INIT(CPageStartup)
  39.     m_dwStartupType = 0;
  40.     m_strDescription = _T("");
  41.     m_strDisplayName = _T("");
  42.     m_strBinaryPathName = _T("");
  43.     //}}AFX_DATA_INIT
  44. }
  45.  
  46. CPageStartup::~CPageStartup()
  47. {
  48. }
  49.  
  50. void PASCAL DDX_VerifySamePassword(CDataExchange * pDX, CEdit& ecPassword1, CEdit& ecPassword2)
  51. {
  52.     if(pDX->m_bSaveAndValidate )
  53.     {
  54.         CString str1, str2;
  55.         ecPassword1.GetWindowText(str1);
  56.         ecPassword2.GetWindowText(str2);
  57.         pDX->PrepareCtrl(ecPassword1.GetDlgCtrlID());
  58.         if( str1.Compare(INTERNAL_PASSWORD_TEXT) == 0 )
  59.         {
  60.             AfxMessageBox(_T("You must specify a password"));
  61.             pDX->Fail();
  62.         }
  63.         if( str1.Compare(str2) != 0 )
  64.         {
  65.             AfxMessageBox(_T("Both passwords must be the same"));
  66.             pDX->Fail();
  67.         }
  68.     }
  69. }
  70.  
  71. void CPageStartup::OnSaveData(CDataExchange* pDX)
  72. {
  73.     m_ecServiceName.GetWindowText(m_strServiceName);
  74.     if( IsEmptyString(m_strServiceName) )
  75.     {
  76.         AfxMessageBox(_T("Service name must not be empty"));
  77.         pDX->m_hWndLastControl = m_ecServiceName;
  78.         pDX->Fail();
  79.     }
  80.     if( m_strDescription.Compare(m_pService->m_strDescription) != 0 )
  81.     {
  82.         m_pService->m_strDescription = m_strDescription;
  83.         m_pService->m_dwChangeFlags |= CHANGED_DESCRIPTION;
  84.     }
  85.     if( m_strDisplayName.Compare(m_pService->m_strDisplayName) != 0 )
  86.     {
  87.         if( IsEmptyString(m_strDisplayName) )
  88.         {
  89.             AfxMessageBox(_T("Display name must not be empty"));
  90.             pDX->m_hWndLastControl = ::GetDlgItem(m_hWnd, IDC_DISPLAY_NAME2);
  91.             pDX->Fail();
  92.         }
  93.         m_pService->m_strDisplayName = m_strDisplayName;
  94.         m_pService->m_dwChangeFlags |= CHANGED_DISPLAYNAME;
  95.     }
  96.     if( m_strBinaryPathName.Compare(m_pService->m_strBinaryPathName) != 0 )
  97.     {
  98.         if( IsEmptyString(m_strBinaryPathName) )
  99.         {
  100.             AfxMessageBox(_T("Image path must not be empty"));
  101.             pDX->m_hWndLastControl = ::GetDlgItem(m_hWnd, IDC_IMAGE_PATH);
  102.             pDX->Fail();
  103.         }
  104.         m_pService->m_strBinaryPathName = m_strBinaryPathName;
  105.         m_pService->m_dwChangeFlags |= CHANGED_BINARYPATH;
  106.     }
  107.     if( (DWORD) m_dwStartupType != m_pService->m_dwStartType )
  108.     {
  109.         m_pService->m_dwStartType = (DWORD) m_dwStartupType;
  110.         m_pService->m_dwChangeFlags |= CHANGED_START_TYPE;
  111.     }
  112.     BOOL bWasSystemAccount = IsEmptyString( m_pService->m_strServiceStartName ) || !m_pService->m_strServiceStartName.Compare(_T("LocalSystem"));
  113.     if( m_btLogonAsSystem.GetCheck() )
  114.     {
  115.         if( !bWasSystemAccount )
  116.         {
  117.             // changed logon to system
  118.             m_pService->m_strServiceStartName = "";
  119.             m_pService->m_dwChangeFlags |= CHANGED_LOGON_SYSTEM;
  120.         }
  121.         DWORD dwBitMask = m_btAllowServiceToInteractWithDesktop.GetCheck() ? SERVICE_INTERACTIVE_PROCESS : 0;
  122.         if( (m_pService->m_dwServiceType & SERVICE_INTERACTIVE_PROCESS) != dwBitMask )
  123.         {
  124.             if( dwBitMask )
  125.             {
  126.                 m_pService->m_dwServiceType |= (SERVICE_INTERACTIVE_PROCESS);
  127.             }
  128.             else
  129.             {
  130.                 m_pService->m_dwServiceType &= ~(SERVICE_INTERACTIVE_PROCESS);
  131.             }
  132.             m_pService->m_dwChangeFlags |= CHANGED_ALLOW_UI;
  133.         }
  134.     }
  135.     else
  136.     {
  137.         CString strUserName, strPassword;
  138.         m_ecUserName.GetWindowText(strUserName);
  139.         m_ecPassword.GetWindowText(strPassword);
  140.         if( bWasSystemAccount ||
  141.             (strUserName.Compare(m_pService->m_strServiceStartName) != 0) )
  142.         {
  143.             DDX_VerifySamePassword(pDX,m_ecPassword, m_ecPassword2 );
  144.  
  145.             // changed logon to system
  146.             m_pService->m_strServiceStartName = strUserName;
  147.             m_pService->m_strServiceStartPassword = strPassword;
  148.             m_pService->m_dwChangeFlags |= CHANGED_LOGON_USER;
  149.  
  150.             if( m_pService->m_dwServiceType & SERVICE_INTERACTIVE_PROCESS )
  151.             {
  152.                 m_pService->m_dwServiceType &= ~SERVICE_INTERACTIVE_PROCESS;
  153.                 m_pService->m_dwChangeFlags |= CHANGED_ALLOW_UI;
  154.             }
  155.         }
  156.     }
  157.     if( IsEmptyString(m_pService->m_strServiceName) )
  158.     {
  159.         m_pService->m_strServiceName = m_strServiceName;
  160.     }
  161. }
  162.  
  163. void CPageStartup::DoDataExchange(CDataExchange* pDX)
  164. {
  165.     CPropertyPage::DoDataExchange(pDX);
  166.  
  167.     //{{AFX_DATA_MAP(CPageStartup)
  168.     DDX_Control(pDX, IDC_SERVICE_NAME, m_ecServiceName);
  169.     DDX_Control(pDX, IDC_LOGON_PASSWORD2, m_ecPassword2);
  170.     DDX_Control(pDX, IDC_ALLOW_SERVICE_TO_INTERACT_WITH_DESKTOP, m_btAllowServiceToInteractWithDesktop);
  171.     DDX_Control(pDX, IDC_LOGON_AS_USER, m_btLogonAsUser);
  172.     DDX_Control(pDX, IDC_LOGON_SYSTEM_ACCOUNT, m_btLogonAsSystem);
  173.     DDX_Control(pDX, IDC_LOGON_PASSWORD, m_ecPassword);
  174.     DDX_Control(pDX, IDC_LOGON_USER_NAME, m_ecUserName);
  175.     DDX_CBIndex(pDX, IDC_COMBO1, m_dwStartupType);
  176.     DDX_Text(pDX, IDC_DESCRIPTION2, m_strDescription);
  177.     DDX_Text(pDX, IDC_DISPLAY_NAME2, m_strDisplayName);
  178.     DDX_Text(pDX, IDC_IMAGE_PATH, m_strBinaryPathName);    
  179.     //}}AFX_DATA_MAP
  180.  
  181.     if( pDX->m_bSaveAndValidate )
  182.     {
  183.         OnSaveData(pDX);
  184.     }
  185.     else
  186.     {
  187.         OnLoadData(pDX);
  188.     }
  189. }
  190.  
  191. void CPageStartup::OnLoadData(CDataExchange* pDX)
  192. {
  193.     m_ecPassword.SetWindowText( INTERNAL_PASSWORD_TEXT );
  194.     m_ecPassword2.SetWindowText( INTERNAL_PASSWORD_TEXT );
  195.     if( IsEmptyString( m_pService->m_strServiceStartName ) || !m_pService->m_strServiceStartName.Compare(_T("LocalSystem")) )
  196.     {
  197.         m_btLogonAsSystem.SetCheck(1);
  198.         OnLogonSystemAccount();
  199.     }
  200.     else
  201.     {
  202.         m_btLogonAsUser.SetCheck(1);
  203.         OnLogonAsUser();
  204.         m_ecUserName.SetWindowText( m_pService->m_strServiceStartName );
  205.     }
  206.     if( m_pService->m_dwServiceType & SERVICE_INTERACTIVE_PROCESS )
  207.     {
  208.         m_btAllowServiceToInteractWithDesktop.SetCheck(BST_CHECKED);
  209.     }
  210.     if( !IsEmptyString(m_strServiceName) )
  211.     {
  212.         m_ecServiceName.SetReadOnly(TRUE);    
  213.         m_ecServiceName.SetWindowText(m_strServiceName);
  214.     }
  215. }
  216.  
  217. BEGIN_MESSAGE_MAP(CPageStartup, CPropertyPage)
  218.     //{{AFX_MSG_MAP(CPageStartup)
  219.     ON_BN_CLICKED(IDC_LOGON_AS_USER, OnLogonAsUser)
  220.     ON_BN_CLICKED(IDC_LOGON_SYSTEM_ACCOUNT, OnLogonSystemAccount)
  221.     ON_BN_CLICKED(IDC_BROWSE_IMAGE_PATH, OnBrowseImagePath)
  222.     //}}AFX_MSG_MAP
  223. END_MESSAGE_MAP()
  224.  
  225. /////////////////////////////////////////////////////////////////////////////
  226. // CPageStartup message handlers
  227.  
  228. void CPageStartup::OnLogonAsUser() 
  229. {
  230.     m_btAllowServiceToInteractWithDesktop.EnableWindow(FALSE);
  231.     m_ecUserName.EnableWindow(TRUE);
  232.     m_ecPassword.EnableWindow(TRUE);
  233.     m_ecPassword2.EnableWindow(TRUE);
  234. }
  235.  
  236. void CPageStartup::OnLogonSystemAccount() 
  237. {
  238.     m_btAllowServiceToInteractWithDesktop.EnableWindow(TRUE);
  239.     m_ecUserName.EnableWindow(FALSE);
  240.     m_ecPassword.EnableWindow(FALSE);
  241.     m_ecPassword2.EnableWindow(FALSE);
  242. }
  243.  
  244. void CPageStartup::OnBrowseImagePath() 
  245. {
  246.     __try
  247.     {
  248.         IOnBrowseImagePath();
  249.     }
  250.     __except( EXCEPTION_EXECUTE_HANDLER )
  251.     {
  252.     }
  253. }
  254.  
  255. void CPageStartup::IOnBrowseImagePath() 
  256. {
  257.     CFileDialog box( TRUE, // BOOL bOpenFileDialog
  258.                      _T(".EXE"), // LPCTSTR lpszDefExt = NULL
  259.                      m_strBinaryPathName, // LPCTSTR lpszFileName = NULL
  260.                      0, // DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
  261.                      _T("EXE files (*.exe)|*.exe|All files (*.*)|(*.*)||"), // LPCTSTR lpszFilter = NULL, 
  262.                      this// CWnd* pParentWnd = NULL
  263.                 );
  264.     if( box.DoModal() == IDOK )
  265.     {
  266.         m_strBinaryPathName = box.GetPathName();
  267.         SetDlgItemText(IDC_IMAGE_PATH, m_strBinaryPathName );
  268.     }
  269. }
  270.