You are here

WinSCP integration with PuTTY?

9 posts / 0 new
Last post
beq
Offline
Last seen: 15 years 11 months ago
Joined: 2008-12-20 12:30
WinSCP integration with PuTTY?

Does anyone know why PuTTY Portable must be started manually before WinSCP Portable can invoke it via its toolbar button? Do the standard (non-PortableApps) versions of these programs have this same limitation?

Also, I noticed that WinSCP Portable is configured to use the file "PuTTYPortableLinker.exe" as the path for the PuTTY program. Would the integration also work if I change this WinSCP setting to the direct path of the putty.exe program file (or perhaps the puttyportable.exe launcher file)?

Sorry I'm somewhat clueless...

beq
Offline
Last seen: 15 years 11 months ago
Joined: 2008-12-20 12:30
Oh, is the use of the

Oh, is the use of the puttyportablelinker.exe file necessary because the PuTTY path setting in WinSCP must be an absolute (instead of relative) path?

John T. Haller
John T. Haller's picture
Online
Last seen: 7 min 30 sec ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
As Is

You must do it as is with no changes. They both use the registry to pass information from one to the other which is why you must use the launcher and have it running first.

Sometimes, the impossible can become possible, if you're awesome!

qwertymodo
qwertymodo's picture
Offline
Last seen: 12 years 4 months ago
Joined: 2008-03-17 19:08
How about this?

So let me see if I understand this. At the point where PuTTYPortableLinker.exe sends up the error and the prompt to the user, it has already checked for the existence of PuTTYPortable and found it (from reading the linker source). So the problem is that the one key HKCU\...\Sessions\WinSCP Portable Temporary Session is a "portable" key, but it has been put into the local version of the registry,so when you launch PuTTYPortable, that session will get backup up as part of the local registry and not passed on to the portable version. So this is why PuTTYPortable must be launched first, so when that key is created, the key will go into the portable version of the registry. Ok, so how about this for an idea? At the point where PuTTYPortableLinker normally deletes that key and sends up an error, why can't we do the following:

Export just the temp session key into a .reg file.
Delete the temp session key from the registry

