Skip to content

Commit

Permalink
This was totally wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jun 8, 2022
1 parent 5ab0799 commit da55ab7
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions src/interactivity/base/RemoteConsoleControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "../../inc/HostSignals.hpp"

#include "../../interactivity/inc/ServiceLocator.hpp"

using namespace Microsoft::Console::Interactivity;

RemoteConsoleControl::RemoteConsoleControl(HANDLE signalPipe) :
Expand Down Expand Up @@ -57,12 +59,50 @@ template<typename T>

[[nodiscard]] NTSTATUS RemoteConsoleControl::SetForeground(_In_ HANDLE hProcess, _In_ BOOL fForeground)
{
HostSignalSetForegroundData data{};
data.sizeInBytes = sizeof(data);
data.processId = HandleToULong(hProcess);
data.isForeground = fForeground;
// return LOG_IF_NTSTATUS_FAILED(ServiceLocator::LocateConsoleControl()->SetForeground(hProcess, fForeground));

enum ControlType
{
ConsoleSetVDMCursorBounds,
ConsoleNotifyConsoleApplication,
ConsoleFullscreenSwitch,
ConsoleSetCaretInfo,
ConsoleSetReserveKeys,
ConsoleSetForeground,
ConsoleSetWindowOwner,
ConsoleEndTask,
};
CONSOLESETFOREGROUND Flags;
Flags.hProcess = hProcess;
Flags.bForeground = fForeground;
auto control = [](_In_ ControlType ConsoleCommand,
_In_reads_bytes_(ConsoleInformationLength) PVOID ConsoleInformation,
_In_ DWORD ConsoleInformationLength) -> NTSTATUS {
{
wil::unique_hmodule _hUser32{ LoadLibraryW(L"user32.dll") };
if (_hUser32)
{
typedef NTSTATUS(WINAPI * PfnConsoleControl)(ControlType Command, PVOID Information, DWORD Length);

static auto pfn = (PfnConsoleControl)GetProcAddress(_hUser32.get(), "ConsoleControl");

if (pfn != nullptr)
{
return pfn(ConsoleCommand, ConsoleInformation, ConsoleInformationLength);
}
}

return STATUS_UNSUCCESSFUL;
}
};
return LOG_IF_NTSTATUS_FAILED(control(ControlType::ConsoleSetForeground, hProcess, fForeground));

// HostSignalSetForegroundData data{};
// data.sizeInBytes = sizeof(data);
// data.processId = HandleToULong(hProcess);
// data.isForeground = fForeground;

return _SendTypedPacket(_pipe.get(), HostSignals::SetForeground, data);
// return _SendTypedPacket(_pipe.get(), HostSignals::SetForeground, data);
}

[[nodiscard]] NTSTATUS RemoteConsoleControl::EndTask(_In_ HANDLE hProcessId, _In_ DWORD dwEventType, _In_ ULONG ulCtrlFlags)
Expand Down

0 comments on commit da55ab7

Please sign in to comment.