Jump to content

need Help .Put_ no return value


Recommended Posts

:oops: 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, :bye:

' vbscript Create the collection.

Set newCollection = swbemconnection.Get("SMS_Collection").SpawnInstance_

newCollection.Name = newCollectionName

newCollection.Comment = newCollectionComment

newCollection.OwnedByThisSite = ownedByThisSite

newCollection.CollectionType = CollectionType

newCollection.LimitToCollectionID = ExistingLimitToCollectionID

' Save collection and collection path for later use

Set collectionPath = newCollection.Put_

The return value writen to the collectionPath var is like "SCCM2012.mydomain.netrootsmssite_S01:MS_Collection.CollectionID="S0100019""

:doh: 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 = $ExistingLimitToCollectionID

EndWith

; Save collection and collection path for later use

Local $collectionPath = $newCollection.Put_

same in AutoIt and no value stored in $ColectionPath var any creative solutions or workarounds from a AutoIt Guru ??

.

Edited by calldor
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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.. :oops:

$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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

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
Link to comment
Share on other sites

So there is no COM error and no return value. Maybe there is an error code.

Can you insert

MsgBox(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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

So there is no COM error and no return value. Maybe there is an error code.

Can you insert

MsgBox(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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

SWbemObject.Put_ method

Return value

If 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?

Link to comment
Share on other sites

In your first post you write that

Set 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 returned

Can 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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...