如何检查IIS 6管理兼容性功能是否已安装?
答
我进行使用注册表研讨会(比较登记处功能)的试用版一些测试,发现如下:
如果安装了IIS 7.x中,以下注册表项包含有关安装的子组件的信息:
HKEY_LOCAL_MACHINE \ SOFTWARE \微软\ InetStp \组件
每个已安装的功能表示用DWORD 00000001的值。如果某个功能未安装,则该值缺失。
对于Web管理工具,该值名称如下:
Web Management Tools
IIS 6 Management Compatibility
IIS 6 Management Console (LegacySnapin)
IIS 6 Scripting Tools (LegacyScripts)
IIS 6 WMI Compatibility (WMICompatibility)
IIS Metabase and IIS 6 configuration compatibility (Metabase + ADSICompatibility)
IIS Management Console (ManagementConsole)
IIS Management Scripts and Tools (ManagementScriptingTools)
IIS Management Service (AdminService)
注意,这些组件的名称从Windows 7安装来了,可能会与Windows Server 2008中的略有不同,虽然注册表项应该是一样的。
一些这方面在一份报告中提到的这篇文章: Using Managed Code to Detect if IIS is Installed and ASP/ASP.NET is Registered
这些和其他子组件列表可以在这里找到: Discover Installed Components
更新:
一些核心功能从最终的代码。这是不完整的代码,但应该是足够的人谁花费的时间查找组件名称为各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://*.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
在VBS或PowerShell的PS1完整的源代码示例任何最终的解决方案? – Kiquenet 2014-01-13 11:51:10
不,我没有一小段示例代码,整个过程太长而无法发布。 – 2014-01-14 08:12:49
很遗憾,也许使用dropbox或github。 – Kiquenet 2014-01-14 08:16:57