public static bool CallFromWizard() { if (Ops.Operation.CallFromWizardFlag == false) { return(false); } Process currentProcess = Process.GetCurrentProcess(); IntPtr currPtr = new IntPtr(currentProcess.Id); List <IntPtr> result = new List <IntPtr>(); GCHandle listHandle = GCHandle.Alloc(result); try { ExcelUtil.WindowEnumDelegate childProc = new ExcelUtil.WindowEnumDelegate(ExcelUtil.WindowEnumProc); ExcelUtil.EnumChildWindows(IntPtr.Zero, childProc, GCHandle.ToIntPtr(listHandle)); foreach (IntPtr ptr in result) { if (ptr == currPtr) { return(true); } } } finally { if (listHandle.IsAllocated) { listHandle.Free(); } } return(false); }