Click here to Skip to main content
15,897,187 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Need help with registry Pin
S Douglas5-Jan-07 1:26
professionalS Douglas5-Jan-07 1:26 
AnswerRe: Need help with registry Pin
ThatsAlok5-Jan-07 3:01
ThatsAlok5-Jan-07 3:01 
QuestionGS option Pin
rp_suman4-Jan-07 18:18
rp_suman4-Jan-07 18:18 
AnswerRe: GS option Pin
Rajesh R Subramanian4-Jan-07 18:51
professionalRajesh R Subramanian4-Jan-07 18:51 
QuestionATL Service VC 6.0 .. Pin
Sakthiu4-Jan-07 18:00
Sakthiu4-Jan-07 18:00 
AnswerRe: ATL Service VC 6.0 .. Pin
Joan M4-Jan-07 19:42
professionalJoan M4-Jan-07 19:42 
AnswerRe: ATL Service VC 6.0 .. Pin
Joan M4-Jan-07 19:45
professionalJoan M4-Jan-07 19:45 
AnswerRe: ATL Service VC 6.0 .. Pin
Joan M4-Jan-07 19:47
professionalJoan M4-Jan-07 19:47 
And also a little bit of code...

inline BOOL CServiceModule::Install()
{
    if (IsInstalled())
        return TRUE;

    SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (hSCM == NULL)
    {
        MessageBox(NULL, _T("Couldn't open service manager"), m_szServiceName, MB_OK);
        return FALSE;
    }

    // Get the executable file path
    TCHAR szFilePath[_MAX_PATH];
    ::GetModuleFileName(NULL, szFilePath, _MAX_PATH);

    SC_HANDLE hService = ::CreateService(
        hSCM, m_szServiceName, m_szServiceName,
        SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
        SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
        szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);

    if (hService == NULL)
    {
        ::CloseServiceHandle(hSCM);
        MessageBox(NULL, _T("Couldn't create service"), m_szServiceName, MB_OK);
        return FALSE;
    }

    ::CloseServiceHandle(hService);
    ::CloseServiceHandle(hSCM);
    return TRUE;
}

inline BOOL CServiceModule::Uninstall()
{
    if (!IsInstalled()) return TRUE;

    SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

    if (hSCM == NULL)
    {
        MessageBox(NULL, _T("Couldn't open service manager"), m_szServiceName, MB_OK);
        return FALSE;
    }

    SC_HANDLE hService = ::OpenService(hSCM, m_szServiceName, SERVICE_STOP | DELETE);

    if (hService == NULL)
    {
        ::CloseServiceHandle(hSCM);
        MessageBox(NULL, _T("Couldn't open service"), m_szServiceName, MB_OK);
        return FALSE;
    }
    SERVICE_STATUS status;
    ::ControlService(hService, SERVICE_CONTROL_STOP, &status);

    BOOL bDelete = ::DeleteService(hService);
    ::CloseServiceHandle(hService);
    ::CloseServiceHandle(hSCM);

    if (bDelete)
        return TRUE;

    MessageBox(NULL, _T("Service could not be deleted"), m_szServiceName, MB_OK);
    return FALSE;
}


Hope this helps.

I think I've missed the name, you must not register the service, you must install it before being able to start it.
QuestionPointer to structure Pin
Vancouver4-Jan-07 12:49
Vancouver4-Jan-07 12:49 
AnswerRe: Pointer to structure Pin
Christian Graus4-Jan-07 12:55
protectorChristian Graus4-Jan-07 12:55 
GeneralRe: Pointer to structure Pin
Vancouver4-Jan-07 13:04
Vancouver4-Jan-07 13:04 
GeneralRe: Pointer to structure Pin
Christian Graus4-Jan-07 13:35
protectorChristian Graus4-Jan-07 13:35 
GeneralRe: Pointer to structure Pin
Vancouver4-Jan-07 14:00
Vancouver4-Jan-07 14:00 
GeneralRe: Pointer to structure Pin
Christian Graus4-Jan-07 14:29
protectorChristian Graus4-Jan-07 14:29 
AnswerRe: Pointer to structure Pin
Mark Salsbery4-Jan-07 12:57
Mark Salsbery4-Jan-07 12:57 
GeneralRe: Pointer to structure Pin
Vancouver4-Jan-07 13:08
Vancouver4-Jan-07 13:08 
GeneralRe: Pointer to structure Pin
James R. Twine4-Jan-07 13:17
James R. Twine4-Jan-07 13:17 
AnswerRe: Pointer to structure Pin
prasad_som4-Jan-07 17:06
prasad_som4-Jan-07 17:06 
AnswerRe: Pointer to structure Pin
Vancouver4-Jan-07 18:48
Vancouver4-Jan-07 18:48 
GeneralRe: Pointer to structure Pin
Joe Woodbury4-Jan-07 18:53
professionalJoe Woodbury4-Jan-07 18:53 
GeneralRe: Pointer to structure Pin
Vancouver4-Jan-07 19:45
Vancouver4-Jan-07 19:45 
GeneralRe: Pointer to structure Pin
David Crow5-Jan-07 3:00
David Crow5-Jan-07 3:00 
GeneralRe: Pointer to structure Pin
Vancouver5-Jan-07 4:41
Vancouver5-Jan-07 4:41 
GeneralRe: Pointer to structure Pin
prasad_som4-Jan-07 19:11
prasad_som4-Jan-07 19:11 
QuestionProblems with Sleep() in thread Pin
acerunner3164-Jan-07 11:42
acerunner3164-Jan-07 11:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.