通过WMI使用VBS检测.Net Framework 3.5或更高版本 [英] Detect .Net Framework 3.5 or higher using VBS through WMI

查看:107
本文介绍了通过WMI使用VBS检测.Net Framework 3.5或更高版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个脚本,该脚本检测通过注册表安装的已安装.Net Framework。该状况应专门检测到3.5或更高版本,然后继续该过程。但是,似乎无法使用注册表。每次安装一个新版本时,您都必须搜索和输入注册表或修改脚本以使其起作用。

I have created a script which detects installed .Net Framework installed through registry. The condition should specifically detect 3.5 or higher version and continue the process. However, using the registry it seems not possible. Every time there is a new version installed, you have to search and input the registry or modify the script just to make it works.

然后我在Google上进行了搜索可以通过WMI完成,这似乎可行。即使已经安装了高于3.5的新安装的.net框架,我也已将脚本修改为灵活的,它将自动检测到安装的3.5或更高版本。不幸的是,如果脚本检测到较低版本或未安装.net框架,则其中一种情况不起作用,脚本应退出并且不会继续执行该过程。

Then I searched it up on google that it can be done through WMI and this seems gonna work. I have modified the script to be flexible even though there are new installed .net framework higher than 3.5 it will automatically detect 3.5 or higher version installed. Unfortunately, one condition is not working if the scripts detect that there is lower version or no installed .net framework installed, the script should quit and will not continue the process.

WriteLog "Checking if there is .Net Framework 4.5, .Net Framework 4.0 and .Net Framework 3.5 installed on the machine.."
If ((RegValueExists("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{8E34682C-8118-31F1-BC4C-98CD9675E1C2}\")) AND (RegValueExists("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{F5B09CFD-F0B2-36AF-8DF4-1DF6B63FC7B4}\"))) Then

    WriteLog"Framework 4 detected on system. "
    WriteLog "Proceeding with installation..."

ElseIf FrameworkCheck("3.5") Then

    'Proceed with installation

End If




功能框架检查

Function FrameworkCheck



Function FrameworkCheck(strVersion)

Dim strComputer, objWMIService, colItems, strVar, objItem

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select Name, Version from Win32_Product Where Name Like 'Microsoft .NET Framework%'")

For Each objItem in colItems

    If objItem.Version => strVersion Then

        WriteLog "Detected Framework Version: " & objItem.Version & " - " & objItem.Name
        WriteLog "Proceeding with installation..."

    ElseIf objItem.Version <> 0 Then

        WriteLog "NOK-Framework 3.5 or later not detected on system. Installation not possible. Please check basic client installation"
        WScript.Quit(-1)            

    End If

Next

End Function


推荐答案

您可能想使用一个函数来获取最大框架版本,然后更改调用代码以查看其是否返回> =最低所需版本(我尚未检查语法)对此):

You may instead want to have a function to get the max framework version, then change the calling code to see if it returns >= the minimum required version (I have not checked the syntax on this):

Function MaxFrameworkVersionCheck()

Dim strComputer, objWMIService, colItems, strVar, objItem, maxVersion

maxVersion = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select Name, Version from Win32_Product Where Name Like 'Microsoft .NET Framework%'")

For Each objItem in colItems
    WriteLog "Detected Framework Version: " & objItem.Version & " - " & objItem.Name
    If objItem.Version > maxVersion Then

        maxVersion = objItem.Version

    End If

Next

MaxFrameworkVersionCheck = maxVersion

End Function

这篇关于通过WMI使用VBS检测.Net Framework 3.5或更高版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