Simulate a launch of PuTTYPortable.exe (but only the registry edits)
-Back up the registry the same way PuTTYPortable does.
-Import PuTTYPortable/Data/settings/putty.reg into the registry
(Because we've already found PuTTYPortable, so we can access its Data)

Now we re-import the temp session key into the registry because it is in it's "portable state"

Now simulate a PuTTYPortable shutdown
Export the entire PuTTY key back into PuTTYPortable/Data/settings/putty.reg
Delete the portable PuTTY keys from the registry
Restore the registry to it's original state

Now you can launch PuTTYPortable and the temp session key will be loaded correctly, without having to have PuTTYPortable open first Smile

In effect, this would achieve the same as having PuTTYPortable open when the user clicked on the PuTTY button in WinSCP because the registry would be in the correct state.

[Update]
I think I got this working, testing and feedback would be appreciated.

;Copyright (C) 2004-2007 John T. Haller of PortableApps.com
;Edited by Ben Whitman 2009

;Website: https://portableapps.com/PuTTYPortable

;This software is OSI Certified Open Source Software.
;OSI Certified is a certification mark of the Open Source Initiative.

;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;as published by the Free Software Foundation; either version 2
;of the License, or (at your option) any later version.

;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.

;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

!define NAME "PuTTYPortableLinker"
!define FULLNAME "PuTTY Portable Linker"
!define APP "PuTTY"
!define VER "1.7.0.0"
!define WEBSITE "PortableApps.com/WinSCPPortable"

;=== Program Details
Name "${FULLNAME}"
OutFile "${NAME}.exe"
Caption "${FULLNAME} | PortableApps.com"
VIProductVersion "${VER}"
VIAddVersionKey ProductName "${FULLNAME}"
VIAddVersionKey Comments "Allows ${APP} to be run from a removable drive.  For additional details, visit ${WEBSITE}"
VIAddVersionKey CompanyName "PortableApps.com"
VIAddVersionKey LegalCopyright "John T. Haller"
VIAddVersionKey FileDescription "${FULLNAME}"
VIAddVersionKey FileVersion "${VER}"
VIAddVersionKey ProductVersion "${VER}"
VIAddVersionKey InternalName "${FULLNAME}"
VIAddVersionKey LegalTrademarks "PortableApps.com is a trademark of Rare Ideas, LLC."
VIAddVersionKey OriginalFilename "${NAME}.exe"
;VIAddVersionKey PrivateBuild ""
;VIAddVersionKey SpecialBuild ""

;=== Runtime Switches
CRCCheck On
WindowIcon Off
SilentInstall Silent
AutoCloseWindow True
RequestExecutionLevel user

;=== Include
;(Standard NSIS)
!include FileFunc.nsh
!insertmacro GetParent
!insertmacro GetParameters
!include Registry.nsh
!include ReplaceInFile.nsh
!include StrRep.nsh

;=== Program Icon
Icon "${NAME}.ico"

Var EXECSTRING
Var PORTABLEAPPSDIRECTORY
Var SETTINGSDIRECTORY
Var FAILEDTORESTOREKEY

Section "Main"
	;=== Check for EXE
	${GetParent} "$EXEDIR" $R0
	${GetParent} $R0 $R0
	${GetParent} $R0 $PORTABLEAPPSDIRECTORY
	IfFileExists `$PORTABLEAPPSDIRECTORY\PuTTYPortable\PuTTYPortable.exe` FoundProgramEXE
		MessageBox MB_OK|MB_ICONINFORMATION `Could not locate $PORTABLEAPPSDIRECTORY\PuTTYPortable\PuTTYPortable.exe.  Please ensure that PuTTY Portable and WinSCP Portable are installed within your PortableApps directory.`
		Abort
		
        

	FoundProgramEXE:
		;=== Check if running
		FindProcDLL::FindProc "PuTTYPortable.exe"
		StrCmp $R0 "1" GetPassedParameters CheckINI

        CheckINI:
                 ;=== Find the INI file, if there is one
                 IfFileExists "$PORTABLEAPPSDIRECTORY\PuTTYPortable\PuTTYPortable.ini" "" NoINI
                 
        ;ReadINI:
                 ;=== Read the parameters from the INI file
                 ReadINIStr $0 "$PORTABLEAPPSDIRECTORY\PuTTYPortable\PuTTYPortable.ini" "PuTTYPortable" "SettingsDirectory"
                 StrCpy "$SETTINGSDIRECTORY" "$PORTABLEAPPSDIRECTORY\PuTTYPortable\$0"
                 IfErrors NoINI RegistryBackup
                 
        NoINI:
                 StrCpy "$SETTINGSDIRECTORY" "$PORTABLEAPPSDIRECTORY\PuTTYPortable\Data\settings"

        RegistryBackup:
                ${registry::SaveKey} "HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\WinSCP%20Portable%20Temporary%20Session" "$SETTINGSDIRECTORY\tempsession.reg" "" $0
                ${registry::DeleteKey} "HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\WinSCP%20Portable%20Temporary%20Session" $R0
		;=== Backup the registry
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\SimonTatham-BackupByPuTTYPortable" $R0
		StrCmp $R0 "0" RestoreSettings
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\SimonTatham" $R0
		StrCmp $R0 "-1" RestoreSettings
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\SimonTatham" "HKEY_CURRENT_USER\Software\SimonTatham-BackupByPuTTYPortable" $R0
		Sleep 100
		
	RestoreSettings:
		IfFileExists "$SETTINGSDIRECTORY\putty.reg" "" SetRandomSeedPath

		;=== Get last drive letter
		ReadINIStr $0 "$SETTINGSDIRECTORY\putty.reg" "HKEY_CURRENT_USER\Software\SimonTatham\PuTTY" `"RandSeedFile"`
		StrCpy $1 $0 1 ;last drive letter
		StrCpy $2 $EXEDIR 1 ;current drive letter
		StrCmp $2 $1 RestoreTheKey
		StrCpy $3 `"PublicKeyFile"="$1:\\`
		StrCpy $4 `"PublicKeyFile"="$2:\\`
		;MessageBox MB_OK|MB_ICONINFORMATION `$3 *** $4`
		${ReplaceInFile} "$SETTINGSDIRECTORY\putty.reg" $3 $4

	RestoreTheKey:
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\putty.reg"`
			Pop $R0
			StrCmp $R0 '0' "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\tempsession.reg"`
			Pop $R0
			StrCmp $R0 '0' SetRandomSeedPath
	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\putty.reg" $R0
		Sleep 2000
		StrCmp $R0 '0' "" +4
		${registry::RestoreKey} "$SETTINGSDIRECTORY\tempsession.reg" $R0
		Sleep 2000
		StrCmp $R0 '0' SetRandomSeedPath
		StrCpy $FAILEDTORESTOREKEY "true"

	SetRandomSeedPath:
		Sleep 100
		${registry::Write} "HKEY_CURRENT_USER\Software\SimonTatham\PuTTY" "RandSeedFile" "$SETTINGSDIRECTORY\PUTTY.RND" "REG_SZ" $0
		Sleep 100
		
        ;CheckSuccessful:
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		CreateDirectory $SETTINGSDIRECTORY
		${registry::SaveKey} "HKEY_CURRENT_USER\Software\SimonTatham\PuTTY" "$SETTINGSDIRECTORY\putty.reg" "" $0
		Sleep 100
		
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKEY_CURRENT_USER\Software\SimonTatham" $R0
		Sleep 100
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\SimonTatham-BackupByPuTTYPortable" $R0
		StrCmp $R0 "-1" GetPassedParameters
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\SimonTatham-BackupByPuTTYPortable" "HKEY_CURRENT_USER\Software\SimonTatham" $R0
		Sleep 100

        StrCmp $FAILEDTORESTOREKEY "true" "" GetPassedParameters
		MessageBox MB_OK|MB_ICONINFORMATION `Please start PuTTY Portable before attempting to use PuTTY integration within WinSCP Portable.`
		Abort
	
	GetPassedParameters:
		;=== Get any passed parameters
		${GetParameters} $0
		StrCmp "'$0'" "''" "" LaunchProgramParameters

		;=== No parameters
		StrCpy $EXECSTRING `"$PORTABLEAPPSDIRECTORY\PuTTYPortable\PuTTYPortable.exe"`
		Goto StartPuTTYPortable

	LaunchProgramParameters:
		StrCpy $EXECSTRING `"$PORTABLEAPPSDIRECTORY\PuTTYPortable\PuTTYPortable.exe" $0`
		
	StartPuTTYPortable:
		Exec $EXECSTRING
SectionEnd

Quamquam omniam nescio, nec nihil scio.

qwertymodo
qwertymodo's picture
Offline
Last seen: 12 years 4 months ago
Joined: 2008-03-17 19:08
Also...

Also, it would be nice if the PuTTYPortable launcher could check for the existence of HKCU\Software\SimonTatham\Sessions\WinSCP Portable Temporary Session on shutdown and delete it before it backs up the key to putty.reg. It is a TEMPORARY session after all, so it's just annoying for it to be there the next time you launch PuTTYPortable.

Quamquam omniam nescio, nec nihil scio.

p-m
Offline
Last seen: 5 years 3 months ago
Joined: 2019-08-27 09:42
Putty integration still not working in 2019?

Hi, I know this is a quite old post and there are some solutions proposed in this and other posts, but why is it that integration is not working still?
You wrote, one should use it as is, but it is not working for me!
I have WinSCP and PuTTY installed from Portableapps.com to their respective folders and I am starting PuTTY first and then WinSCP and nevertheless get the message that I should start PuTTY first. Looked a little bit (longer) into that problem, including the scripts and the registry, but still can't find a simple solution. I am no programmer at all and the proposed changes to installers or the registry seem to be no real solution to me, when it should work out of the box. Even changing the path to PuTTY is only working for that session, because it is overwritten each time WinSCP is opened. Also the temporary registry-key for PuTTY is left there. I know, that all of this was discussed many times, but seriously, what is the solution?
Can you please help me find out why it is not working, for me at least?
Thank you in advance!

John T. Haller
John T. Haller's picture
Online
Last seen: 7 min 30 sec ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
Processes Bug

Have you tried it right after starting your computer before starting anything else? WinSCP and PuTTY work together just fine but we more recently found a processes bug in all the NSIS addons that cause them to fail and show a given process isn't running even when it is when around 300 or more processes are running in Windows. If that's the case, that would be why it is working for everyone else (including me) but not for you. This same bug causes installs and updates in the PA.c Platform's app store and updater not to run silently, requiring you to hit next in the installers. If this is the bug you're seeing, I can push out a fix with our custom code that can properly detect the processes.

Side note: It seems some other software will have issues when running this many processes that I found in my testing that it can be otherwise difficult to nail down. The monitoring software for my CyberPower UPS is unable to work properly with that many processes running, for example. No specific errors, just unable to communicate with the monitoring service.

Sometimes, the impossible can become possible, if you're awesome!

p-m
Offline
Last seen: 5 years 3 months ago
Joined: 2019-08-27 09:42
re processes bug

thank you for your answer,
I have almost 300 processes running right from the start without starting anything else.
Starting a browsersession with a few tabs and a few other progs and you have it, to test that updater-bug I would have to have a few old paf-installers, will try installing a few from the repo. But I think I had that problem that it stopped after each install in the last weeks. I have definitely problems with processes not starting randomly. I think that could be my problem...would try that fix if you don't mind.
P.S. trying apps from the repo was not a good idea... all up to date of course.
edit: It is working on my laptop, could you please push out that fix, thanks!
another edit: It is working on the pc also, if I start it with the necessary processes only, but that is not really feasible on the long run.

page2pagepro
Offline
Last seen: 1 year 5 months ago
Joined: 2012-05-24 17:01
Alternative to PuTTYPortableLinker.exe

Edit PuTTYPortableLinkerU.nsi

Insert Line after line 78 before:
FindProcDLL::FindProc "PuTTYPortable.exe"
StrCmp $R0 "1" GetPassedParameters WarnAnotherInstance

after:
FindProcDLL::FindProc "PuTTYPortable.exe"
StrCmp $R0 "0" GetPassedParameters
StrCmp $R0 "1" GetPassedParameters WarnAnotherInstance

Recompile NSIS and save PortableApps\WinSCPPortable\App\winscp\PuTTYPortableLinker.exe

Done.

Log in or register to post comments