Skip to main content

sms: decoding advertflags for "asap"

before i start writing this, let me give some credit to robert mahle for getting me some information confirming stuff in this post. we've been working a bit (har har, no pun intended) trying to figure out how to decode the value of "asap" from the sms admin console into a spreadsheet. before i move too far ahead, some background for you...

in this previous post about displaying advertisement info via a script, we ran into some confusion trying to decode the advertflags value. trying to get "asap" to show up just wasn't happening. the real confusion about this is "asap" is not treated like other schedule data that you'd find by looking for the sms_scheduletoken data type. usually it's held under assignedschedule. despite the fact that "asap" shows up in the sms admin console as a schedule, it's held under advertflags. the sdk confirms this:

AdvertFlags
  Data type: uint32
  Access type: Read/write
  Qualifiers: Bits
  When to announce the advertisement to the user. These bit flags must be coordinated with the
  bit flags specified in the ProgramFlags property of the advertised program. For example, if
  you set ONUSERLOGOFF, the NOUSERLOGGEDIN flag in the program must be set. If the flag
  settings do not match, the program will not be advertised.
 
  The default value is 0.
 
  Bit flags are as follows:
 
  IMMEDIATE (bit 5)
  ONSYSTEMSTARTUP (bit 8)
  ONUSERLOGON (bit 9)
  ONUSERLOGOFF (bit 10)
  NO_DISPLAY (bit 25)
  ONSLOWNET (bit 26)

in order to decode advertflags, you have to have a little bit of understanding regarding how bit flags work. don't worry; we'll get into all that in a second. you know, as long as we're covering "asap" stuff, i suppose we'll use that in our example.

alright, the first thing to do would be to create a little script that will dump out all of your advertisements that are set to "asap." don't sweat it. no coding required. here's a little something you can use. it's from the book sms 2003 recipes: a problem-solution approach. i modified it a little bit for the decoding work we'll be doing.

strSMSServer = "mySMSServer"

Set objLoc =  CreateObject("WbemScripting.SWbemLocator")
Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms")
Set Results = objSMS.ExecQuery("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true")
For each Loc in Results
 If Loc.ProviderForLocalSite = True Then
     Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & Loc.SiteCode)
         strSMSSiteCode = Loc.Sitecode
 End If
Next

Set colAdverts = objSMS.ExecQuery("Select * From SMS_Advertisement order by AdvertisementName")
For Each objAdvert In colAdverts
 if (objadvert.advertflags AND 2^5) then
     wscript.echo objAdvert.AdvertisementName & " ------- " & objAdvert.AdvertFlags
 end if
Next

if i run this script in my environment, i'd get output like the following... (i've changed the names around in case you thought we ran apps from a company called some).

C:\temp>cscript smsadvertisement.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Some Custom Screensaver ------- 33554464
Some Antivirus App ------- 33554464
Some Email Disaster Recovery Analyzer ------- 33554464
Some Monitoring Agent ------- 33554464
Some Zip Utility 9.0 ------- 33554464
Some Webby App ------- 33554464

the value following the ------- is the value of advertflags. in my environment, all of these advertisements contain the same value for me (may not be the case for you). i'm going to use the first one called "some custom screensaver." the value, obviously for this one is 33554464. as a reminder...

bit 1bit 2result
000
100
010
111

when using AND as a bitwise operator, this is basically what occurs: as you can see, anything with both comparison bits set to 1 will result in 1. otherwise, you get 0. hold on to that... if you look at the script above, we perform a bitwise AND operation. it happens right here:

if (objadvert.advertflags AND 2^5) then
  wscript.echo objAdvert.AdvertisementName & " ------- " & objAdvert.AdvertFlags
end if

okay, real quick math lesson: 2 to the 5th is ... ? that's right, 32. keep that magic value in your head. it's easier to do it this way because in the sdk, it specifies it's the 5th value. instead of multiplying 2*2*2*2*2, we just raise it to the power of the 5. the 5th bit is "immediate" otherwise known as "asap". take the value you're working with and put it in your calculator as a decimal value. now, click the "bin" radio button. you'll see that the value of 33554464 is converted to 10000000000000000000100000. now, do the same thing for 32 (or 2^5). you'll get 100000. just to make it easier to understand visually, i added leading zeroes, getting this: 00000000000000000000100000. now stack them together:

10000000000000000000100000
00000000000000000000100000
--------------------------
00000000000000000000100000

remember above when i told you that both comparison bits have to be 1 in order for the result bit to be 1? well, look at that. we only have a single place that it occurs.

ANDing the values together gives you a value of 32. (if you don't believe me, paste 100000 into your calculator as a hex value and convert it to dec.) the if/then script statement above is doing this for you.by the way, since you're only checking for one value, the result being greater than 0 is a successful return. technically you could write it as:
if (objadvert.advertflags AND 2^5) > 0 then
  wscript.echo objAdvert.AdvertisementName & " ------- " & objAdvert.AdvertFlags
end if
but you get the idea. since we know the value we return is 32, which is greater than 0, then it successfully found the 5th bit to be turned on. you could also set it to = 2^5 instead.

Comments

  1. I was trapped in AssignedScheduleEnabled, thanks for pointing me to AdvertFlags
    //Johan

    ReplyDelete

Post a Comment

Popular posts from this blog

using preloadpkgonsite.exe to stage compressed copies to child site distribution points

UPDATE: john marcum sent me a kind email to let me know about a problem he ran into with preloadpkgonsite.exe in the new SCCM Toolkit V2 where under certain conditions, packages will not uncompress.  if you are using the v2 toolkit, PLEASE read this blog post before proceeding.   here’s a scenario that came up on the mssms@lists.myitforum.com mailing list. when confronted with a situation of large packages and wan links, it’s generally best to get the data to the other location without going over the wire. in this case, 75gb. :/ the “how” you get the files there is really not the most important thing to worry about. once they’re there and moved to the appropriate location, preloadpkgonsite.exe is required to install the compressed source files. once done, a status message goes back to the parent server which should stop the upstream server from copying the package source files over the wan to the child site. anyway, if it’s a relatively small amount of packages, you can

How to Identify Applications Using Your Domain Controller

Problem Everyone has been through it. We've all had to retire or replace a domain controller at some point in our checkered collective experiences. While AD provides very intelligent high availability, some applications are just plain dumb. They do not observe site awareness or participate in locating a domain controller. All they want is the name or IP of one domain controller which gets hardcoded in a configuration file somewhere, deeply embedded in some file folder or setting that you are never going to find. How do you look at a DC and decide which applications might be doing it? Packet trace? Logs? Shut it down and wait for screaming? It seems very tedious and nearly impossible. Potential Solution Obviously I wouldn't even bother posting this if I hadn't run across something interesting. :) I ran across something in draftcalled Domain Controller Isolation. Since it's in draft, I don't know that it's published yet. HOWEVER, the concept is based off

sccm: content hash fails to match

back in 2008, I wrote up a little thing about how distribution manager fails to send a package to a distribution point . even though a lot of what I wrote that for was the failure of packages to get delivered to child sites, the result was pretty much the same. when the client tries to run the advertisement with an old package, the result was a failure because of content mismatch. I went through an ordeal recently capturing these exact kinds of failures and corrected quite a number of problems with these packages. the resulting blog post is my effort to capture how these problems were resolved. if nothing else, it's a basic checklist of things you can use.   DETECTION status messages take a look at your status messages. this has to be the easiest way to determine where these problems exist. unfortunately, it requires that a client is already experiencing problems. there are client logs you can examine as well such as cas, but I wasn't even sure I was going to have enough m