A device for automatic dispensing of a maintenance agent, such as an anti-icing agent or a de-icing agent, on specific parts of a rolling stock, such as a locomotive or a carriage, travelling on a railway track, the device comprising: a dispensing unit adapted to dispense said maintenance agent on said specific parts of the rolling stock, a detection unit configured to generate a detection signal before said rolling stock reaches the dispensing unit, a sensor unit configured to determine a position of a part of the rolling stock and generate a position signal, and for determining a velocity of the rolling stock, and a control unit which is configured to receive said detection signal from said detection unit, receive said position signal from said sensor unit, determine a dispensing schedule based on said rolling-stock velocity, said dispensing schedule comprising a time schedule having data about when to dispense the maintenance agent from the dispensing unit and information about a time duration of how long to dispense the maintenance agent from the dispensing unit, and transmit a control signal to the dispensing unit, wherein the control signal is configured to control said dispensing unit based on said dispensing schedule, characterised in that the detection unit is configured to generate an identification signal, said identification signal comprising data about an identity of the rolling stock, and wherein the control unit is configured to determine if a rolling stock is approved for dispensing operation based on said identification signal. a dispensing unit adapted to dispense said maintenance agent on said specific parts of the rolling stock, a detection unit configured to generate a detection signal before said rolling stock reaches the dispensing unit, a sensor unit configured to determine a position of a part of the rolling stock and generate a position signal, and for determining a velocity of the rolling stock, and a control unit which is configured to receive said detection signal from said detection unit, receive said position signal from said sensor unit, determine a dispensing schedule based on said rolling-stock velocity, said dispensing schedule comprising a time schedule having data about when to dispense the maintenance agent from the dispensing unit and information about a time duration of how long to dispense the maintenance agent from the dispensing unit, and transmit a control signal to the dispensing unit, wherein the control signal is configured to control said dispensing unit based on said dispensing schedule, characterised in that the detection unit is configured to generate an identification signal, said identification signal comprising data about an identity of the rolling stock, and wherein the control unit is configured to determine if a rolling stock is approved for dispensing operation based on said identification signal. receive said detection signal from said detection unit, receive said position signal from said sensor unit, determine a dispensing schedule based on said rolling-stock velocity, said dispensing schedule comprising a time schedule having data about when to dispense the maintenance agent from the dispensing unit and information about a time duration of how long to dispense the maintenance agent from the dispensing unit, and transmit a control signal to the dispensing unit, wherein the control signal is configured to control said dispensing unit based on said dispensing schedule,