Axapta programming blog: practical HOWTOs

Thursday, April 06, 2006

How to setup Axapta batch server running as user defined windows service

Batch processing allows you to run a job, that requires a large amount of computer power, on another, faster computer. Batch jobs, once they are activated to run, are sent to a batch list, where they are queued, and will eventually be ran. This allows you to have jobs run without tying up your computer's power, meaning that you can continue to work while your job is being run. But, you should have in mind that it's not enough to schedule your job in Axapta using a Batch tab on the form. Even though your job will be put into a queue, it will not be executed until Axapta is started as a batch executer (processing instance). In order to have this kind of Axapta running you can simply start one more instance of Axapta client and go to Basic -> Periodic -> Batch -> Processing

specify there batch group which this instance should take care of and that's basically it. But, having one more instance of Axapta running will make you a trouble when for example server was suddenly restarted. In order to start an Axapta client as a batch server instance you can specify special command line parameter using -startupcmd switch.

It should look like this: -startupcmd=batch.

The starting of batch using -startupcmd parameter involves these four classes:

SysStartupCmdBatchRun and

In order to specify a batch group using the -startupcmd parameter use this kind of startup parameter: startupcmd=batch_invoice

The thing is, that SysStartupCmd class takes any '_' sign as a separator for the startupCmd, treating batch_invoice as the command batch with invoice as the parameter. The Application class redirects control to SysStartupCmd when the -startupcmd parameter are specified. SysStartupCmd constructs a child class based on the command: SysStartupCmdBatchRun. The SysStartupCmdBatchRun class instantiates a BatchRun and calls run. Modifying infoRun as this:

void infoRun()

batchRun batchRun = new batchRun();
batchRun.parmGroupId(parm); // added;


will get your batch server up and running with a specified batch group right from the command line!

This seems to be it, but there is one more problem appears! How to make sure that this Axapta client (aka batch server) always starts when your server is started? Well, you can put it into your windows Startup menu, but then you have to make sure to login with your profile every time server starts! This is not appropriate solution for the server, so we will use standard windows services. To setup user defined windows server we will need to make some small modifications into the windows registry. Here are 6 easy steps to perform:

1. At a MS-DOS command prompt(running CMD.EXE), type the following command:

[path]\INSTSRV.EXE [My Service] [path]\SRVANY.EXE

where path is the drive and directory of the Windows NT Resource Kit (i.e., C:\RESKIT) and My Service is the name of the service you are creating. Example:

C:\Program Files\Resource Kit\Instsrv.exe Notepad C:\Program Files\Resource Kit\Srvany.exe

NOTE: To verify that the service was created correctly, check the registry to verify that the ImagePath value under

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\service name

is set to point to SRVANY.EXE. If this is not set correctly, the service will stop shortly after it starts and return an Event ID 7000 "The service name failed to start."

NOTE: You should back up the registry before you edit it.

2. Run Registry Editor (Regedt32.exe)and locate the following subkey:


3. From the Edit menu, click Add Key. Type the following and click OK:

Key Name: Parameters
Class : [leave blank]

4. Select the Parameters key.

5. From the Edit menu, click Add Value. Type the following and click OK:

Value Name: Application
Data Type : REG_SZ
String : [path]\[application.ext]

where [path]\[application.ext] is the drive and full path to the application executable including the extension (i.e., C:\WinNT\Notepad.exe) In our case you should type something like this:

[path to your axapta client bin]\ax32.exe startupcmd=batch_yourBatchGroup

6. Close Registry Editor.

By default, a newly created service it configured to run Automatically when the system is restarted. To change this setting to Manual, run the Services applet from Control Panel and change the Startup value to Manual. A service set to Manual can be started in one of several ways:

- From the Services applet in Control Panel

- From a MS-DOS command prompt, type the following: NET START [My Service]

- Use the Sc.exe utility from the Resource Kit. Type the following from a MS-DOS command prompt:

[path]\Sc.exe start [my service]

where [path] is the drive and directory of the Windows NT Resource Kit (i.e., C:\Reskit).

IMPORTANT: Before you edit the registry, make sure you understand how to restore it if a problem occurs. For information on how to do this, view the "Restoring the Registry" or the "Restoring a Registry Key" online Help topics in Registry Editor.


  • Great. This is exactly what I need. is there any chance that you could put a more detailed description with pictures on the registry key creation please? I dont quite get that bit.



    By Blogger Biggles, at 2:17 AM  

  • HI

    I would like to add a .NET user control in DAX... is it possible ? if yes then how ?

    By Blogger SHAJI P.D., at 3:01 AM  

  • Hi,

    Congratz for your blog, it has really interesting articles :)

    Just one little thing ...

    srvany isn't best service manager for this work ...

    for example : If you kill the Axapta session that is running batch from another Axapta session ... srvany ignores this and it seems to be running while in fact ... Axapta session is stopped :/

    I was looking for another service manager over the net and I found nssm.exe ... it works perfectly for this case.
    When Axapta session is forced to be closed ... it restarts the session again.

    I've explained my own way to setting up "Running batch as a service" here

    But ... I'm sorry .. it's in Spanish language

    Well, congratz again for your page. Keep working this way :)

    And ... sorry for my english :/

    Best Regards,

    A Dynamics AX (Axapta) tricks site in Spanish language :)

    By Blogger Mkz, at 2:48 AM  

  • Thanks, this is great! I'm having one problem though, I have never changed in any Classes in axapta before so I'm not sure if I'm doing it right but I edit the 'SysStartupCmdbatchRun' and add the line: batchRun.parmGroupId(parm);
    (so it looks just like the example) and then save and everything looks good but when I restart Axapta it has been changed back to the original state. What do I have to do to keep the change?

    By Anonymous crazyzed, at 10:53 AM  

  • Hi crazyEd,

    I think this is a license problem.

    In some places where it happened to me I solved it exporting and re-importing the class just after modifications are made.

    I mean you can make your modifications on the class and export it, then you can re-import it again.

    It works for me many times :)


    A Dynamics AX (Axapta) tricks site in Spanish language :)

    By Blogger Mkz, at 2:42 AM  

  • Hi,

    I followed all the steps described here, but couldn't get my AX 3 SP3 batch server running. However win service is in status started, but it seems that batch user couldn't login into axapta.
    I created new user in axapta, filled his network name (windows user with and then without domain). Tried also to specify the command line switches for specifying user name, also tried to run win batch service under this user. Still no success.
    Is there some requirement to have windows active directory integration turned on?

    By Anonymous bishop, at 8:03 AM  

  • Does anyone know how to capture any error messages produced in a batch server and send them to event log or email?

    By Anonymous Anonymous, at 4:11 AM  

  • do you know if can i pass a second parameter to the startupcmd ?
    for example :
    -startupcmd=batch_BatchGroup_Company ?

    Thank you

    By Blogger TAPAN, at 1:29 AM  

  • No, you can't post second parameter in standard AX. But it is easy to fix - look into SysStartupCmd class.

    By Blogger AxaptaBuilder, at 2:30 AM  

  • ok i fixed it ..
    it works well but just for one batch, if i do the same process for another batch, it open a new Axapta window. So do you know a way to process all the process in the same Axapta window ??

    because i have around 40 batch to process :D

    By Blogger TAPAN, at 7:52 AM  

Post a Comment

Links to this post:

Create a Link

<< Home