LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

C#如何用代码检测IIS是否已经启用“IIS6元数据库兼容性”

admin
2021年6月15日 9:26 本文热度 3393

使用 VB.NET、C# 或 VBScript,如何检查 IIS 6 管理兼容性功能及其子功能是否已安装在运行 IIS 7.x 的计算机上?

解决方案

我使用 Registry Workshop 的试用版(比较注册表功能)进行了一些测试,结果如下:

如果安装了 IIS 7.x,以下注册表项包含有关已安装子组件的信息:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Components

每个已安装的功能都用 DWORD 0x00000001 的值表示。如果未安装功能,则缺少该值。

对于 Web 管理工具,值名称如下:

Web Management Tools

IIS 6 Management Compatibility

IIS 6 Management Console (LegacySnapin)                       //IIS6 管理控制台

IIS 6 Scripting Tools (LegacyScripts)                         //IIS6 脚本工具

IIS 6 WMI Compatibility (WMICompatibility)                    //IIS6 WMI 兼容性

IIS Metabase and IIS 6 configuration compatibility (Metabase) //IIS6 元数据库兼容性

 

IIS Management Console (ManagementConsole)                            //IIS 管理控制台

IIS Management Scripts and Tools (ManagementScriptingTools)           //IIS 管理工具和脚本

IIS Management Service (AdminService)                                 //IIS 管理服务


请注意,这些组件名称来自 Windows 7 安装,可能与 Windows Server 2008 的组件名称略有不同,但注册表项应该相同。

本文的注释中提到了其中的一些内容: 使用托管代码检测是否已安装 IIS 并已注册 ASP/ASP.NET

可以在此处找到这些和其他子组件的列表: 发现已安装的组件

更新:

最终代码中的一些核心功能。这不是完整的代码,但对于花时间查找各种 IIS 版本的组件名称的人来说应该足够了:

Function IsIISComponentInstalled(ByVal ComponentName)
Dim result
Dim intProcessorArchitecture
intProcessorArchitecture = GetProcessorArchitectureIIS()
If intProcessorArchitecture = 64 Then
'64-bit system
On Error Resume Next
Err.Clear
result = RegReadDWORD(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\InetStp\Components", ComponentName, 64)
If Err.Number <> 0 Then
Err.Clear
IsIISComponentInstalled = False
Else
If result = 1 Then
IsIISComponentInstalled = True
Else
IsIISComponentInstalled = False
End If
End If
Else
'32-bit system
If RegReadStringIIS("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Components\" & ComponentName) = "1" Then
IsIISComponentInstalled = True
Else
IsIISComponentInstalled = False
End If
End If
End Function

Function GetProcessorArchitectureIIS()
Dim strProcessorArchitecture
Dim oShell
Set oShell = CreateObject("Wscript.Shell")
strProcessorArchitecture = oShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
If strProcessorArchitecture = "x86" Then
GetProcessorArchitectureIIS = 32
Else
If strProcessorArchitecture = "AMD64" Then
GetProcessorArchitectureIIS = 64
Else
GetProcessorArchitectureIIS = 0
End If
End If
End Function

Function RegReadStringIIS(sRegValue)
Set oShell = CreateObject("WScript.Shell")
On Error Resume Next
RegReadStringIIS = oShell.RegRead(sRegValue)
If Err Then
RegReadStringIIS = ""
Err.clear
End If
If VarType(RegReadStringIIS) < vbArray Then
If RegReadStringIIS = sRegValue Then
RegReadStringIIS = ""
End If
End If
On Error Goto 0
End Function
 
'-------------------------------------------------------------------
' Reads a REG_SZ value from the local computer's registry using WMI.
' Parameters:
' RootKey - The registry hive (see http://msdn.microsoft.com/en-us/library/aa390788(VS.85).aspx for a list of possible values).
' Key - The key that contains the desired value.
' Value - The value that you want to get.
' RegType - The registry bitness: 32 or 64.
'
'References:
' http://stackoverflow.com/questions/1229760/how-do-i-read-64-bit-registry-values-from-vbscript-running-as-a-an-msi-post-inst
' http://msdn.microsoft.com/en-us/library/aa393067(VS.85).aspx
' http://msdn.microsoft.com/en-us/library/windows/desktop/aa390445(v=VS.85).aspx
'
Function RegReadDWORD(RootKey, Key, Value, RegType)
Dim oCtx, oLocator, oReg, oInParams, oOutParams
Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
oCtx.Add "__ProviderArchitecture", RegType
Set oLocator = CreateObject("Wbemscripting.SWbemLocator")
Set oReg = oLocator.ConnectServer("", "root\default", "", "", , , , oCtx).Get("StdRegProv")
Set oInParams = oReg.Methods_("GetDWORDValue").InParameters
oInParams.hDefKey = RootKey
oInParams.sSubKeyName = Key
oInParams.sValueName = Value
Set oOutParams = oReg.ExecMethod_("GetDWORDValue", oInParams, , oCtx)
RegReadDWORD = oOutParams.uValue
End Function

 


该文章在 2021/6/15 9:31:17 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved