Sign in to follow this  
Followers 0
Digisoul

new instance of a class

2 posts in this topic

How can i get the functnality of Object to create a new instance of a class ?

Use in Vb Script:

SWbemObject.SpawnInstance_

Please some 1 tell me how can i create this instance with Autoit ?


73 108 111 118 101 65 117 116 111 105 116

Share this post


Link to post
Share on other sites



How can i get the functnality of Object to create a new instance of a class ?

Use in Vb Script:

SWbemObject.SpawnInstance_

Please some 1 tell me how can i create this instance with Autoit ?

What happens when you just use it? Seems to work for me.

Demo translated from: MSDN: SWbemObject Object

$wbemCimtypeString = 8
$objSWbemService = ObjGet("Winmgmts:root\default")
$objClass = $objSWbemService.Get()
$objClass.Path_.Class = "NewClass"

; Add a property
; String property
$objClass.Properties_.add("PropertyName", $wbemCimtypeString)
; Make the property a key property 
$objClass.Properties_("PropertyName").Qualifiers_.add("key", True)

; Write the new class to the root\default namespace in the repository
$objClassPath = $objClass.Put_
ConsoleWrite("$objClassPath.Path = " & $objClassPath.Path & @LF)

; Create an instance of the new class using SWbemObject.SpawnInstance
$objNewClass = ObjGet("Winmgmts:root\default:NewClass")
$objNewInst = $objNewClass.Spawninstance_

$objNewInst.PropertyName = "My Instance"

; Write the instance into the repository
$objInstancePath = $objNewInst.Put_
ConsoleWrite("$objInstancePath.Path = " & $objInstancePath.Path & @LF)

Output:

>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Temp\Test.au3"  
$objClassPath.Path = \\.\root\default:NewClass
$objInstancePath.Path = \\.\root\default:NewClass.PropertyName="My Instance"
+>17:56:29 AutoIT3.exe ended.rc:0

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0