Using the ParentProcessUtilities struct from this answer about finding a parent process, you can do this:
static bool RunningAsService() {
var p = ParentProcessUtilities.GetParentProcess();
return ( p != null && p.ProcessName == "services" );
}
Note that the process name for the parent process does not include the extension ".exe".