Frage

Wie würde ich den aktuellen Verzeichnispfad einer IIS-Anwendung (virtuelle Ordner) mithilfe von WMI erhalten?

War es hilfreich?

Lösung

Verwenden Sie Scriptomatic V2 Werkzeuge, um mehr Proben wie das anzuzeigen:

On Error Resume Next

Const wbemFlagReturnImmediately = &h10 Const wbemFlagForwardOnly = &h20

arrComputers = Array("*") For Each strComputer In arrComputers WScript.Echo WScript.Echo "==========================================" WScript.Echo "Computer: " & strComputer WScript.Echo "=========================================="

Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\MicrosoftIISv2") Set colItems = objWMIService.ExecQuery("SELECT * FROM IIsWebVirtualDir_IIsWebVirtualDir", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems WScript.Echo "GroupComponent: " & objItem.GroupComponent WScript.Echo "PartComponent: " & objItem.PartComponent WScript.Echo Next Next

Andere Tipps

Sicher, es ist 3 Jahre alt, aber es ist eine nette kleine Frage. Wenn die Spezifikation der Lösung .NET enthält Powershell verwenden müssen, dann wird dies den Trick. Jemand möchte einen Tag wissen:

$server = 'ServerName'
$query = "Select Path From IIsWebVirtualDirSetting WHERE Name = 'W3SVC/1/ROOT'"
Get-WmiObject -namespace "root/microsoftiisv2" -query $query -computername $server -authentication 6

Das resultierende Objekt enthält eine Eigenschaft mit dem Namen „Path“.

Hier ist eine rein .Net Option, die das gleiche Ergebnis wie Isalamon Antwort zurückkommen sollte.

Aus meiner WmiMacros

Probenverbrauch (ersetzen strComputer)

Macros.WmiMacros.QueryWmiAdvanced  (Macros.WmiMacros.ScopeItem.Creation("\\\\strComputer\\root\\MicrosoftIISv2", true,true)) "SELECT * FROM IIsWebVirtualDir_IIsWebVirtualDir"
|> Seq.map (fun e-> e.Properties.["GroupComponent"].Value, e.Properties.["PartComponent"].Value)

Weit weit detailliertere Nutzung:

let webServerSettings = 
    Macros.WmiMacros.QueryWmiAdvanced  (Macros.WmiMacros.ScopeItem.Creation("\\\\strComputer\\root\\MicrosoftIISv2", true,true)) "SELECT Name,ServerComment FROM IIsWebServerSetting" 
    |> Seq.map (fun e -> e.Properties.["Name"].Value,e.Properties.["ServerComment"].Value)
let webVirtualDirs = 
    Macros.WmiMacros.QueryWmiAdvanced  (Macros.WmiMacros.ScopeItem.Creation("\\\\strComputer\\root\\MicrosoftIISv2", true,true)) "SELECT AppRoot,Name FROM IIsWebVirtualDir"
    |> Seq.map (fun e -> e.Properties.["Name"].Value,e.Properties.["AppRoot"].Value)
let webVirtualDirSettings = 
    Macros.WmiMacros.QueryWmiAdvanced  (Macros.WmiMacros.ScopeItem.Creation("\\\\strComputer\\root\\MicrosoftIISv2", true,true)) "SELECT Name,Path,AppPoolId FROM IIsWebVirtualDirSetting"
    |> Seq.map (fun e -> e.Properties.["Name"].Value,e.Properties.["Path"].Value,e.Properties.["AppPoolId"].Value)
// webServerSettings.Dump("ss");
// webVirtualDirs.Dump("vd");
query { 
    for name,sc in webServerSettings do 
    join (vname,appRoot) in webVirtualDirs on ((name.ToString() + "/ROOT") = vname.ToString())
    join (sname,path,appPoolId) in webVirtualDirSettings on (name.ToString()+ "/ROOT" = sname.ToString() )
    select (appRoot,name,sc,path,appPoolId)
    }

detaillierter Implementierungscode:

type ScopeItem = 
    | Scope of ManagementScope
    | Creation of string*bool*bool

let private createAdvancedScope (path:string) requiresDomainSecurity requiresPacketSecurity = 
    let scope = 
        if requiresDomainSecurity then  
            let conn = ConnectionOptions(Authority=sprintf "ntlmdomain:%s" Environment.UserDomainName)
            ManagementScope(path, conn)
        else 
        ManagementScope(path, null)
    if requiresPacketSecurity then scope.Options.Authentication <- AuthenticationLevel.PacketPrivacy
    scope.Connect()
    scope

let QueryWmiAdvanced (scopeInput: ScopeItem) query = 
        let scope = 
            match scopeInput with
            | Scope s -> s
            | Creation (path, requiresDomainSecurity, requiresPacketSecurity) -> createAdvancedScope path requiresDomainSecurity requiresPacketSecurity
            // createAdvancedScope path requiresDomainSecurity requiresPacketSecurity
        let query = new ObjectQuery(query)
        use searcher = new ManagementObjectSearcher(scope, query)
        use results = searcher.Get()
        results |> Seq.cast<ManagementObject>  |> Array.ofSeq
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top