在做iServer批处理版控制台时写了2种方法,测试环境WindowsXP/2003/Vista/7(x86)。这里给出来,供大家参考:

方法一:
这只是简单的检测,并不保证运行库完整可靠性,至于检测其他版本的运行库,可以修改find后面的字符串来实现。

@echo off
echo. && echo 测试VC++运行库...
dir %windir%\WinSxS | find /i /c "Microsoft.VC90" >nul || (
  echo 测试失败,尚未安装VC++2008
)
pause

方法二:
通过注册表搜索已注册的卸载信息来获取安装状态,相对比较准确,只是对微软更新比较敏感,需要随时更新注册信息。

@echo off
set "HKLMU=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
reg query %HKLMU%{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4} >nul 2>nul && set VC2008=Microsoft Visual C++ 2008 Redistributable X86
reg query %HKLMU%{9A25302D-30C0-39D9-BD6F-21E6EC160475} >nul 2>nul && set VC2008=Microsoft Visual C++ 2008 SP1 Redistributable X86
reg query %HKLMU%{1F1C2DFC-2D24-3E06-BCB8-725134ADF989} >nul 2>nul && set VC2008=Microsoft Visual C++ 2008 SP1 Redistributable ATL Security Update X86
reg query %HKLMU%{350AA351-21FA-3270-8B7A-835434E766AD} >nul 2>nul && set VC2008=Microsoft Visual C++ 2008 Redistributable X64
reg query %HKLMU%{8220EEFE-38CD-377E-8595-13398D740ACE} >nul 2>nul && set VC2008=Microsoft Visual C++ 2008 SP1 Redistributable X64
reg query %HKLMU%{4B6C7001-C7D6-3710-913E-5BC23FCE91E6} >nul 2>nul && set VC2008=Microsoft Visual C++ 2008 SP1 Redistributable ATL Security Update X64
reg query %HKLMU%{2B547B43-DB50-3139-9EBE-37D419E0F5FA} >nul 2>nul && set VC2008=Microsoft Visual C++ 2008 Redistributable IA64
reg query %HKLMU%{5827ECE1-AEB0-328E-B813-6FC68622C1F9} >nul 2>nul && set VC2008=Microsoft Visual C++ 2008 SP1 Redistributable IA64
reg query %HKLMU%{977AD349-C2A8-39DD-9273-285C08987C7B} >nul 2>nul && set VC2008=Microsoft Visual C++ 2008 SP1 Redistributable ATL Security Update IA64
if defined VC2008 (
  echo 已安装 %VC2008%
) else (
  echo 未安装 VC2008
)
pause

标签: dos

添加新评论