Answers:
sigcheck -a -q %windir%\system32\mstsc.exe
-如果需要添加MD5,SHA1,PESHA1,SHA256
sigcheck -a -q -h %windir%\system32\mstsc.exe
-测试版本,并运行命令:
sigcheck -a -q %windir%\system32\mstsc.exe | find "Prod version:" | find "6.0.6001.18564" && Echo "RDP 6.0.6001.18564"
Windows XP Service Pack 2支持工具或
Windows Server 2003 Service Pack 2 32位支持工具
filever /V %windir%\system32\mstsc.exe
变体2:
filever /V %windir%\system32\mstsc.exe | findstr "FileDesc Version"
filever /V %windir%\system32\mstsc.exe | findstr "ProductVersion" | find "6.0.6001.18564" && Echo "RDP 6.0.6001.18564"
filever /V %windir%\system32\mstsc.exe | findstr "ProductVersion" | find "6.0.6001.18564" || Echo "NOT 6.0.6001.18564"
wmic datafile where "name='C:\\<windows dir>\\system32\\mstsc.exe'" get version
文件描述:
powershell (gi %windir%\system32\mstsc.exe).versioninfo.FileDescription
版:
powershell (gi %windir%\system32\mstsc.exe).versioninfo ^|Ft -Au
脚本版本比较:
$VerArr = [version]"8.2.6001.18564", [version]"6.0.6001.18564"
[version]$v1="8.2.6001.18564"
[version]$v2="6.0.6001.18564"
[version]$v3=(gi $env:windir\system32\mstsc.exe).versioninfo.ProductVersion
$v3
$v3 -ge $v1
$v3 -ge $v2
If ($VerArr -contains $v3)
{
echo 'Run version list block'
}
输出:
Major Minor Build Revision
----- ----- ----- --------
6 0 6001 18564
False
True
Run version list block
cscript //Nologo vers01.vbs
vers01.vbs:
WScript.Echo CreateObject("Scripting.FileSystemObject").GetFileVersion(CreateObject("WScript.Shell").Environment("Process")("WINDIR") & "\system32\mstsc.exe")
cscript //Nologo vers01.js
vers01.js:
WScript.Echo(new ActiveXObject("Scripting.FileSystemObject").GetFileVersion(new ActiveXObject("WScript.Shell").ExpandEnvironmentStrings("%windir%")+"//system32//mstsc.exe"));
pefile modyle安装:解压缩,运行 python setup.py install
import pefile, os
pe = pefile.PE(os.path.join(os.environ['WINDIR'],'system32\mstsc.exe'))
ProductVersion = pe.FileInfo[0].StringTable[0].entries['ProductVersion']
print ProductVersion
php vers01.php
php.ini(%windir%
):
extension_dir = C:\php\ext\
[COM_DOT_NET]
extension=php_com_dotnet.dll
vers01.php:
<?php
$path = getenv('SystemRoot').'\\system32\\mstsc.exe';
$fso = new COM("Scripting.FileSystemObject");
echo $fso->GetFileVersion($path);
?>
安装Win32 :: File :: VersionInfo模块: cpan Win32::File::VersionInfo
use Win32::File::VersionInfo;
$fn=$ENV{windir} . "\\system32\\mstsc.exe";
$fl=GetFileVersionInfo($fn);
if($fl){print $fl->{FileVersion},"\n";}
@STTR的答案很好,只是它没有提供一种方法来批量比较版本,因为这可能也是个问题,例如,在将10.0.10049与6.3.9600比较时。
如果用plain进行处理IF %ver1% GTR %ver%
,将会得到字符串比较,并且6.3.9600
看起来比更大10.0.10049
。
我知道您已经告诉您这不是“为我编写”,但是这种情况下,编写代码比用普通英语解释要容易得多(并且代码不言自明)。
从/superuser//a/363308/131936中,我找到了如何使用来读取文件版本wmic
,该文件是随裸机附带的。
(
SETLOCAL
ECHO Usage: %0 <file> [<MinVer>]
ECHO If second argument provided, returns error level 1 if version of file is less than required
ECHO Otherwise, sets %%filever%% variable to file version No.
rem /superuser//a/363308/131936
SET "fileNameForWMIC=%~1"
)
SET fileNameForWMIC=%fileNameForWMIC:\=\\%
FOR /F "usebackq skip=1" %%I IN (`wmic datafile where Name^="%fileNameForWMIC%" get Version`) DO (
SET filever=%%~I
GOTO :break
)
:break
(
IF "%~2"=="" (
ENDLOCAL
SET "filever=%filever%"
EXIT /B
)
FOR /F "delims=. tokens=1,2,3,4" %%I IN ("%filever%") DO (
SET fileverSub1=%%I
SET fileverSub2=%%J
SET fileverSub3=%%K
SET fileverSub4=%%L
)
FOR /F "delims=. tokens=1,2,3,4" %%I IN ("%~2") DO (
SET chkSub1=%%I
SET chkSub2=%%J
SET chkSub3=%%K
SET chkSub4=%%L
)
IF NOT DEFINED fileverSub2 SET fileverSub2=0
IF NOT DEFINED fileverSub3 SET fileverSub3=0
IF NOT DEFINED fileverSub4 SET fileverSub4=0
IF NOT DEFINED chkSub2 SET chkSub2=0
IF NOT DEFINED chkSub3 SET chkSub3=0
IF NOT DEFINED chkSub4 SET chkSub4=0
)
(
ENDLOCAL
IF %chkSub1% GTR %fileverSub1% EXIT /B 1
IF %chkSub2% GTR %fileverSub2% EXIT /B 1
IF %chkSub3% GTR %fileverSub3% EXIT /B 1
IF %chkSub4% GTR %fileverSub4% EXIT /B 1
EXIT /B 0
)
首先,读取一个文件版本:
CALL compareVersion.cmd file1.exe
SET file1ver=%filever%
然后将其与其他文件进行比较:
CALL compareVersion.cmd file2.exe %file1ver%
IF ERRORLEVEL 1 (
… do this when file2 is lower version than file1…
) ELSE (
… do this when file2 is higher or equal to version of file1…
)
另外,如果需要,您可以对版本进行硬编码:
CALL compareVersion.cmd file2.exe 1.2.3.4 || (ECHO Min required version 1.2.3.4 not provided & EXIT /B)
PS这是我的脚本,用于读取/检查Windows版本,该脚本基于类似原理构建。