如何使用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. 通过访问令牌应用程序获取用户信息
- 3. WMI获取更多信息
- 4. 通过C#应用程序从HP P420i Contrller获取SMART信息
- 5. 通过API命令获取应用程序引擎信息
- 6. Navita TEM应用程序如何获取通话记录信息?
- 7. 如何获取iPhone应用程序从Web上获取信息?
- 8. 通过WMI从c#获取WebCam设备ID和信息
- 9. 如何通过zip获取openweathermap.org信息?
- 10. 如何通过udid获取idevice信息?
- 11. 如何通过js获取div信息?
- 12. 如何在应用程序中获取MMS/SMS消息信息?
- 13. 获取Facebook应用程序信息
- 14. 如何通过WMI查询获取GB中的总物理内存(RAM)信息?
- 15. 如何获取过程信息?
- 16. 获取通用应用程序(windows phone)信息
- 17. 如何从调用应用程序获取版本信息
- 18. 应用程序如何获取PayPal用户交易信息?
- 19. 如何使用BatteryStatsHelper获取应用程序电池信息?
- 20. 如何获取ios应用程序的签名应用程序证书信息
- 21. 如何在配置过程中获取Heroku应用程序的信息?
- 22. 获取WMI信息的C代码
- 23. 从Python获取CPU信息WMI
- 24. WMI硬件,获取RAM信息
- 25. 获取服务信息,而WMI
- 26. 获取没有WMI的电池信息
- 27. 如何使用WMI获取FireWire详细信息?
- 28. 如何使用WMI查询获取PCIController信息?
- 29. 获取过程信息
- 30. 如何获取iOS中前台应用程序的信息?
谢谢@lsalamon,这是一个有用的提示,(+1),但我忘记标记我的要求,它是.NET代码。 – ProfK 2009-09-20 15:53:14