//wmi 客户端
import com;

namespace com;

class wmi{
	ctor(path,computer){
		return ..com.GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" + (computer:".") + (path || "\root\cimv2"))
	};
}

wmi.sink = function(event){
	var sinkObj = ..com.CreateObject( "WbemScripting.SWbemSink");
	..com.Connect(sinkObj,event);
	return sinkObj;
}

wmi.query = function(wql){ 
	if(..string.find(wql,"\s")) return wmi().ExecQuery(wql)
	else return wmi().InstancesOf(wql)
} 

wmi.get = function(wql,property){
	var items = wmi.query(wql);
	if( items ) {
		var item = ..com.first(items);
		if(item && property) return item[property];
		return item;
	}
}

wmi.each = function(wql){
	var items = wmi.query(wql);
	if( items ) return ..com.each(items);
}

/**intellisense()
com.wmi = WMI / Windows Management Instrumentation 客户端\n参考文档 https://docs.microsoft.com/en-us/windows/win32/wmisdk/wmi-reference
com.wmi( = 创建 WMI 客户端对象
com.wmi(.(path,computer) = 创建 WMI 客户端对象,所有参数可省略,\n@path 默认为 "\root\cimv2"\n@computer 默认为"."
com.wmi() = !stdComObject.
com.wmi.sink(event) = @.sink(\n	OnCompleted = function(hResult,wbemErrorObject,wbemAsyncContext){\n		\n	};\n	OnObjectPut = function(wbemObjectPath,wbemAsyncContext){\n		\n	};\n	OnObjectReady = function(wbemObject,wbemAsyncContext){\n		\n	};\n	OnProgress = function(upperBound,current,message,wbemAsyncContext){\n		\n	};\n)
com.wmi.query("__") =  可输入WQL查询语句或类名,\n调用 ExecQuery 返回查询结果
com.wmi.get( = 可输入WQL查询语句或类名,\n返回首个查询结果
com.wmi.get(.(wql) =  @wql 参数可输入WQL查询语句或类名,\n成功则返回首个查询结果
com.wmi.get(.(wql,property) =  @wql 参数可输入WQL查询语句或类名,\n成功则返回首个查询结果中 @property 参数指定的属性值\n失败返回 null
com.wmi.each(wql) =  @for index,item in com.wmi.each("__/*可输入WQL查询语句或类名*/") {
	
} 
end intellisense**/

/**intellisense(!stdComObject)
ExecQuery("SELECT * FROM Win32_BaseBoard__") = 使用 WQL 进行查询,返回 COM 对象,\n参数@2必须省略,可选用参数@3指定选项,\n半同步优化请将参数@3指定以下值 _wbemFlagReturnImmediately | _wbemFlagForwardOnly\n更多参数说明请参考 https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemservices-execquery
ExecQueryAsync(.(sinkObj,wqlQuery) = 异步查询对象,\n参数@1必须传入 com.wmi.sink 创建的对象,\n参数@2指定 WQL 查询语句\n更多参数说明请参考 https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemservices-execqueryasync
ExecNotificationQueryAsync(.(sinkObj,wqlQuery) = 执行异步查询以接收事件,\n参数@1必须传入 com.wmi.sink 创建的对象,\n参数@2指定 WQL 查询语句\n更多参数说明请参考 https://docs.microsoft.com/en-us/windows/win32/wmisdk/swbemservices-execnotificationqueryasync
InstancesOf(.(strClass,iFlags) = 根据指定的类名,返回可使用 com.each 遍历的对象
end intellisense**/

/**intellisense()
_wbemFlagReturnImmediately=@16/*_wbemFlagReturnImmediately*/
_wbemFlagForwardOnly=@32/*_wbemFlagForwardOnly*/
end intellisense**/