protected override void OnCustomCommand(int command) { switch (command) { case 128: _Player.PlayAudio(); break; case 129: SpawnInSession.StartProcessInSession("notepad.exe", 1); break; } }
public void StartSessionMuter(uint sessId) { // test if we already have the session data if (_MuterSessions.ContainsKey(sessId)) { var pipes = _MuterSessions[sessId]; // ensure the pipe is working try { pipes.Item1.WriteByte((byte)SessionMuter.Commands.PING); pipes.Item2.ReadByte(); // do nothing if success return; } catch (Exception) { // very likely broken pipe. erase this pipe and create new child. CloseSessionMuter(sessId); } } // create new anon pipes AnonymousPipeServerStream pipeServerOut = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable); AnonymousPipeServerStream pipeServerIn = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable); // open process bool success = false; try { success = SpawnInSession.StartProcessInSession(Assembly.GetExecutingAssembly().Location, sessId, $"ProcessName.exe startsessionmuter {Process.GetCurrentProcess().Id} {pipeServerOut.GetClientHandleAsString()} {pipeServerIn.GetClientHandleAsString()}"); } catch (Exception) { success = false; } pipeServerIn.DisposeLocalCopyOfClientHandle(); pipeServerOut.DisposeLocalCopyOfClientHandle(); if (success) { _MuterSessions[sessId] = new Tuple <PipeStream, PipeStream>(pipeServerOut, pipeServerIn); } else { pipeServerOut.Dispose(); pipeServerIn.Dispose(); } }
public AudioPlayer(string audioFile, float?playingVolume) { _Pid = Process.GetCurrentProcess().Id; AudioFile = audioFile; if (playingVolume != null) { AdjustVolumeOnPlay = true; TargetVolume = (float)playingVolume; } else { AdjustVolumeOnPlay = false; } // start session muter uint activeSess = SpawnInSession.GetCurrentUserSessionId(); if (activeSess != SpawnInSession.INVALID_SESSION_ID) { StartSessionMuter(activeSess); } }