# WindowsRHotKey

Simulates Windows + R and Run

```
DWORD CreateProcessByWindowsRHotKeyW(_In_ PWCHAR FullPathToBinary)
{
    INPUT ExecuteHotkey[4] = { 0 };
    INPUT BinaryInputBuffer[2] = { 0 };
    INPUT ExecuteBinaryCommand[2] = { 0 };
    UINT Result = ERROR_SUCCESS;
    HWND RunWindow = NULL;

    ExecuteHotkey[0].type = INPUT_KEYBOARD;
    ExecuteHotkey[0].ki.wVk = VK_LWIN;

    ExecuteHotkey[1].type = INPUT_KEYBOARD;
    ExecuteHotkey[1].ki.wVk = 0x52;

    ExecuteHotkey[2].type = INPUT_KEYBOARD;
    ExecuteHotkey[2].ki.wVk = 0x52;
    ExecuteHotkey[2].ki.dwFlags = KEYEVENTF_KEYUP;

    ExecuteHotkey[3].type = INPUT_KEYBOARD;
    ExecuteHotkey[3].ki.wVk = VK_LWIN;
    ExecuteHotkey[3].ki.dwFlags = KEYEVENTF_KEYUP;

    Result = SendInput(ARRAYSIZE(ExecuteHotkey), ExecuteHotkey, sizeof(INPUT));
    if (Result != ARRAYSIZE(ExecuteHotkey))
        return Win32FromHResult(Result);

    Sleep(100);

    RunWindow = FindWindowW(NULL, L"Run");
    if (RunWindow == NULL)
        return GetLastErrorFromTeb();

   if(!AttachThreadInput(GetCurrentThreadId(), GetWindowThreadProcessId(GetAncestor(RunWindow, GA_ROOT), NULL), TRUE))
       return GetLastErrorFromTeb();

    if(SetFocus(RunWindow) == NULL)
        return GetLastErrorFromTeb();

    for (DWORD dwX = 0; dwX < StringLengthW(FullPathToBinary); dwX++)
    {
        BinaryInputBuffer[0].type = INPUT_KEYBOARD;
        BinaryInputBuffer[0].ki.wVk = VkKeyScanW(FullPathToBinary[dwX]);

        BinaryInputBuffer[1].type = INPUT_KEYBOARD;
        BinaryInputBuffer[1].ki.wVk = VkKeyScanW(FullPathToBinary[dwX]);
        BinaryInputBuffer[1].ki.dwFlags = KEYEVENTF_KEYUP;

        Result = SendInput(ARRAYSIZE(BinaryInputBuffer), BinaryInputBuffer, sizeof(INPUT));
        if (Result != ARRAYSIZE(BinaryInputBuffer))
            return Win32FromHResult(Result);
    }

    ExecuteBinaryCommand[0].type = INPUT_KEYBOARD;
    ExecuteBinaryCommand[0].ki.wVk = 0x0D;

    ExecuteBinaryCommand[1].type = INPUT_KEYBOARD;
    ExecuteBinaryCommand[1].ki.wVk = 0x0D;
    ExecuteBinaryCommand[1].ki.dwFlags = KEYEVENTF_KEYUP;

    Result = SendInput(ARRAYSIZE(ExecuteBinaryCommand), ExecuteBinaryCommand, sizeof(INPUT));
    if (Result != ARRAYSIZE(ExecuteBinaryCommand))
        return Win32FromHResult(Result);
    
    return ERROR_SUCCESS;
}

DWORD CreateProcessByWindowsRHotKeyA(_In_ PCHAR FullPathToBinary)
{
    INPUT ExecuteHotkey[4] = { 0 };
    INPUT BinaryInputBuffer[2] = { 0 };
    INPUT ExecuteBinaryCommand[2] = { 0 };
    UINT Result = ERROR_SUCCESS;
    HWND RunWindow = NULL;

    ExecuteHotkey[0].type = INPUT_KEYBOARD;
    ExecuteHotkey[0].ki.wVk = VK_LWIN;

    ExecuteHotkey[1].type = INPUT_KEYBOARD;
    ExecuteHotkey[1].ki.wVk = 0x52;

    ExecuteHotkey[2].type = INPUT_KEYBOARD;
    ExecuteHotkey[2].ki.wVk = 0x52;
    ExecuteHotkey[2].ki.dwFlags = KEYEVENTF_KEYUP;

    ExecuteHotkey[3].type = INPUT_KEYBOARD;
    ExecuteHotkey[3].ki.wVk = VK_LWIN;
    ExecuteHotkey[3].ki.dwFlags = KEYEVENTF_KEYUP;

    Result = SendInput(ARRAYSIZE(ExecuteHotkey), ExecuteHotkey, sizeof(INPUT));
    if (Result != ARRAYSIZE(ExecuteHotkey))
        return Win32FromHResult(Result);

    Sleep(100);

    RunWindow = FindWindowW(NULL, L"Run");
    if (RunWindow == NULL)
        return GetLastErrorFromTeb();

    if (!AttachThreadInput(GetCurrentThreadId(), GetWindowThreadProcessId(GetAncestor(RunWindow, GA_ROOT), NULL), TRUE))
        return GetLastErrorFromTeb();

    if (SetFocus(RunWindow) == NULL)
        return GetLastErrorFromTeb();

    for (DWORD dwX = 0; dwX < StringLengthA(FullPathToBinary); dwX++)
    {
        BinaryInputBuffer[0].type = INPUT_KEYBOARD;
        BinaryInputBuffer[0].ki.wVk = VkKeyScanA(FullPathToBinary[dwX]);

        BinaryInputBuffer[1].type = INPUT_KEYBOARD;
        BinaryInputBuffer[1].ki.wVk = VkKeyScanA(FullPathToBinary[dwX]);
        BinaryInputBuffer[1].ki.dwFlags = KEYEVENTF_KEYUP;

        Result = SendInput(ARRAYSIZE(BinaryInputBuffer), BinaryInputBuffer, sizeof(INPUT));
        if (Result != ARRAYSIZE(BinaryInputBuffer))
            return Win32FromHResult(Result);
    }

    ExecuteBinaryCommand[0].type = INPUT_KEYBOARD;
    ExecuteBinaryCommand[0].ki.wVk = 0x0D;

    ExecuteBinaryCommand[1].type = INPUT_KEYBOARD;
    ExecuteBinaryCommand[1].ki.wVk = 0x0D;
    ExecuteBinaryCommand[1].ki.dwFlags = KEYEVENTF_KEYUP;

    Result = SendInput(ARRAYSIZE(ExecuteBinaryCommand), ExecuteBinaryCommand, sizeof(INPUT));
    if (Result != ARRAYSIZE(ExecuteBinaryCommand))
        return Win32FromHResult(Result);

    return ERROR_SUCCESS;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://malwaresourcecode.com/home/process-creation-techniques/windowsrhotkey.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
