Stopping and starting services using x++

This post with the code snippet helps you how to access the status of any windows services using X++. Also, it is easy to start and stop windows services programmatically.

Before you start running the code, you need to add reference System.ServiceProcess from the AOT references node.

Note : Get_status() method is used to get the status of the service. Code can be modified according to the status of the service.

static void
start_stop_Service(Args _args)
{
    System.ServiceProcess.ServiceController controller = new
System.ServiceProcess.ServiceController();
    ;
    controller.set_MachineName(‘.’);
    controller.set_ServiceName("IISADMIN");
    controller.Stop();
    sleep(500);
    controller.Start();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: