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 >
Wrap
C/C++ Source or Header
|
2005-01-05
|
9KB
|
270 lines
// PageStartup.cpp : implementation file
//
#include "stdafx.h"
#include "pserv2.h"
#include "PageStartup.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPageStartup property page
#define INTERNAL_PASSWORD_TEXT _T("\x18\x60\x08\x18\x60\x08\x18\x60\x08")
IMPLEMENT_DYNCREATE(CPageStartup, CPropertyPage)
void CPageStartup::SetService(CService* instance)
{
m_pService = instance;
if( m_pService != NULL )
{
m_dwStartupType = m_pService->m_dwStartType;
m_strDescription = m_pService->m_strDescription;
m_strDisplayName = m_pService->m_strDisplayName;
m_strBinaryPathName = m_pService->m_strBinaryPathName;
m_strServiceName = m_pService->m_strServiceName;
}
}
CPageStartup::CPageStartup()
: CPropertyPage(CPageStartup::IDD),
m_pService( 0 )
{
//{{AFX_DATA_INIT(CPageStartup)
m_dwStartupType = 0;
m_strDescription = _T("");
m_strDisplayName = _T("");
m_strBinaryPathName = _T("");
//}}AFX_DATA_INIT
}
CPageStartup::~CPageStartup()
{
}
void PASCAL DDX_VerifySamePassword(CDataExchange * pDX, CEdit& ecPassword1, CEdit& ecPassword2)
{
if(pDX->m_bSaveAndValidate )
{
CString str1, str2;
ecPassword1.GetWindowText(str1);
ecPassword2.GetWindowText(str2);
pDX->PrepareCtrl(ecPassword1.GetDlgCtrlID());
if( str1.Compare(INTERNAL_PASSWORD_TEXT) == 0 )
{
AfxMessageBox(_T("You must specify a password"));
pDX->Fail();
}
if( str1.Compare(str2) != 0 )
{
AfxMessageBox(_T("Both passwords must be the same"));
pDX->Fail();
}
}
}
void CPageStartup::OnSaveData(CDataExchange* pDX)
{
m_ecServiceName.GetWindowText(m_strServiceName);
if( IsEmptyString(m_strServiceName) )
{
AfxMessageBox(_T("Service name must not be empty"));
pDX->m_hWndLastControl = m_ecServiceName;
pDX->Fail();
}
if( m_strDescription.Compare(m_pService->m_strDescription) != 0 )
{
m_pService->m_strDescription = m_strDescription;
m_pService->m_dwChangeFlags |= CHANGED_DESCRIPTION;
}
if( m_strDisplayName.Compare(m_pService->m_strDisplayName) != 0 )
{
if( IsEmptyString(m_strDisplayName) )
{
AfxMessageBox(_T("Display name must not be empty"));
pDX->m_hWndLastControl = ::GetDlgItem(m_hWnd, IDC_DISPLAY_NAME2);
pDX->Fail();
}
m_pService->m_strDisplayName = m_strDisplayName;
m_pService->m_dwChangeFlags |= CHANGED_DISPLAYNAME;
}
if( m_strBinaryPathName.Compare(m_pService->m_strBinaryPathName) != 0 )
{
if( IsEmptyString(m_strBinaryPathName) )
{
AfxMessageBox(_T("Image path must not be empty"));
pDX->m_hWndLastControl = ::GetDlgItem(m_hWnd, IDC_IMAGE_PATH);
pDX->Fail();
}
m_pService->m_strBinaryPathName = m_strBinaryPathName;
m_pService->m_dwChangeFlags |= CHANGED_BINARYPATH;
}
if( (DWORD) m_dwStartupType != m_pService->m_dwStartType )
{
m_pService->m_dwStartType = (DWORD) m_dwStartupType;
m_pService->m_dwChangeFlags |= CHANGED_START_TYPE;
}
BOOL bWasSystemAccount = IsEmptyString( m_pService->m_strServiceStartName ) || !m_pService->m_strServiceStartName.Compare(_T("LocalSystem"));
if( m_btLogonAsSystem.GetCheck() )
{
if( !bWasSystemAccount )
{
// changed logon to system
m_pService->m_strServiceStartName = "";
m_pService->m_dwChangeFlags |= CHANGED_LOGON_SYSTEM;
}
DWORD dwBitMask = m_btAllowServiceToInteractWithDesktop.GetCheck() ? SERVICE_INTERACTIVE_PROCESS : 0;
if( (m_pService->m_dwServiceType & SERVICE_INTERACTIVE_PROCESS) != dwBitMask )
{
if( dwBitMask )
{
m_pService->m_dwServiceType |= (SERVICE_INTERACTIVE_PROCESS);
}
else
{
m_pService->m_dwServiceType &= ~(SERVICE_INTERACTIVE_PROCESS);
}
m_pService->m_dwChangeFlags |= CHANGED_ALLOW_UI;
}
}
else
{
CString strUserName, strPassword;
m_ecUserName.GetWindowText(strUserName);
m_ecPassword.GetWindowText(strPassword);
if( bWasSystemAccount ||
(strUserName.Compare(m_pService->m_strServiceStartName) != 0) )
{
DDX_VerifySamePassword(pDX,m_ecPassword, m_ecPassword2 );
// changed logon to system
m_pService->m_strServiceStartName = strUserName;
m_pService->m_strServiceStartPassword = strPassword;
m_pService->m_dwChangeFlags |= CHANGED_LOGON_USER;
if( m_pService->m_dwServiceType & SERVICE_INTERACTIVE_PROCESS )
{
m_pService->m_dwServiceType &= ~SERVICE_INTERACTIVE_PROCESS;
m_pService->m_dwChangeFlags |= CHANGED_ALLOW_UI;
}
}
}
if( IsEmptyString(m_pService->m_strServiceName) )
{
m_pService->m_strServiceName = m_strServiceName;
}
}
void CPageStartup::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPageStartup)
DDX_Control(pDX, IDC_SERVICE_NAME, m_ecServiceName);
DDX_Control(pDX, IDC_LOGON_PASSWORD2, m_ecPassword2);
DDX_Control(pDX, IDC_ALLOW_SERVICE_TO_INTERACT_WITH_DESKTOP, m_btAllowServiceToInteractWithDesktop);
DDX_Control(pDX, IDC_LOGON_AS_USER, m_btLogonAsUser);
DDX_Control(pDX, IDC_LOGON_SYSTEM_ACCOUNT, m_btLogonAsSystem);
DDX_Control(pDX, IDC_LOGON_PASSWORD, m_ecPassword);
DDX_Control(pDX, IDC_LOGON_USER_NAME, m_ecUserName);
DDX_CBIndex(pDX, IDC_COMBO1, m_dwStartupType);
DDX_Text(pDX, IDC_DESCRIPTION2, m_strDescription);
DDX_Text(pDX, IDC_DISPLAY_NAME2, m_strDisplayName);
DDX_Text(pDX, IDC_IMAGE_PATH, m_strBinaryPathName);
//}}AFX_DATA_MAP
if( pDX->m_bSaveAndValidate )
{
OnSaveData(pDX);
}
else
{
OnLoadData(pDX);
}
}
void CPageStartup::OnLoadData(CDataExchange* pDX)
{
m_ecPassword.SetWindowText( INTERNAL_PASSWORD_TEXT );
m_ecPassword2.SetWindowText( INTERNAL_PASSWORD_TEXT );
if( IsEmptyString( m_pService->m_strServiceStartName ) || !m_pService->m_strServiceStartName.Compare(_T("LocalSystem")) )
{
m_btLogonAsSystem.SetCheck(1);
OnLogonSystemAccount();
}
else
{
m_btLogonAsUser.SetCheck(1);
OnLogonAsUser();
m_ecUserName.SetWindowText( m_pService->m_strServiceStartName );
}
if( m_pService->m_dwServiceType & SERVICE_INTERACTIVE_PROCESS )
{
m_btAllowServiceToInteractWithDesktop.SetCheck(BST_CHECKED);
}
if( !IsEmptyString(m_strServiceName) )
{
m_ecServiceName.SetReadOnly(TRUE);
m_ecServiceName.SetWindowText(m_strServiceName);
}
}
BEGIN_MESSAGE_MAP(CPageStartup, CPropertyPage)
//{{AFX_MSG_MAP(CPageStartup)
ON_BN_CLICKED(IDC_LOGON_AS_USER, OnLogonAsUser)
ON_BN_CLICKED(IDC_LOGON_SYSTEM_ACCOUNT, OnLogonSystemAccount)
ON_BN_CLICKED(IDC_BROWSE_IMAGE_PATH, OnBrowseImagePath)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPageStartup message handlers
void CPageStartup::OnLogonAsUser()
{
m_btAllowServiceToInteractWithDesktop.EnableWindow(FALSE);
m_ecUserName.EnableWindow(TRUE);
m_ecPassword.EnableWindow(TRUE);
m_ecPassword2.EnableWindow(TRUE);
}
void CPageStartup::OnLogonSystemAccount()
{
m_btAllowServiceToInteractWithDesktop.EnableWindow(TRUE);
m_ecUserName.EnableWindow(FALSE);
m_ecPassword.EnableWindow(FALSE);
m_ecPassword2.EnableWindow(FALSE);
}
void CPageStartup::OnBrowseImagePath()
{
__try
{
IOnBrowseImagePath();
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
}
}
void CPageStartup::IOnBrowseImagePath()
{
CFileDialog box( TRUE, // BOOL bOpenFileDialog
_T(".EXE"), // LPCTSTR lpszDefExt = NULL
m_strBinaryPathName, // LPCTSTR lpszFileName = NULL
0, // DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
_T("EXE files (*.exe)|*.exe|All files (*.*)|(*.*)||"), // LPCTSTR lpszFilter = NULL,
this// CWnd* pParentWnd = NULL
);
if( box.DoModal() == IDOK )
{
m_strBinaryPathName = box.GetPathName();
SetDlgItemText(IDC_IMAGE_PATH, m_strBinaryPathName );
}
}