public bool Execute(string file, string param, string dir) { IntPtr sessionTokenHandle = IntPtr.Zero; try { sessionTokenHandle = SessionFinder.GetLocalInteractiveSession(); if (sessionTokenHandle != IntPtr.Zero) { ProcessLauncher.StartProcessAsUser(file, param, dir, sessionTokenHandle); } } catch (System.ComponentModel.Win32Exception ex) { if (ex.NativeErrorCode == 1008) //ERROR_NO_TOKEN: No user is logged-on { return(false); } throw ex; } catch (Exception ex) { //What are we gonna do? throw ex; } finally { if (sessionTokenHandle != IntPtr.Zero) { NativeMethods.CloseHandle(sessionTokenHandle); } } return(true); }
public void Execute(object source, ElapsedEventArgs e) { IntPtr sessionTokenHandle = IntPtr.Zero; try { sessionTokenHandle = SessionFinder.GetLocalInteractiveSession(); if (sessionTokenHandle != IntPtr.Zero) { ProcessLauncher.StartProcessAsUser("cmd.exe", "cmd.exe /C start iexplore https://www.youtube.com/watch?v=oHg5SJYRHA0&t=1s", sessionTokenHandle); } } finally { if (sessionTokenHandle != IntPtr.Zero) { NativeMethods.CloseHandle(sessionTokenHandle); } } }
private void StartJumpingIn(string gamerTag, object param) { // Turn off background updates to friend profiles. LiveManager.FriendUpdatesEnabled = false; // Turn off background updates to friend joinable states. LiveManager.JoinableUpdatesEnabled = false; // TODO: Warn of potentially "destructive" action. Player may have invited people to join their session. // This action closes the local session, invalidating the invites. LiveManager.CloseSession(); // Cancel pending friend profile and joinable state queries. LiveManager.ClearQueuedOperations(null); // Show the "initializing sharing room" notification dialog. openingSharingRoomMessage.Activate(); // Start finding our friend's network session. SessionFinder finderOp = new SessionFinder(gamerTag, FindSessionComplete_Join, param, this); finderOp.Queue(); }
private void FindSessionComplete_Join(AsyncLiveOperation op) { UIGridShareFriendElement friendElement = op.Param as UIGridShareFriendElement; if (op.Succeeded) { SessionFinder finderOp = op as SessionFinder; if (finderOp.AvailableSessions.Count > 0) { // We found an available session. Before we can start joining it, we must cancel all pending LIVE // operations. Some of them may be queued attempts to find joinable sessions (incompatible with // joining a session), and the others will be profile updates (no longer relevant as we're leaving // this screen). LiveManager.ClearQueuedOperations(null); openingSharingRoomMessage.Activate(); // Start joining the session. AvailableSessionJoiner joinerOp = new AvailableSessionJoiner(finderOp.AvailableSessions[0], JoinSessionComplete_ActivateSharingScreen, op.Param, this); // This operation must start before the network session updates again or // the available sessions collection becomes invalid for some reason. joinerOp.Queue(true); finderOp.AvailableSessions = null; // prevent dispose, since we passed the available session to the joiner. // TODO: Show joining session message here.. } else { // We didn't find the session. Re-enable the share hub's periodic LIVE operations. LiveManager.FriendUpdatesEnabled = true; LiveManager.JoinableUpdatesEnabled = true; // Session is no longer available, so mark friend as not joinable. // This may change if we detect they are joinable again. if (friendElement != null) { friendElement.Friend.IsJoinable = false; } // Not leaving the share hub anymore, since we failed to join the session. shared.grid.Active = true; openingSharingRoomMessage.Deactivate(); } } else { // We didn't find the session. Re-enable the share hub's periodic LIVE operations. LiveManager.FriendUpdatesEnabled = true; LiveManager.JoinableUpdatesEnabled = true; // The join operation failed, so mark friend as not joinable. // This may change if we detect they are joinable again. if (friendElement != null) { friendElement.Friend.IsJoinable = false; } // Not leaving the share hub anymore, since we failed to join the session. shared.grid.Active = true; openingSharingRoomMessage.Deactivate(); } }