Software, Drivers, Profiles, etc...
You can find an example Starting & Ending G-code Script on the Starting & Ending G-code Scripts page.