| |

VerySource

 Forgot password?
 Register
Search
View: 677|Reply: 3

How to turn MFC into a system service program

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-3 11:30:01
| Show all posts |Read mode
I have a written MFC program, how to turn it into a system service program, I deleted the window in the MFC program .. I do n’t use ALT
Reply

Use magic Report

1

Threads

27

Posts

24.00

Credits

Newbie

Rank: 1

Credits
24.00

 China

Post time: 2020-1-3 11:45:01
| Show all posts
ding :)
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-4 11:24:01
| Show all posts
Hey, I just wrote a related program

Because it is inconvenient to be completely public

Let me show you two key pieces of code

xo0888@tom.com


// Add service
BOOL AddServices ()
{
char name [100];
char info [200];
char path [300];

printf ("Please enter service name\n\n");
scanf ("% s",&name);
printf ("Please enter a service description\n\n");
scanf ("% s",&info);
printf ("Please enter the program path\n\n");
scanf ("% s",&path);



SC_HANDLE manager = NULL;
SC_HANDLE service = NULL;

if ((manager = OpenSCManager (NULL, NULL, SC_MANAGER_CREATE_SERVICE)) == NULL)
{
printf ("OpenSCManager Error");
}
service = CreateService (
manager, name, info,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
path, 0, 0, 0, 0, 0);
if (service)
printf ("Service created successfully\n\n");
else
printf ("Service creation failed\n\n");

CloseServiceHandle (service);
CloseServiceHandle (manager);
return 0;
}



// Delete service
BOOL DelServices ()
{
char name [100];
SC_HANDLE scm;
    SC_HANDLE service;
    SERVICE_STATUS status;

printf ("Please enter the service name to be deleted\n\n");
scanf ("% s",&name);

if ((scm = OpenSCManager (NULL, NULL, SC_MANAGER_CREATE_SERVICE)) == NULL)
{
printf ("OpenSCManager Error\n");
}
    service = OpenService (scm, name, SERVICE_ALL_ACCESS | DELETE);
    if (! service)
        printf ("OpenService error!\n");

    BOOL isSuccess = QueryServiceStatus (service,&status);
    if (! isSuccess)
        printf ("QueryServiceStatus error!\n");

    if (status.dwCurrentState! = SERVICE_STOPPED)
{

        isSuccess = ControlService (service, SERVICE_CONTROL_STOP,&status);
        if (! isSuccess)
            printf ("Stop Service error!\n");
        Sleep (500);

    }

    isSuccess = DeleteService (service);
    if (! isSuccess)
         printf ("Failed to delete service!");
    else
         printf ("Successfully deleted service!");

    CloseServiceHandle (service);
    CloseServiceHandle (scm);
return 0;
}
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Great Britain

 Author| Post time: 2020-1-5 10:45:01
| Show all posts
I want to know how to turn MFC into a service ..
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list