以下をメモ帳にコピペして、拡張子vbsで保存してください。
スクリプトギャラリーには、その他のサンプルがたくさん!!
---ここから
strComputer = "."
Set objDic_Name = CreateObject("Scripting.Dictionary")Set objDic_Parent = CreateObject("Scripting.Dictionary")Set objDic_Tree = CreateObject("Scripting.Dictionary")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colFeatureList = objWMIService.ExecQuery("SELECT * FROM Win32_ServerFeature")
For Each n in colFeatureList objDic_Name.Add n.ID, n.Name objDic_Parent.Add n.ID, n.ParentID 'Wscript.Echo n.ID & ":" & n.Name & ":" & n.ParentIDNext
strFunctions = ""
For Each ID in objDic_Name.Keys
ParentID = objDic_Parent(ID) Name = objDic_Name(ID)
If ParentID = "0" then objDic_Tree.Add ID , "+" Else If objDic_Tree.Exists(ParentID) Then objDic_Tree.Add ID, objDic_Tree(ParentID) & "+" End If End IF
strName_Me = objDic_Tree(ID) & Name
If ParentID = 0 Then strName_Parent = "N/A" Else strName_Parent = objDic_Tree(ParentID) & objDic_Name(ParentID) End If
If InStr(strFunctions , strName_Parent) Then strFunctions = Replace(strFunctions, strName_Parent, strName_Parent & "," & strName_Me) Else strFunctions = strFunctions & "," & strName_Me End If
Next
arrName = Split(strFunctions ,",")
For Each n in arrName Wscript.Echo nNext