我又构建了一个代码验证该属性,设置一个新的类的该属性为True
但是该类还是能设置2个实例
难道这个属性不是标志该类只有一个实例?
- Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
- Set objSWbemServices = objSWbemLocator.ConnectServer()
- Set objSWbemObject = objSWbemServices.Get() '获取一个空类的实例
- objSWbemObject.Path_.Class = "NewClass" '设置类名
- objSWbemObject.Properties_.Add "Property01", 8 '为这个类添加一个字符串属性
- objSWbemObject.Properties_("Property01").Qualifiers_.Add "key", True '设定一个主键属性
- Set objSWbemObjectPath = objSWbemObject.Put_() '更新该类到WMI中,同时返回一个SWbemObjectPath对象
- Msgbox "IsSingleton:" & objSWbemObjectPath.IsSingleton 'False
- objSWbemObjectPath.SetAsSingleton()
- Msgbox "IsSingleton:" & objSWbemObjectPath.IsSingleton 'True
- Set objSWbemObject = objSWbemServices.Get("NewClass")
- Set objNewInst = objSWbemObject.SpawnInstance_() '为这个类增加一个实例
- objNewInst.Property01 = "New00" '设置实例的属性值
- Set objNewInst1 = objSWbemObject.SpawnInstance_() '为这个类再增加一个实例
- objNewInst1.Property01 = "New01" '设置实例的属性值
- objNewInst.Put_() '更新该类到WMI中
- objNewInst1.Put_()
- Set objSWbemObjectSet = objSWbemServices.InstancesOf("NewClass")
- Msgbox "这个类有 " & objSWbemObjectSet.Count & " 个实例"
- objSWbemObject.Delete_() '删除这个类
复制代码
|