如何使用WMI獲取IIS應用程序(虛擬文件夾)的實際目錄路徑?如何通過WMI獲取IIS應用程序信息
回答
使用Scriptomatic V2工具來查看更多的樣本這樣:
On Error Resume NextConst 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
當然,這是3歲,但它是一個不錯的小問題。如果解決方案必須使用.NET的規範包括PowerShell,那麼這將會起到訣竅的作用。有人可能會想知道有一天:
$server = 'ServerName'
$query = "Select Path From IIsWebVirtualDirSetting WHERE Name = 'W3SVC/1/ROOT'"
Get-WmiObject -namespace "root/microsoftiisv2" -query $query -computername $server -authentication 6
生成的對象將包含一個名爲「路徑」一個屬性。
下面是一個純粹的.Net選項,應該返回與Isalamon的答案相同的結果。
使用範例(更換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)
遠遠更詳細的用法:
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)
}
詳細的執行代碼:
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
我很驚訝沒有.net解決方案,直到現在。野生。 – Maslow 2014-09-30 13:11:56
- 1. IIS + WMI:無法獲取所有WMI信息
- 2. 通過C#應用程序從HP P420i Contrller獲取SMART信息
- 3. 通過API命令獲取應用程序引擎信息
- 4. 通過WMI從c#獲取WebCam設備ID和信息
- 5. 如何通過udid獲取idevice信息?
- 6. 如何通過zip獲取openweathermap.org信息?
- 7. 如何通過js獲取div信息?
- 8. 獲取Facebook應用程序信息
- 9. 如何在應用程序中獲取MMS/SMS消息信息?
- 10. 如何獲取過程信息?
- 11. 獲取通用應用程序(windows phone)信息
- 12. 如何使用BatteryStatsHelper獲取應用程序電池信息?
- 13. 如何從調用應用程序獲取版本信息
- 14. 獲取沒有WMI的電池信息
- 15. WMI硬件,獲取RAM信息
- 16. 獲取服務信息,而WMI
- 17. 獲取WMI信息的C代碼
- 18. 獲取過程信息
- 19. 如何使用WMI查詢獲取PCIController信息?
- 20. 如何在我的應用程序中獲取電池信息?
- 21. 如何從Osclass獲取信息到Android應用程序
- 22. 如何從UWP應用程序獲取診斷統計信息
- 23. 桌面應用程序如何從網站獲取信息?
- 24. 通過Google API獲取用戶信息
- 25. 如何通過一些分析信息獲取程序的調用圖
- 26. 通過java創建iis應用程序
- 27. 如何通過用戶id獲取Facebook用戶信息android
- 28. 如何通過短信獲取聯繫信息
- 29. 通過win消息在應用程序之間進行通信
- 30. WMI:獲取無效類錯誤通過其他程序
謝謝@lsalamon,這是一個有用的提示,(+1),但我忘記標記我的要求,它是.NET代碼。 – ProfK 2009-09-20 15:53:14