{"id":1900,"date":"2018-03-07T14:10:51","date_gmt":"2018-03-07T14:10:51","guid":{"rendered":"https:\/\/www.autoitconsulting.com\/site\/?page_id=1900"},"modified":"2025-07-26T14:14:29","modified_gmt":"2025-07-26T13:14:29","slug":"running-sccm-sdk-example-code-snippets","status":"publish","type":"page","link":"https:\/\/www.autoitconsulting.com\/site\/sccm-sdk\/fundamentals\/running-sccm-sdk-example-code-snippets\/","title":{"rendered":"Running the ConfigMgr SDK Example Code Snippets"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>This page shows how to easily run the c# example code snippets from the Microsoft Configuration Manager SDK sections on this site. A small Visual Studio C# project was created that can be downloaded and modified to run the required example snippets.<\/p>\n\n\n\n<p>The example Program and Wrapper.cs class (downloads below) is a basic C# console application that can be used to connect to ConfigMgr and run the various example code snippets found on this site. Each example is designed to be as stand-alone as possible. You may have to edit the examples to work in your environment. Related examples may be bundled together in a single file. For example, all of the IResultObject disposal examples are in the file IResultObjectDisposal.cs.<\/p>\n\n\n\n<p>Clone the entire ConfigMgr SDK snippets repo below and use Visual Studio to compile and edit the examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Examples and Downloads<\/h2>\n\n\n\n<p>The examples on this page can be downloaded from the <a href=\"https:\/\/github.com\/AutoItConsulting\/sccm-sdk-snippets\" target=\"_blank\" rel=\"noopener\">GitHub repo<\/a>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/AutoItConsulting\/sccm-sdk-snippets\/blob\/master\/src\/AutoIt.SCCM.SDK.Snippets\/Program.cs\" target=\"_blank\" rel=\"noopener\">Program.cs<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/AutoItConsulting\/sccm-sdk-snippets\/blob\/master\/src\/AutoIt.SCCM.SDK.Snippets\/Wrapper.cs\" target=\"_blank\" rel=\"noopener\">Wrapper.cs<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Wrapper Class<\/h3>\n\n\n\n<p>The wrapper class&nbsp;<strong>Wrapper.cs<\/strong> contains a&nbsp;<strong>Run()<\/strong> method that contains commented out example methods near the comment &#8220;Call snippets&#8221;. Simply uncomment the method you are interested in testing and examine that method to determine if it needs to be customised for your environment.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 0 16px;font-size:0.8em;width:100%;text-align:left;background-color:#1E1E1E;font-style:italic;color:#D4D4D4\"><span style=\"border-bottom:1px solid rgba(234, 191, 191, 0.2)\">C#<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>public void Run()\n{\n    \/\/ Connect to SCCM\n\n    \/\/\n    \/\/ Call snippets - uncomment required snippets.\n    \/\/\n\n    \/\/\n    \/\/ Fundamentals\n    \/\/\n    \/\/IResultObjectExecuteQueryDisposalV1(wqlConnection);\n    \/\/IResultObjectExecuteQueryDisposalV2(wqlConnection);\n    \/\/IResultObjectDisposalOfReturnValue(wqlConnection);\n    \/\/LazyPropertyFromQuery(wqlConnection);\n\n    \/\/ Disconnect from SCCM\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">void<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">Run<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/ Connect to SCCM<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/ Call snippets - uncomment required snippets.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/ Fundamentals<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/IResultObjectExecuteQueryDisposalV1(wqlConnection);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/IResultObjectExecuteQueryDisposalV2(wqlConnection);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/IResultObjectDisposalOfReturnValue(wqlConnection);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/LazyPropertyFromQuery(wqlConnection);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">    \/\/ Disconnect from SCCM<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview This page shows how to easily run the c# example code snippets from the Microsoft Configuration Manager SDK sections on this site. A small Visual Studio C# project was created that can be downloaded and modified to run the required example snippets. The example Program and Wrapper.cs class (downloads below) is a basic C# [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":100234,"parent":1769,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1900","page","type-page","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/pages\/1900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/comments?post=1900"}],"version-history":[{"count":7,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/pages\/1900\/revisions"}],"predecessor-version":[{"id":100253,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/pages\/1900\/revisions\/100253"}],"up":[{"embeddable":true,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/pages\/1769"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/media\/100234"}],"wp:attachment":[{"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/media?parent=1900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}