static bool RunningAsService() { if (System.Environment.UserInteractive) { return(false); } else { Process p = ProcessUtilities.GetParentProcess(); return(p != null && p.ProcessName == "services"); } }