C#如何用代碼檢測(cè)IIS是否已經(jīng)啟用“IIS6元數(shù)據(jù)庫(kù)兼容性”
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
使用 VB.NET、C# 或 VBScript,如何檢查 IIS 6 管理兼容性功能及其子功能是否已安裝在運(yùn)行 IIS 7.x 的計(jì)算機(jī)上? 解決方案 我使用 Registry Workshop 的試用版(比較注冊(cè)表功能)進(jìn)行了一些測(cè)試,結(jié)果如下: 如果安裝了 IIS 7.x,以下注冊(cè)表項(xiàng)包含有關(guān)已安裝子組件的信息: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Components 每個(gè)已安裝的功能都用 DWORD 0x00000001 的值表示。如果未安裝功能,則缺少該值。 對(duì)于 Web 管理工具,值名稱(chēng)如下: Web Management Tools IIS 6 Management Compatibility IIS 6 Management Console (LegacySnapin) //IIS6 管理控制臺(tái) IIS 6 Scripting Tools (LegacyScripts) //IIS6 腳本工具 IIS 6 WMI Compatibility (WMICompatibility) //IIS6 WMI 兼容性 IIS Metabase and IIS 6 configuration
compatibility (Metabase) //IIS6 元數(shù)據(jù)庫(kù)兼容性
IIS Management Console (ManagementConsole) //IIS 管理控制臺(tái) IIS Management Scripts and Tools
(ManagementScriptingTools) //IIS 管理工具和腳本 IIS Management Service (AdminService) //IIS
管理服務(wù)
請(qǐng)注意,這些組件名稱(chēng)來(lái)自 Windows 7 安裝,可能與 Windows Server 2008 的組件名稱(chēng)略有不同,但注冊(cè)表項(xiàng)應(yīng)該相同。 本文的注釋中提到了其中的一些內(nèi)容: 使用托管代碼檢測(cè)是否已安裝 IIS 并已注冊(cè) ASP/ASP.NET 可以在此處找到這些和其他子組件的列表: 發(fā)現(xiàn)已安裝的組件 更新: 最終代碼中的一些核心功能。這不是完整的代碼,但對(duì)于花時(shí)間查找各種 IIS 版本的組件名稱(chēng)的人來(lái)說(shuō)應(yīng)該足夠了: 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 編輯過(guò) |
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)... |