2010-04-23 62 views

回答

8

我進行使用註冊表研討會(比較登記處功能)的試用版一些測試,發現如下:

如果安裝了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://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 
+0

在VBS或PowerShell的PS1完整的源代碼示例任何最終的解決方案? – Kiquenet 2014-01-13 11:51:10

+0

不,我沒有一小段示例代碼,整個過程太長而無法發佈。 – 2014-01-14 08:12:49

+0

很遺憾,也許使用dropbox或github。 – Kiquenet 2014-01-14 08:16:57

相關問題