For the Small Generators (5-8KVA) we have here, ones with an Electric Start Keyswitch,
when the switch is in the off position, it does 2 things:
Shorts the Magneto to the Chassis (Stops Spark),
and
Connects the Fuel Cutoff Solenoid to the 12v Supply the generator produces. When the Generator stops spinning, the 12v Supply goes away, and the Fuel Cutoff Solenoid (Under the carburetor ?spelling?) releases.
If you have this start switch configuration, then just use a multimeter to check which pins are shorted when the switch is in the Off Position (Make sure battery is disconnected when you do these tests). Then put in a Double Pole Double Throw Relay, and set it so that when it looses power, it Shorts out the same wires that the Switch does (Use the NC Contacts on the Relay). That way the Generator will only run when the Switch is in the On Position, AND the Relay is Energised. If the switch is turned off, or the relay looses power, then those systems will be shorted, and the generator will shut off.