/// <summary> /// Returns the InternetSecurityZone assign to the currently loaded document /// </summary> /// <returns></returns> protected InternetSecurityZone GetSecurityZone() { IOleCommandTargetWithExecParams target = (IOleCommandTargetWithExecParams)Document; object input = null; object output = null; target.Exec(MSHTML, GETFRAMEZONE, OpenLiveWriter.Interop.Com.OLECMDEXECOPT.DODEFAULT, ref input, ref output); UInt32 zoneInt = (UInt32)output; InternetSecurityZone zone = (InternetSecurityZone)zoneInt; return(zone); }
/// <summary> /// Execute the command with an input and output parameter /// </summary> public override void Execute() { // get the command target IOleCommandTargetWithExecParams target = GetCommandTarget(); // if there is a target, execute the command on it if (target != null) { object input = null; object output = null; try { target.Exec( CGID_IWebBrowserPrivate, m_cmdID, OpenLiveWriter.Interop.Com.OLECMDEXECOPT.DODEFAULT, ref input, ref output); } catch (COMException e) { // The InternetOptions command throws a spurious exception // every time it is invoked -- ignore it. if (m_cmdID != InternetOptions) { throw e; } } } // should never try to execute a command if there is no target! // (caller should have detected this via QueryStatus) else { Debug.Assert(false, "Attempted to execute a command when there is no valid target"); } }
public static void Run(string appId, LaunchAction action, string[] args) { Mutex m_mutex = new Mutex(false, @"Local\" + appId); RunningObjectTable rot = new RunningObjectTable(); for (int i = 0; i < 120; i++) // wait for ~60 seconds { if (m_mutex.WaitOne(1, false)) { // we are the first instance try { using (rot.Register(appId, new OleCommandTargetImpl(action))) { action(args, true); } return; } finally { m_mutex.ReleaseMutex(); } } else { // we are not the first instance IOleCommandTargetWithExecParams instance = rot.GetObject(appId) as IOleCommandTargetWithExecParams; if (instance != null) { try { object dummy = null; object processId = null; instance.Exec(Guid.Empty, 0, OLECMDEXECOPT.DODEFAULT, ref dummy, ref processId); User32.AllowSetForegroundWindow((int)processId); object objArgs = args; object result = null; instance.Exec(Guid.Empty, 1, OLECMDEXECOPT.DODEFAULT, ref objArgs, ref result); if (result is bool && (bool)result) { return; } } catch (Exception e) { Trace.WriteLine(e.ToString()); } finally { Marshal.ReleaseComObject(instance); } } } Thread.Sleep(500); } Trace.WriteLine(appId + " could not start!"); }