calldor Posted March 25, 2012 Posted March 25, 2012 (edited) i woking on automatisation for ConfigMgr 2012 but are blocked i see no Solution for a possible simple thing.Here an example code Snipet Function to create a Collection..the collection will be created also in AutoIt but i loose the collecitonPath so i can not use it to do more with it, ' vbscript Create the collection.Set newCollection = swbemconnection.Get("SMS_Collection").SpawnInstance_newCollection.Name = newCollectionNamenewCollection.Comment = newCollectionCommentnewCollection.OwnedByThisSite = ownedByThisSitenewCollection.CollectionType = CollectionTypenewCollection.LimitToCollectionID = ExistingLimitToCollectionID' Save collection and collection path for later useSet collectionPath = newCollection.Put_The return value writen to the collectionPath var is like "SCCM2012.mydomain.netrootsmssite_S01:MS_Collection.CollectionID="S0100019"" all try's to do same in AutoIt fail...; AutoIT Create the collection.Local $newCollection = $sconnection.Get("SMS_Collection").SpawnInstance_With $newCollection.Name = $newCollectionName.Comment = $newCollectionComment.OwnedByThisSite = $ownedByThisSite.CollectionType = $CollectionType.LimitToCollectionID = $ExistingLimitToCollectionIDEndWith; Save collection and collection path for later useLocal $collectionPath = $newCollection.Put_same in AutoIt and no value stored in $ColectionPath var any creative solutions or workarounds from a AutoIt Guru ??. Edited March 25, 2012 by calldor
wakillon Posted March 25, 2012 Posted March 25, 2012 May be like this... Local $newCollection = $sconnection.Get ( 'SMS_' & $Collection ).SpawnInstance_() AutoIt 3.3.18.0 X86 - SciTE 4.4.6.0 - WIN 11 24H2 X64 - Other Examples Scripts
water Posted March 25, 2012 Posted March 25, 2012 A COM error handler will give you more information about the error. Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") ; AutoIT Create the collection Local $newCollection = $sconnection.Get("SMS_Collection").SpawnInstance_ With $newCollection .Name = $newCollectionName .Comment = $newCollectionComment .OwnedByThisSite = $ownedByThisSite .CollectionType = $CollectionType .LimitToCollectionID = $ExistingLimitToCollectionID EndWith ; Save collection and collection path for later use Local $collectionPath = $newCollection.Put_ ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _ "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ "err.description is: " & @TAB & $oError.description & @CRLF & _ "err.source is: " & @TAB & $oError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF) EndFunc ;==>_ErrFunc My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
calldor Posted March 25, 2012 Author Posted March 25, 2012 thx for your feedback wakillon but i'cant see how to fix it by setting a part of the Class with a $var.. so i Post the script i transfered from a vb example to autoIT to explain wath i exactly do but without the collectionpath i cant configure the collection. same problem with all other sccm actions.. expandcollapse popup$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler Const $wbemAuthenticationLevelPkt = 6 Global $SCCM_Sitecode Global $newfolderpath Global $strComputer = "SCCM.mydomain.net" Global $strUser = "mydomain.netadministrator" Global $strPassword = "password" Global $obj_wbemLocator = ObjCreate("WbemScripting.SWbemLocator") ;$obj_wbemLocator.Security_.AuthenticationLevel = $wbemAuthenticationLevelPkt ;Packet Privacy Global $wbemConnection = $obj_wbemLocator.ConnectServer($strComputer, "rootsms", $strUser, $strPassword) Global $obj_ProviderLoc = $wbemConnection.InstancesOf("SMS_ProviderLocation") For $Location In $obj_ProviderLoc If $Location.ProviderForLocalSite = True Then $wbemConnection = $obj_wbemLocator.ConnectServer($Location.Machine, "rootsmssite_" & $Location.SiteCode) $SCCM_Sitecode = $Location.SiteCode ExitLoop EndIf Next ; Create Dynamic Device Collections ConsoleWrite(@ScriptLineNumber &@TAB& "reate Dynamic Device Collections " & @CRLF) _CreateDynamicCollection($wbemConnection, "New Dynamic Device Collection", "New Dynamic Device Collection Comment", true, "SELECT * from SMS_R_System", "New Rule Name", 2, "SMS00001") ; Create Dynamic User Collections ConsoleWrite(@ScriptLineNumber &@TAB& "Create Dynamic User Collections" & @CRLF) _CreateDynamicCollection($wbemConnection, "New Dynamic User Collection", "New Dynamic User Collection Comment", true, "SELECT * from SMS_R_User", "New Rule Name", 1, "SMS00004") Func _CreateDynamicCollection($sconnection, $newCollectionName, $newCollectionComment, $ownedByThisSite, $queryForRule, $ruleName, $CollectionType, $ExistingLimitToCollectionID) ; Create the collection. Local $newCollection = $sconnection.Get ('SMS_Collection').SpawnInstance_() ;Global $newCollection = $sconnection.Get("SMS_Collection").SpawnInstance_ With $newCollection .Name = $newCollectionName .Comment = $newCollectionComment .OwnedByThisSite = $ownedByThisSite .CollectionType = $CollectionType .LimitToCollectionID = $ExistingLimitToCollectionID EndWith ; Save the new collection and save the collection path for later. Local $collectionPath = ($newCollection.Put_) ConsoleWrite(@ScriptLineNumber &@TAB& "Save the new collection and save the collection path for later." & @CRLF & $collectionPath& @CRLF) exit ;exit for Test beacuse no collectionpath... ; Create a new collection rule object for validation Local $queryRule = $sconnection.Get("SMS_CollectionRuleQuery") ConsoleWrite(@ScriptLineNumber &@TAB& "Create a new collection rule object for validation" & @CRLF & $queryRule & @CRLF) ; Validate the query (good practice before adding it to the collection). Local $validQuery = $queryRule.ValidateQuery($queryForRule) ConsoleWrite(@ScriptLineNumber &@TAB& ";// Validate the query (good practice before adding it to the collection)." & @CRLF & $validQuery & @CRLF) ; continue with processing, if the query is valid. If $validQuery Then ; Create the query rule. Local $newQueryRule = $QueryRule.SpawnInstance_ $newQueryRule.QueryExpression = $queryForRule $newQueryRule.RuleName = $ruleName ; Add the new query rule to a variable. Local $newCollectionRule = $newQueryRule ; Get the collection. Local $newCollection = $sconnection.Get($collectionPath.RelPath) ; Add the rules to the collection. $newCollection.Properties_.Item("AddMembershipRule") = $newCollectionRule ; Call RequestRefresh to initiate the collection evaluator. $newCollection.Properties_.Item("RequestRefresh") = False EndIf EndFunc Func MyErrFunc() Dim $HexNumber=hex($oMyError.number,8) Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription ) $g_eventerror = 1; something to check for when this function returns Endfunc
calldor Posted March 25, 2012 Author Posted March 25, 2012 Thx water shure i use an error handler the collection was created without errors but i got no identifier back so i can not continue to configure it ... A COM error handler will give you more information about the error. Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") ; AutoIT Create the collection Local $newCollection = $sconnection.Get("SMS_Collection").SpawnInstance_ With $newCollection .Name = $newCollectionName .Comment = $newCollectionComment .OwnedByThisSite = $ownedByThisSite .CollectionType = $CollectionType .LimitToCollectionID = $ExistingLimitToCollectionID EndWith ; Save collection and collection path for later use Local $collectionPath = $newCollection.Put_ ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _ "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ "err.description is: " & @TAB & $oError.description & @CRLF & _ "err.source is: " & @TAB & $oError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF) EndFunc ;==>_ErrFunc
wakillon Posted March 25, 2012 Posted March 25, 2012 Try Local $newCollection = $sconnection.Get ('SMS_Collection').SpawnInstance_() $newCollection.Name = $newCollectionName $newCollection.Comment = $newCollectionComment $newCollection.OwnedByThisSite = $ownedByThisSite $newCollection.CollectionType = $CollectionType $newCollection.LimitToCollectionID = $ExistingLimitToCollectionID ; Save the new collection and save the collection path for later. Local $collectionPath = $newCollection.Put_() Did you get result for other values as $newCollection.Name ? AutoIt 3.3.18.0 X86 - SciTE 4.4.6.0 - WIN 11 24H2 X64 - Other Examples Scripts
calldor Posted March 25, 2012 Author Posted March 25, 2012 Try Local $newCollection = $sconnection.Get ('SMS_Collection').SpawnInstance_() $newCollection.Name = $newCollectionName $newCollection.Comment = $newCollectionComment $newCollection.OwnedByThisSite = $ownedByThisSite $newCollection.CollectionType = $CollectionType $newCollection.LimitToCollectionID = $ExistingLimitToCollectionID ; Save the new collection and save the collection path for later. Local $collectionPath = $newCollection.Put_() Did you get result for other values as $newCollection.Name ? allready tryed same effect with or wihout "with" no return..value
water Posted March 25, 2012 Posted March 25, 2012 So there is no COM error and no return value. Maybe there is an error code. Can you insertMsgBox(0, "", "@error: " & @error & ", @extended: " & @extended)after; AutoIT Create the collection Local $newCollection = $sconnection.Get("SMS_Collection").SpawnInstance_ My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
calldor Posted March 25, 2012 Author Posted March 25, 2012 So there is no COM error and no return value. Maybe there is an error code. Can you insertMsgBox(0, "", "@error: " & @error & ", @extended: " & @extended)after; AutoIT Create the collection Local $newCollection = $sconnection.Get("SMS_Collection").SpawnInstance_ ok i insert ConsoleWrite("@error: " & @error & ", @extended: " & @extended &@CRLF) ;Global $newCollection = $sconnection.Get("SMS_Collection").SpawnInstance_ With $newCollection .Name = $newCollectionName .Comment = $newCollectionComment .OwnedByThisSite = $ownedByThisSite .CollectionType = $CollectionType .LimitToCollectionID = $ExistingLimitToCollectionID EndWith ; Save the new collection and save the collection path for later. Local $collectionPath = ($newCollection.Put_) ConsoleWrite("@error: " & @error & ", @extended: " & @extended&@CRLF) Returns.. @error: 0, @extended: 0 @error: 0, @extended: 0 i going cracy...
ProgAndy Posted March 25, 2012 Posted March 25, 2012 Did you already try to call .Put_() with an empty pair of parantheses? *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
calldor Posted March 25, 2012 Author Posted March 25, 2012 is it possible that autoit is unable to store a result from .Put_ in a $var same done in Vb give back the full collectionpath from the new created collection.. like this: SCCM2012.mydomain.netrootsmssite_S01:MS_Collection.CollectionID="S0100019"AutoIt create the collection also successfully but no return looks cracy..
water Posted March 25, 2012 Posted March 25, 2012 (edited) Shouldn't the code be:Global $newCollection = $sconnection.Get("SMS_Collection").SpawnInstance_ ConsoleWrite("@error: " & @error & ", @extended: " & @extended &@CRLF) With $newCollection .Name = $newCollectionName .Comment = $newCollectionComment .OwnedByThisSite = $ownedByThisSite .CollectionType = $CollectionType .LimitToCollectionID = $ExistingLimitToCollectionID EndWith ; Save the new collection and save the collection path for later. Local $collectionPath = ($newCollection.Put_) ConsoleWrite("@error: " & @error & ", @extended: " & @extended&@CRLF) Edited March 25, 2012 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
wakillon Posted March 25, 2012 Posted March 25, 2012 Did you already try to call .Put_() with an empty pair of parantheses?I already suggest in Post#6 AutoIt 3.3.18.0 X86 - SciTE 4.4.6.0 - WIN 11 24H2 X64 - Other Examples Scripts
calldor Posted March 25, 2012 Author Posted March 25, 2012 Did you already try to call .Put_() with an empty pair of parantheses? Local $collectionPath = $newCollection.Put_() tryed same effect creates the collection but also no return no error...
calldor Posted March 25, 2012 Author Posted March 25, 2012 looks like i found a strong part of a code problem...
calldor Posted March 25, 2012 Author Posted March 25, 2012 thx all for your input looks like the powercoders has no solution. is it possible that this cant be done in autoit or it looks more like a Bug??
water Posted March 25, 2012 Posted March 25, 2012 If the Visual Basic code returns the desired result on your machine then it should be possible to do in AutoIt too I think. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
calldor Posted March 26, 2012 Author Posted March 26, 2012 yep normaly i also can use a .Get_ to read it in but this is also empty..
calldor Posted March 27, 2012 Author Posted March 27, 2012 SWbemObject.Put_ method Return valueIf the call is successful, an SWbemObjectPath object is returned. This object contains the object path of the instance or class that has been successfully committed to WMI.I played long Time arround no solution ? So the $Var is really empty and i ask could this be a Bug in AutoIt because same can be done well in vbscript?
water Posted March 27, 2012 Posted March 27, 2012 In your first post you write thatSet collectionPath = newCollection.Put_ The return value written to the collectionPath var is like "\\SCCM2012.mydomain.net\root\sms\site_S01:MS_Collection.CollectionID="S0100019""Now you write an SWbemObjectPath object is returnedCan you test what type of data is actually returned. Do a MsgBox(0, "", "$CollectionPath is an object: " & IsObj($CollectionPath))and post what you get. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now