Check the current version in a BAT?

Advertisement

IronPhoenix
Joined:
Posts:
5
Location:
USA

Check the current version in a BAT?

So far, the only way I've found to get the WinSCP version number in a batch file is to open a connection and close it, then look at the log. Like this...
set SCPMAJ_REQ=5
set SCPMIN_REQ=13
%WINSCP% %SCP_PAR%
call :check_log
for /f "usebackq tokens=6,7 delims=.() " %%a in ( `findstr /c:"WinSCP Version" %SCPLOG%` ) do (
   set SCPMAJ_VER=%%a
   set SCPMIN_VER=%%b
)
if /i %SCPMAJ_VER% EQU %SCPMAJ_REQ% if /i %SCPMIN_VER% LSS %SCPMIN_REQ% set BADVER=TRUE
if /i %SCPMAJ_VER% LSS %SCPMAJ_REQ% set BADVER=TRUE
if defined BADVER (
   echo [E] WinSCP is not the correct version.  It must be at least %SCPMAJ_REQ%.%SCPMIN_REQ%
   echo     and is actually %SCPMAJ_VER%.%SCPMIN_VER%
   call :winscp_bad
   goto :exitlogic
) else (
   if /i %DEBUG% GEQ 3 echo [D] WinSCP Version %SCPMAJ_VER%.%SCPMIN_VER%
)

Most env vars are self-explanatory. SCP_PAR (for parameters) is, in this case,
/script=[script] /log=%SCPLOG%
. The two other calls are just a quick explanation to the user of how to install (
:winscp_bad
) and looking for basic problems, like no connection, bad password, etc (
:check_log
)

I guess the question is, is there a way to get the version number from the command line without going through all this, or, if not, is there a way to get WinSCP to generate a log file without actually opening a connection? I'd like to speed this up...

Reply with quote

Advertisement

IronPhoenix
Joined:
Posts:
5
Location:
USA

Nice to know.

However, the WMIC method fails as presented. The for statement does not like parentheses in the pathname [C:\Program Files (x86)\WinSCP\WinSCP.exe] though it works if I change "Program Files (x86)" to "progra~2" - not an option because I don't know that's the case on all machines this script runs on, though it should be.... The Powershell and makecab methods are far longer than I wanted to spend in these scripts...

Copying the executable to c:\temp\ first and pointing wmic at that copy takes a second, but it's faster than opening a connection, and it works. Escaping the closing parentheses in the pathname also works: "C:\\Program Files (x86^)\\WinSCP\\WinSCP.exe" Oddly, it doesn't need to have the opening paren escaped, too...

Reply with quote

Advertisement

You can post new topics in this forum