在开发.Net程序之后就是发布,发布时就会有一个稍微令人有点头疼的问题,就是.Net2.0和4.0的问题,这里我用VB6写了个类,可以用来检测.Net2.0/3.5/4.0、系统位数判断和系统是否为XP,通过检测来决定是否安装.Net版本,或者运行不同的程序。
Public Function isdotNET40() As Boolean On Error GoTo err Dim NET As Object Set NET = CreateObject("wscript.shell") Dim a As String a = NET.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Client\Version") isdotNET40 = True Exit Function err: isdotNET40 = False End Function Public Function isdotNET35() As Boolean On Error GoTo err Dim NET As Object Set NET = CreateObject("wscript.shell") Dim a As String a = NET.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\Version") isdotNET35 = True Exit Function err: isdotNET35 = False End Function Public Function isdotNET20() As Boolean On Error GoTo err Dim NET As Object Set NET = CreateObject("wscript.shell") Dim a As String a = NET.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727\Version") isdotNET20 = True Exit Function err: isdotNET20 = False End Function Public Function isXP() As Boolean On Error GoTo err Dim reg As Object Set reg = CreateObject("wscript.shell") Dim datas As String datas = reg.regread("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName") If InStr(1, datas, "XP") <> 0 Then isXP = True Else isXP = False Exit Function err: isXP = True End Function Public Function is64bit() As Boolean If Dir(Environ("Windir") & "\SysWOW64", vbDirectory) <> "" Then is64bit = True Else is64bit = False End If End Function
使用也是非常简单,比如检测到电脑中没有.Net4,但是软件需要.Net4才能运行的。
Dim SysNet As New SysNet If SysNet.isdotNET40 Then Shell App.path & "\Net40安装程序.exe" , 1 Else Shell App.path & "\主程序.exe" , 1 End If
文章评论