Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


this is no cleaned up version... as it's the code I've used and tested with :P
It's part of my local __ProcessX.au3 I use for different kind of things...

Replace "<xXx>" with "s€x" and that "€" is an "E"

;~ Func _WinAPI_GetCommandLineFromPID($iPID)
;~ If $iDELETE = replace CommandLine with "*" so no one can read it again (ProgramPath isn't replaced)
;~ If $iDELETE > 1 = even replace the ProgramPath
Func _ProcessGetCommandLine($iPID = @AutoItPID, $iDELETE = 0)
   Local $dwDesiredAccess = 0x0410; 0x0410 = PROCESS_VM_READ (0x0010) | PROCESS_QUERY_INFORMATION (0x0400)         0x0438 = && PROCESS_VM_OPERATION (0x0008) | PROCESS_VM_WRITE (0x0020)
   If $iDELETE Then
      $iDELETE = Int($iDELETE + 0);
      $dwDesiredAccess += 0x0028;
   Local $aCall = DllCall('Kernel32.dll', 'HANDLE', 'OpenProcess', _
         'DWORD', $dwDesiredAccess, _
         'BOOL', 0, _
         'DWORD', $iPID)
   If @error Or Not $aCall[0] Then
      Return SetError(1, 0, '')
   Local $hProcess = $aCall[0]
   Local $tPROCESS_BASIC_INFORMATION = DllStructCreate('dword_ptr ExitStatus;' & _
         'ptr PebBaseAddress;' & _
         'dword_ptr AffinityMask;' & _
         'dword_ptr BasePriority;' & _
         'dword_ptr UniqueProcessId;' & _
         'dword_ptr InheritedFromUniqueProcessId')
   $aCall = DllCall('ntdll.dll', 'int', 'NtQueryInformationProcess', _
         'handle', $hProcess, _
         'dword', 0, _ ; ProcessBasicInformation
         'ptr', DllStructGetPtr($tPROCESS_BASIC_INFORMATION), _
         'dword', DllStructGetSize($tPROCESS_BASIC_INFORMATION), _
         'dword*', 0)
   If @error Then
      DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
      Return SetError(2, 0, '')
   Local $tPEB = DllStructCreate('byte InheritedAddressSpace;' & _
         'byte ReadImageFileExecOptions;' & _
         'byte BeingDebugged;' & _
         'byte Spare;' & _
         'ptr Mutant;' & _
         'ptr ImageBaseAddress;' & _
         'ptr LoaderData;' & _
         'ptr ProcessParameters;' & _
         'ptr SubSystemData;' & _
         'ptr ProcessHeap;' & _
         'ptr FastPebLock;' & _
         'ptr FastPebLockRoutine;' & _
         'ptr FastPebUnlockRoutine;' & _
         'dword EnvironmentUpdateCount;' & _
         'ptr KernelCallbackTable;' & _
         'ptr EventLogSection;' & _
         'ptr EventLog;' & _
         'ptr FreeList;' & _
         'dword Tl<xXx>pansionCounter;' & _
         'ptr TlsBitmap;' & _
         'dword TlsBitmapBits[2];' & _
         'ptr ReadOnlySharedMemoryBase;' & _
         'ptr ReadOnlySharedMemoryHeap;' & _
         'ptr ReadOnlyStaticServerData;' & _
         'ptr AnsiCodePageData;' & _
         'ptr OemCodePageData;' & _
         'ptr UnicodeCaseTableData;' & _
         'dword NumberOfProcessors;' & _
         'dword NtGlobalFlag;' & _
         'ubyte Spare2[4];' & _
         'int64 CriticalSectionTimeout;' & _
         'dword HeapSegmentReserve;' & _
         'dword HeapSegmentCommit;' & _
         'dword HeapDeCommitTotalFreeThreshold;' & _
         'dword HeapDeCommitFreeBlockThreshold;' & _
         'dword NumberOfHeaps;' & _
         'dword MaximumNumberOfHeaps;' & _
         'ptr ProcessHeaps;' & _
         'ptr GdiSharedHandleTable;' & _
         'ptr ProcessStarterHelper;' & _
         'ptr GdiDCAttributeList;' & _
         'ptr LoaderLock;' & _
         'dword OSMajorVersion;' & _
         'dword OSMinorVersion;' & _
         'dword OSBuildNumber;' & _
         'dword OSPlatformId;' & _
         'dword ImageSubSystem;' & _
         'dword ImageSubSystemMajorVersion;' & _
         'dword ImageSubSystemMinorVersion;' & _
         'dword GdiHandleBuffer[34];' & _
         'dword PostProcessInitRoutine;' & _
         'dword Tl<xXx>pansionBitmap;' & _
         'byte Tl<xXx>pansionBitmapBits[128];' & _
         'dword SessionId')
   $aCall = DllCall('Kernel32.dll', 'bool', 'ReadProcessMemory', _
         'ptr', $hProcess, _
         'ptr', DllStructGetData($tPROCESS_BASIC_INFORMATION, 'PebBaseAddress'), _
         'ptr', DllStructGetPtr($tPEB), _
         'dword', DllStructGetSize($tPEB), _
         'dword*', 0)
   If @error Or Not $aCall[0] Then
      DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
      Return SetError(3, 0, '')
   Local $tPROCESS_PARAMETERS = DllStructCreate('dword AllocationSize;' & _
         'dword ActualSize;' & _
         'dword Flags;' & _
         'dword Unknown1;' & _
         'word LengthUnknown2;' & _
         'word MaxLengthUnknown2;' & _
         'ptr Unknown2;' & _
         'handle InputHandle;' & _
         'handle OutputHandle;' & _
         'handle ErrorHandle;' & _
         'word LengthCurrentDirectory;' & _
         'word MaxLengthCurrentDirectory;' & _
         'ptr CurrentDirectory;' & _
         'handle CurrentDirectoryHandle;' & _
         'word LengthSearchPaths;' & _
         'word MaxLengthSearchPaths;' & _
         'ptr SearchPaths;' & _
         'word LengthApplicationName;' & _
         'word MaxLengthApplicationName;' & _
         'ptr ApplicationName;' & _
         'word LengthCommandLine;' & _
         'word MaxLengthCommandLine;' & _
         'ptr CommandLine;' & _
         'ptr EnvironmentBlock;' & _
         'dword Unknown[9];' & _
         'word LengthUnknown3;' & _
         'word MaxLengthUnknown3;' & _
         'ptr Unknown3;' & _
         'word LengthUnknown4;' & _
         'word MaxLengthUnknown4;' & _
         'ptr Unknown4;' & _
         'word LengthUnknown5;' & _
         'word MaxLengthUnknown5;' & _
         'ptr Unknown5;')
   $aCall = DllCall('Kernel32.dll', 'bool', 'ReadProcessMemory', _
         'ptr', $hProcess, _
         'ptr', DllStructGetData($tPEB, 'ProcessParameters'), _
         'ptr', DllStructGetPtr($tPROCESS_PARAMETERS), _
         'dword', DllStructGetSize($tPROCESS_PARAMETERS), _
         'dword*', 0)
   If @error Or Not $aCall[0] Then
      DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
      Return SetError(4, 0, '')
   $aCall = DllCall('Kernel32.dll', 'bool', 'ReadProcessMemory', _
         'ptr', $hProcess, _
         'ptr', DllStructGetData($tPROCESS_PARAMETERS, 'CommandLine'), _
         'wstr', '', _
         'dword', DllStructGetData($tPROCESS_PARAMETERS, 'MaxLengthCommandLine'), _
         'dword*', 0)
   If @error Or Not $aCall[0] Then
      DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
      Return SetError(5, 0, '')
   If $iDELETE Then
      Local $tmp = '';
      Local $tmp_len = DllStructGetData($tPROCESS_PARAMETERS, 'LengthCommandLine');
      Local $tmp_slen = ($tmp_len / 2)
      Local $tmp_nlen = 0;
      Local $pos = 0;
      If $iDELETE == 1 Then
         $pos = StringInStr($aCall[3], ' ');
         If $pos <> 0 Then
            Local $pos2 = StringInStr($aCall[3], '"');
            If $pos2 == 0 Or $pos < $pos2 Then
               $tmp = StringLeft($aCall[3], $pos);
               $pos2 = StringInStr($aCall[3], '"', 0, 2);
               $pos = StringInStr($aCall[3], ' ', 0, 1, $pos2);
               If $pos <> 0 Then
                  $tmp = StringLeft($aCall[3], $pos);
                  $pos = $tmp_slen;
            $pos = $tmp_slen;
;~       $tmp &= '/TUStart /pid:532';
      For $i = $pos To $tmp_slen
         $tmp &= '*';
      _WinAPI_WriteProcessMemory($hProcess, DllStructGetData($tPROCESS_PARAMETERS, 'CommandLine'), $tmp, $tmp_len, $tmp_nlen, 'wstr');
      If $tmp_nlen <> $tmp_len Then
;~          ConsoleWrite('WriteError!' & @LF);
         DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
         Return SetError(0, 6, $aCall[3])
   DllCall('Kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProcess)
   Return $aCall[3]
EndFunc   ;==>_ProcessGetCommandLine

WhiteTiger wrote:

It's done in AutoIt and actually OpenSource... so I'll handle it out on request (and it's ugly as there's a lot of comments, unused crap and that like... As I said, not finished)

WhiteTiger, would you be so kind and share the AutoIT code block(s) that re-write the process commandline, so no one can view the original process commandline (which contains the USR/PWD) in taskmgr.

Much appreciated.

Implemented in 5.2.2 beta and released today :-)

what's wrong with my wrapper :P
It does all that... passes "port", "directory" etc^^ Well... passing the directory is a bit hacky as WinSCP has no support for that one.
And even though I'm using my wrapper and I'm kind of happy with it, a native solution within WinSCP is preferred... (and faster/better directory change on KiTTY's part)
The worst thing about my wrapper is (besides the fact I haven't completed it) that it still has to read from registry and clean it afterwards... it leaves no tracks but still shouldn't be considered "portable"

Hi, Martin,

Well i doubt somebody will start from scratch. If somebody will decide to build another version, they probably would use putty sources. Same as Mozilla, bunch of Firefox spin-offs.

Problem with passing parameters, there does not seem to be a way to pass custom PORT, keeping in mind that first step securing your server is to change SSH port, makes this method useless.

Of course, it would be the best, if we could pass host, login info, PORT and even directory.

Simba wrote:

Next step would be to rename Putty instances to "SSH client" (i believe in future there might arise new , even better alternatives).

It's still not generic enough to support any SSH client fully. It relies on registry keys format of PuTTY and its clones. but you can at least pass username, password and hostname to any SSH client that is able to accept them on command line (patterns !U, !P and !@).

Display Note "Portable Kitty version not supported".

That contradicts your suggestion above, doesn't it? Anyway, even portably KiTTY is partially supported, when you use !U@!@ pattern to pass username and hostname.

Tested and it's working perfectly.

Next step would be to rename Putty instances to "SSH client" (i believe in future there might arise new , even better alternatives).

Include dropdown - "Putty" or "Kitty"

Display Note "Portable Kitty version not supported".

And we are good to go.


Simba wrote:

Martin, my above post provides very simple solution.

Maybe you could add it for another users?

Registry key is now configurable in GUI:

I'm sending you a dev version for testing.

Martin, my above post provides very simple solution.

Maybe you could add it for another users?


Actually i found very easy way.

On <invalid hyperlink removed by admin>

The problem was that KiTTY is using a different key in the windows registry to store its settings.

For PuTTY you have:

For KiTTY it's

So in order to launch a KiTTY session straight from WinSCP(portable) you need to edit WinSCP.ini

Just browse for the line:
and replace it with:

Just make sure you are using NOT portable Kitty version.
After changing Winscp registry key, change path to Kitty.exe and it will work.

Re: Send login & password to PuTTY

martin wrote:

This request has been added to the tracker:

This has been implemented, in terms of custom command-like patterns.

and you used my wrapper? (and it worked^^ wasn't that sure about that :P)
Well... my wrapper passes the port to kitty... you could check the command line it passes.
For that: open taskmgr, set refresh rate to "high" and start KiTTY through WinSCP . You might be able to "capture" the command line that way before the wrapper deletes it.

Thanks for your response.
First time i got it working, but after it always: Network error: connection refused.

Maybe Martin could help us?

well.. Simba you might try my Putty wrapper for now... it's still not finished (and I'm not really developing it further as it works for me) but should work...

You'll have to setup WinSCP the way I require it though...
  • Options->Preferences...->Environment->Window->Show full path (checked)
  • extract PuTTY-Wrapper where your KiTTY.exe is
  • setup WinSCP to use PuTTY-Wrapper instead of PuTTY/KiTTY
    Options->Preferences...->Integration/Applications->PuTTY path

also, it deletes the registry entries for PuTTY / all SimonTatham products... that means your PuTTY settings if you're not using KiTTY in a portable way.

so use it only with KiTTY or portable PuTTY (portable putty not tested.. as I pass KiTTY specific params) and don't use the registry to store PuTTY/KiTTY settings.

It's done in AutoIt and actually OpenSource... so I'll handle it out on request (and it's ugly as there's a lot of comments, unused crap and that like... As I said, not finished)

Hello Martin,

Please, it is time to make a move to Kitty. Putty is outdated.

I have tried creating custom command withing winscp to call kitty, but i cannot find a way to pass the port, so i always get Network connection refused.

As discussed in this post:

Otherwise login info passed via parameters seems to work fine.


Support for putty should be dropped. It's dead.

Please change it to kitty or provide us way to use kitty.

Thanks, Martin.


I would also like to add my name to those who want the password sent to Putty.

well... my wrapper will be still of some use.. it gives KiTTY all informations it needs by command line, but it censors the command line once KiTTY is fully running (replaces the entire command line with "*", so using taskmgr will show something like "KiTTY.exe **************************************")
As we are talking about portable versions anyway, such security additions might be helpful. (not that I'm using my portable version outside my Computer/Home)

P.S. the code to "delete" the command line is actually based on code to retrieve the command line of other processes, but it does not only read it as it also overwrites it.

Re: KiTTY in place of PuTTY

well... to be fair, I've wrote a wrapper application that starts KiTTY (and even sends the current remote path to it)
I've wrote it as I've posted my first post... actually I wanted to "upgrade" WinSCP but it's code is a mess xD And I'm only using real C/C++ so no Borland crap (which is the main reason I'm not able to do it directly for WinSCP, besides the code of course xD)

I can give you the wrapper... I wanted to post it anyway but it's not user friendly at all :P Works for me but no one else xD

KiTTY in place of PuTTY

I agree with scottyman2k.
Pmimarly I use Kitty.
I use putty only for the fact that winscp does not allow to pass parameters to an external application. I noticed that winscp passes the following parameters:
-pw password -load "WinSCP temporary session"

but nothing else.
For example it doesn't pass the userID.
If userID could be passed it would be enough to throw kitty.
For example:
-l userID -pass password -load "WinSCP temporary session"

So it's great if winscp could start other external applications over putty.

KiTTY in place of PuTTY

Hi guys
I'd rather use KiTTY than PuTTY, but want to manage all the connections from inside WinSCP

I also only use KiTTY and WinSCP in portable mode.
Most of the time I just start KiTTY first and then WinSCP using Shift+F3, but it would be cool if it would work the other way around too.

KiTTY integration

I want to support the idea of integration of a portable KiTTY.


martin wrote:

Not all session options can be passed via command-line.

...can they be passed with ini files? Do those "portable" versions use ini files?

WhiteTiger wrote:

Why using the registry anyway?

Not all session options can be passed via command-line.

Just change the way PuTTY integration works.
The current Integration isn't compatible with KiTTY in portable mode just because all informations are stored to the registry. (or any other portable PuTTY, except all who uses the registry as a fall back)
Just allow patterns for external applications so we can use something like this:
putty -pw "!P" !U@!@

kitty -pw "!P" -cmd "cd !/" !U@!@
kitty -pass "!P" -cmd "cd !/" !U@!@
(but i don't like the pattern style... what ever :D)
Why using the registry anyway?

Of course, don't get the session informations from stored session files^^

It is possible. I'll see if more people ask for it.

The username is correctly sent if you save it in the options of the server you want to connect to.

If you have a server stored without access data, WinSCP asks for username and password and, once connected, if you open a PuTTY session, it (PuTTY) will ask for the username.

Is it possible to send username and password to the PuTTY session without storing them in the server options?

Username be sent also, if you have entered it already on login dialog.

Send login & password to PuTTY

I think it could be very useful to login in a PuTTY session without typing the username in the PuTTY login window.

The password is already sent through the provided WinSCP option.