Command-line Options - WinSCP version in human and raw ways

Advertisement

Makc666
Joined:
Posts:
50
Location:
MSK-RU

Command-line Options - WinSCP version in human and raw ways

Martin,

I wasn't able to find this on anywhere in docs.

The only way I was able to find to get WinSCP version is to run:
winscp.com /help
This will output on the first line WinSCP version.
WinSCP, Version 5.9.3 (Build 7136)
Copyright (c) 2000-2016 Martin Prikryl

Usage:
WinSCP [/script=file] [/command cmd1...] [/parameter // param1...]
...
...

I have just met with the requirement to check WinSCP version in scripting.
For example if someone is trying to run old version which doesn't support some command or trying to run incompatibility version then, for example, stop him.

The best way to do this one is to have in Command-line Options a parameter like:
/rawversion (may be also /version).

Also we can have this one in Scripting and Task Automation - Commands.

rawversion has to display it in raw way like: 50903 or may be 7136 (assuming that build version is always increasing).
and
version has to display it in human way like: WinSCP, Version 5.9.3 (Build 7136)

The best close example for such command is in PHP.

They use PHP_VERSION_ID and I can check very easily:
if (PHP_VERSION_ID < 50100) {
   //do one thing
}else{
   //do another thing
}
or
if (PHP_VERSION_ID < 50207) {
    define('PHP_MAJOR_VERSION',   $version[0]);
    define('PHP_MINOR_VERSION',   $version[1]);
    define('PHP_RELEASE_VERSION', $version[2]);

    // and so on, ...
}

// PHP_VERSION_ID is defined as a number, where the higher the number 
// is, the newer a PHP version is used. It's defined as used in the above 
// expression:
//

$version_id = $major_version * 10000 + $minor_version * 100 + $release_version;

For example I have PHP 5.6.19
print PHP_VERSION_ID; will give me 50619

Thank you!

Reply with quote

Advertisement

Makc666
Joined:
Posts:
50
Location:
MSK-RU

Re: Command-line Options - WinSCP version in human and raw ways

martin wrote:

powershell -Command [System.Diagnostics.FileVersionInfo]::GetVersionInfo('winscp.exe').FileVersion
5.9.3.7136

See https://stackoverflow.com/q/30686/850848

I do understand this one, but in such way you have to use external utility. Also no guaranty you will have powershell.

So having such native switch will be wonderful!

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Command-line Options - WinSCP version in human and raw ways

Makc666 wrote:

I do understand this one, but in such way you have to use external utility. Also no guaranty you will have powershell.
99% of WinSCP users have PowerShell.

Anyway, if you want a pure batch file solution, use:

@echo off
echo WScript.Echo CreateObject("Scripting.FileSystemObject").GetFileVersion(WScript.Arguments(0)) > version.vbs
cscript /nologo version.vbs winscp.exe
del version.vbs

See https://stackoverflow.com/q/602802/850848#604411

Reply with quote

Makc666
Joined:
Posts:
50
Location:
MSK-RU

Martin, I understand this one.

But again (sorry) the best way is to get native output from WinSCP rather then creating any temp files or scripts.

Also you can try to get the version this way:

@ECHO OFF
if defined ProgramFiles(x86) (
   set "winscp_com=%ProgramFiles(x86)%\WinSCP\WinSCP.com"
) else (
   set "winscp_com=%ProgramFiles%\WinSCP\WinSCP.com"
)
setlocal EnableDelayedExpansion
for /f "tokens=2,3,4,* delims= " %%a in ('"%winscp_com%" /help ^| findstr /B /I /R WinSCP ^| findstr /I /R Build') do (
   echo %%b %%c %%d
)
PAUSE

But again it is not the best variant as it is very sensitive.

For example if you will replace
for /f "tokens=2,3,4,* delims= " %%a in ('"%winscp_com%" /help ^| findstr /B /I /R WinSCP ^| findstr /I /R Version') do (
with
for /f "tokens=2,3,4,* delims= " %%a in ('"%winscp_com%" /help ^| findstr /B /I /R "WinSCP, Version"') do (
it will not work.
Looks like some glitch with double quotes in "%winscp_com%" and "WinSCP, Version" together.

So, once again, best way is native output.

If you can implement this one it will be wonderful.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Sorry, but I do not think this is necessary.

WinSCP has its version stored in the native binary header, as any other Windows binary.

There are dozens standard tools and ways to retrieve that information.

Reply with quote

Advertisement

You can post new topics in this forum