Shaun Cassells at MyITForum.com

SMS 2003 and ConfigMgr 2007, PowerShell, Scripting, Finance, Fitness and Fun

February 2007 - Posts

-2147217407 error or 80041001 how to avoid programmatically

If you have done any scripting or programming for WMI you have inevitably run into error 2147217407 or -2147217407 or 80041001

What is this error? 
 Well it is ExecASynchQuery Failure. 
Umm okay what does that mean? 
 It means the query took long enough that it timed out. 
What does that mean?
 That either you are referencing an object that was just created (and isn't done being created) or the server was to busy (might want to consider opening more WMI connections) or that your search isn't specific enough
 
Okay how do I fix... or avoid the issue.   Well this is going to infuriate you, but seriously, take a deep breath and wait.  10 seconds seems to be a good time.  

Here is how you do it in VBA:

    'Turn off the pause if error thingy (don't worry we check)
    On Error Resume Next
        'Create the advertisement.
        'This is your put statement or could be any command line
        instAdvert.Put_
        'Count it so you don't infinite loop
        ErrCounter = 0
        'Try it once.  You'll like it
        Do While (Err.Number <> 0) And (ErrCounter < 3)
            'Tell the plebian something didn't work right. 
            'Plus you give them error code... so when they report something broke you say what :)
            Result = MsgBox("Advertisement connect failed Trying again in 10 seconds" & vbCrLf & _
                            " Error Loop #: " & ErrCounter & " of 3" & vbCrLf & _
                            " Error Number: " & Err.Number, vbExclamation, "Trying again in 10 seconds")
            'Sleep for 10 seconds because advertisements are being communicated to fast (WMI issues)
            newHour = Hour(Now())
            newMinute = Minute(Now())
            ' + 10 = Delay 10 seconds from now
            newSecond = Second(Now()) + 10
            waitTime = TimeSerial(newHour, newMinute, newSecond)
            ' Hang time!
            Application.Wait waitTime
             'Reset the Err counter
             '  !!!!! VERY IMPORTANT !!!!!

            Err.Number = 0
            'Try again
            instAdvert.Put_
            'count up so you don't infinite loop I miss C++ (inside joke)
            ErrCounter = ErrCounter + 1
           
        Loop
    'Turn error stopping back on!
    'Don't forget this one; otherwise you'll have no idea if something breaks later.
   
    On Error GoTo 0

SoftGrid via SMS adds an Add Remove Program Entry

 

Been working with our MS TAM for more detail.

http://www.softricity.com/products/softgrid-sms.asp

QUOTE:

Integrate asset discovery and metering
Virtualized applications are included in SMS asset discovery and metering reports, providing a complete picture of all application usage.

 

Turns out this is because SoftGrid inserts an Add Remove Program entry on the target PC.  The Add Remove Program entry is only inserted with SMS distribution.  This may or may not still be present when version 4.5 comes out in July.

Posted: Feb 07 2007, 09:23 AM by scassells | with no comments
Filed under:
Modification of SMSAutomation DLL from the SMS 2003 SDK 3.1 to prevent duplicate items with the same name

I have gotten back into scripting and programming for SMS again.  This time in C#

Programmatic Problem:  SMS has a restriction that requires a unique name in the MMC.  However, programmatically you can create as many items as you want because they are based on a unique instance ID (eg.  CollectionID)

The following Code Fragment is from the Collections.cs.   Modifying the Constructor.  I put a try catch block in to see if the exact name already exists.  If it does exist, return nothing.  If it doesn't continue with the constructor.  This works great with all constructors, Packages, Collections, Programs, Advertisements, etc.

 

  

// **********************************************************************

// Constructor - Create a new collection

// **********************************************************************

internal SMSCollection(SMSProvider oProvider, string sCollectionName)

{

// Create a new SMS_Collection instance

m_oProvider = oProvider;

try //Does collection Exist?

{

ManagementObjectCollection oQueryResults =

m_oProvider.Connection.ExecuteQuery("SELECT * FROM SMS_Collection WHERE NAME=\"" + sCollectionName + "\"");

foreach (ManagementObject mo in oQueryResults)

{

//collection Exists. Stop Creation

throw new Exception("Found collection. Halting Creation.");

}

}

catch (Exception e)

{

//collection Does Not Exist. Continue.

ManagementObject oCollection = m_oProvider.Connection.CreateInstance("SMS_Collection");

oCollection.SetPropertyValue("Name", sCollectionName);

oCollection.SetPropertyValue("OwnedByThisSite", true);

string sRelPath = oCollection.Put(new PutOptions(m_oProvider.Context)).RelativePath;

// Load the new collection

oCollection = m_oProvider.Connection.GetObject(sRelPath, m_oProvider.Context);

Load(oCollection, true);

}

}