Putty Agent (pageant) unable to start when file "C:\Program" exists
What steps will reproduce the problem?
- Create a file in C:\ (or whatever drive the Program Files folder is located) named Program (no extension)
- Attempt to do anything with TortoiseGit that involves the Putty Agent (pageant)
What is the expected output? What do you see instead?
It is expected that pageant is launched and the operation requiring it continues normally. Instead a message box appears that says "Could not start the Putty Agent (pageant)." and when cleared, user is prompted for credentials (if pageant wasn't run previously).
What version of TortoiseGit and Git are you using? On what operating system?
Windows 10.0.17134 (x64)
Please provide any additional information below.
This issue is believed to be caused by the fact that double-quotes do not surround the full path to pageant.exe in CAppUtils::LaunchPAgent. Since TortoiseGit is typically installed in C:\Program Files, the call to LaunchApplication, and later CreateProcess, first looks for an executable called "C:\Program", fails, and then eventually finds pageant.exe in the TortoiseGit folder in the Program Files folder. From the documentation on CreateProcess (https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa):
The lpApplicationName parameter can be NULL. In that case, the module name must be the first white space–delimited token in the lpCommandLine string. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin; otherwise, the file name is ambiguous. For example, consider the string "c:\program files\sub dir\program name". This string can be interpreted in a number of ways. The system tries to interpret the possibilities in the following order:
c:\program.exe c:\program files\sub.exe c:\program files\sub dir\program.exe c:\program files\sub dir\program name.exe
Note that there may be additional instances of this issue throughout the TortoiseGit code.