Win32-OpenSSH icon indicating copy to clipboard operation
Win32-OpenSSH copied to clipboard

Can't hide ssh.exe when started by TortoiseSVN

Open RussSchultz opened this issue 4 years ago • 2 comments
trafficstars

I've been trying to find a way to hide the ssh.exe run by TortoiseSVN when doing its operations.

I even went to the point of writing a tiny exe to wrap and call ssh.exe, but an ssh.exe window still opens even though my exe is a 'windows' app and i'm using STARTUPINFO to hide the window, or even move it off the screen, or even create with no window.

Is this something that can be fixed in SSH.EXE?

Why not use TortoisePlink? Because you have to use Putty with TortoisePlink and putty is always a pain to set up (particularly when new hires show up). I'd rather just deal with the popup--but I'd rather deal with neither.

RussSchultz avatar Aug 03 '21 02:08 RussSchultz

Here's my wrapper EXE source code, compiled with 2019. Pardon any warnings

`

// ssh_wrapper.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#pragma comment(linker, "/subsystem:\"windows\" /entry:\"wmainCRTStartup\"") 

#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <strsafe.h>

void _tmain(int argc, TCHAR* argv[])
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    std::wstring cmdline = _T("C:\\windows\\system32\\OpenSSH\\ssh.exe");

    for (int i = 1; i < argc; i++)
    {
        cmdline += _T(" ");
        cmdline += argv[i];
    }

    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    si.dwFlags     = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES | STARTF_USEPOSITION |STARTF_USESIZE;
    si.dwXSize = 0;
    si.dwYSize = 0;
    si.dwX = -1000;
    si.dwY = -1000;
    si.wShowWindow = SW_HIDE;
    si.hStdInput   = GetStdHandle(STD_INPUT_HANDLE);
    si.hStdOutput  = GetStdHandle(STD_OUTPUT_HANDLE);
    si.hStdError   = GetStdHandle(STD_ERROR_HANDLE);
    si.dwFlags    |= STARTF_USESTDHANDLES;

    ZeroMemory(&pi, sizeof(pi));

    // Start the child process. 
    if (!CreateProcess(NULL,    // No module name (use command line)
        (LPWSTR)cmdline.c_str(),// Command line
        NULL,                   // Process handle not inheritable
        NULL,                   // Thread handle not inheritable
        TRUE,                   // Set handle inheritance to TRUE
        CREATE_NEW_CONSOLE,
        NULL,                   // Use parent's environment block
        NULL,                   // Use parent's starting directory 
        &si,                    // Pointer to STARTUPINFO structure
        &pi)                    // Pointer to PROCESS_INFORMATION structure
        )
    {
        printf("CreateProcess failed (%d).\n", GetLastError());
        return;
    }
    // Wait until child process exits.
    WaitForSingleObject(pi.hProcess, INFINITE);

    // Close process and thread handles. 
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
    return;
}

`

RussSchultz avatar Aug 03 '21 13:08 RussSchultz

See this March 2018 thread on the TortoiseSVN mailing list: https://groups.google.com/g/tortoisesvn/c/ZmO6bU25-lo/m/-zrfgIdiAAAJ

Stefan's answer there summarized: TortoiseSVN opens that window in case ssh.exe does require user input on the terminal (such as the dialogue for accepting a new host public key). PuTTY's plink.exe similarly may require user input on the terminal, i.e. has the same problem. This is why there is TortoisePlink, Stefan's rewrite of plink, which handles any such interaction via the GUI rather than via the console. Ssh.exe is a command-line tool. It wasn't designed to be quietly called by a GUI application behind the scenes, as it can't interact with the user without a terminal.

I suspect the real solution to your problem may be to use SVN rather than TortoiseSVN, i.e. to stay in the terminal rather than try to mix terminal and GUI tools. Or to write a version of ssh.exe that pops up a GUI window whenever it needs user interaction, i.e. an OpenSSH-based equivalent of TortoisePlink.

mgkuhn avatar Aug 12 '21 18:08 mgkuhn