Rights to sample code -


  • Here's the specific article I'm interested in :

    I've included the original e-mail that I sent below, and the reply I've had so far. I checked in the Terms of Use page here:

    This page lists license terms for software, but I think it means downloadable software, rather than sample code. I couldn't find anything that mentions the rights for sample code. I assume it's published on the support pages to help people, and that it's OK to use, but I can't find something that says that.

    I'm currently trying to develop something for myself, but if it works out, I might wish to distribute the compiled code, so I'd like to know if I'd be able to do that, or if it's not acceptable.
    Checked the agreements but did not find any licensing rules related to "sample code"


    Looking for Right to sample code,



    • Moved by Mike Feng Thursday, August 18, 2011 6:12 AM off-topic (From:Visual Basic General)
    Monday, August 15, 2011 2:22 PM

All replies

  • All Microsoft sample codes are copywrite, You cannot copy/paste them and used them for commercial purpose.

    However, If you examine the algorithm used in the example, you will realize that it didn't brings any innovative idea and is plainly a method of commun usage.

    Commun usage method is not copywritable. so the idea of the algorithm can be used as base to write a code that have similar function.

    The reason why Microsoft publish a code is obviously not to show a method of doing someting that you can never use.

    Monday, August 15, 2011 2:57 PM
  • To expand on what Crazypennie says, you cannot take the actual sample code and sell or distribute it as your own work: it is Copyrighted (by default, even if it doesn't state this).

    However, when you use that code in a compiled application, you are not distributing the copyrighted code, but using the feature, algorithm or capability that it describes.

    This is like having a wrench or spanner. The design and materials are copyrighted and possibly patented. You cannot take that spanner and say it is your design to do with as you wish - you cannot make more spanners from that spanner and sell them. However, you can use the functionality afforded by that spanner and build a car. The car is not a derivative work of the spanner.

    [I'm sure someone will poke holes in this argument, but it's only used as an illustative example; likewise there can be other intricacies associated with software patents, but generally, patented algorithms, and the code implementing said algorithms are not published].

    Further reinforcing Crazypennie's statements, think about it from a 'reasonable man' standpoint: published sample code is, by its nature, designed to be used. That is, it is saying 'this is how you would perform this function'.

    Stephen J Whiteley
    • Proposed as answer by Reed KimbleMVP Monday, August 15, 2011 8:31 PM
    Monday, August 15, 2011 5:40 PM
  • Hi ALL,

    This is an interesting question.

    What if you were to take the method and rewrite it slightly with different variable names and so on?



    Click this link to see how to insert a picture into a forum post.
    Or see
    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    XNA is coming to VB.Net

    App Hub forums

    Monday, August 15, 2011 5:57 PM
  • I think this is what you're looking for:


    So keep the copyright notices (if any) in for the appropriate sections, and it's often a good idea to add in the URL where the code came from in the first place anyway. Consult someone appropriately qualified in the relevant laws if in doubt.



    Monday, August 15, 2011 7:45 PM
  • This is a great question!! And I can see why you had trouble finding an answer, because it took me several minutes to find the exact answer and I knew exactly what I was looking for!


    Not everything stated here is 100% correct.  Pennie actually extended an assumption just a bit to far: there are indeed Microsoft-written code samples which may be directly copied into a commercial product - they just want copyright credit, and don't want you to then try to claim that your product was written by Microsoft.  =P

    Specifically, the code you know you can always use directly is any sample found in a KB Article.  Truly, KB Articles are written to correct or help prevent serious issues in the Windows platform.  Microsoft would rather give away free sample code then have a lot of software out there which developers do not understand how to fix.

    If you go back to that KB article, and scroll down to where you found the TOU link, you will see just above that a link to the "Services Agreement" for this particular service (the Knowledge Base).  This link takes you to:

    Now the master TOU at is the place to start.  This is the root Terms of Use for all of the websites provided by Microsoft.  But this document was designed to be an extremely simplified legal document which could be readily understood by the average reader, and at the same time it is designed to cover every aspect of Microsoft's online presence... these are two rather contradictory objectives...

    So to follow the legal speak, and be sure we are correct, we first have to look at the section from the TOU:


    Through its network of Web properties, Microsoft provides you with access to a variety of resources, including developer tools, download areas, communication forums and product information (collectively "Services"). The Services, including any updates, enhancements, new features, and/or the addition of any new Web properties, are subject to the TOU.

    Now then, we know that any particular "thing" we find on a website whose parent domain is can be considered a "Service".  So, when we look at the footer links on any Microsoft site, we can look for an applicable "Service Agreement" which applies to that particular service.  It is in these service agreements that we can find information specific to the site we are viewing.

    So in the KB site services agreement, under the section Ownership & License, we see that item (d) allows us to use sample code:

    d. Sample Code. In addition to the rights set out in the Developments section above, you are also granted a non-exclusive, perpetual right to reproduce and distribute the object code form of any computer code, provided by us for the purpose of illustration (“sample code”) provided that you agree:

    • (i) not to use our name, logo, or trademarks to market your computer product in which the sample code is embedded;
    • (ii) to include a valid copyright notice on your computer product in which the sample code is embedded;
    • and (iii) to indemnify, hold harmless, and defend us and our suppliers from and against any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the sample code.


    So the precise answer is available, even if it becomes somewhat difficult to find due to the overwhelming depth and breadth of the Microsoft online presence.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    Monday, August 15, 2011 8:23 PM
  • However, when you use that code in a compiled application, you are not distributing the copyrighted code, but using the feature, algorithm or capability that it describes.


    Stephen J Whiteley

    This is the key part of any copyrighted code (and code found on ANY website that does not expressly say is "FREE to reproduce" is likely copyrighted by the Site's TOU).

    Once you incorportate the logic, it becomes your code.  The real question is if you can just copy-paste, or if you need to rewrite it using your own variable names and coding style.

    In the case where you are allowed to copy-paste, but are required to maintain a Copyright notice, you typically will include with your product's own copyright, a section which details the code components you used and their copyrights.  We actually see this quite commonly if we actually read a program's copyrights.  :)  For instance, click help - about on a really hefty application, like Photoshop, and check out how may credits they must give for code that they have either licensed or reused.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    Monday, August 15, 2011 8:37 PM
  • @John - LOL I think you'd be good to go!

    Sometimes there may be a copyright covered block of code so simplistic, or so finely tuned, that there is little you can do except change the variable names without ruining the code itself.  There may be no other way to reproduce it in the same language...

    I think the only way to protect the actual logic of your code from being reproduced is to never print it in the first place.  =)

    In any event, if you use someone else's logic and simply rewrite it, then giving them credit would still be the proper thing to do.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    Monday, August 15, 2011 8:43 PM
  • Reed,

    Here I do not dispute any of your comments since I believe that they are right,

    However, I also believe that One should avoid as much as possible to copy/paste or use an exact copy of an algorithm from a souce exterior of the organisation that produce a commercial software. regardless if it is Microsoft or not and regardlless if there is an explicit Copywright/ agreement or not.


    Monday, August 15, 2011 9:10 PM
  • Pennie,

    Agreed.  :)

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    Monday, August 15, 2011 9:40 PM