{"id":114,"date":"2009-09-30T22:24:26","date_gmt":"2009-09-30T22:24:26","guid":{"rendered":"http:\/\/dirk.forbiddendream.be\/?p=114"},"modified":"2016-01-07T10:50:19","modified_gmt":"2016-01-07T10:50:19","slug":"working-with-windows-registry-part-3-reading-from-the-registry","status":"publish","type":"post","link":"https:\/\/dirk.schuermans.me\/?p=114","title":{"rendered":"Working with Windows Registry in VB.NET \u2013 Part 3: Reading from the Registry"},"content":{"rendered":"<p>Welcome to the third part!<\/p>\n<p>In the previous part, part 2, we&#8217;ve learned how to write stuff to the registry. In this part you&#8217;ll learn how to read from it.<\/p>\n<p><!--more--><br \/>\n<a href=\"#summary\">Proceed to summary of this post<\/a><\/p>\n<p>Again, we&#8217;ll need to import the correct namespace and define our variable oRegKey:<\/p>\n<pre name=\"code\" class=\"vb.net\">'Import correct namespace\r\nImports Microsoft.Win32\r\n\r\n'Define RegistryKey within our procedure or function\r\nDim oRegKey as RegistryKey<\/pre>\n<p>After that we need to point our regkey in the direction of our settings:<\/p>\n<pre name=\"code\" class=\"vb.net\">'Set working subkey\r\noRegKey = Registry.LocalMachine.OpenSubKey(\"SOFTWARE\\MyApp\")<\/pre>\n<p>Note that I left the &#8220;True&#8221; out, we&#8217;re only reading stuff in this part anyway.<\/p>\n<p>Once we&#8217;ve done that, we are going to fetch our settings:<\/p>\n<pre name=\"code\" class=\"vb.net\">'Declare variables\r\nDim sVersion, sAuthor, sSerial As String\r\n\r\n'Retrieve settings from Registry\r\nsVersion = oRegKey.GetValue(\"Version\")\r\nsAuthor = oRegKey.GetValue(\"Author\")\r\nsSerial = oRegKey.GetValue(\"Serial\")\r\n\r\n'Close the RegistryKey\r\noRegKey.Close()<\/pre>\n<p>There you go! You now have your settings that you previously stored in the Registry back in your application for further use!<\/p>\n<p><a name=\"summary\"><\/a><br \/>\n<span style=\"color: #ff0000;\"><span style=\"text-decoration: underline;\"><strong>POST SUMMARY<\/strong><\/span><\/span><\/p>\n<pre name=\"code\" class=\"vb.net\">'Import correct namespace\r\nImports Microsoft.Win32\r\n\r\n'Procedure to read stuff from the Registry\r\nPublic Sub fnRead()\r\n\t'Declare variables\r\n\tDim oRegKey as RegistryKey\r\n\tDim sVersion, sAuthor, sSerial As String\r\n\r\n\t'Set the SubKey to work with\r\n\toRegKey = Registry.LocalMachine.OpenSubKey(\"SOFTWARE\\MyApp\")\r\n\r\n\t'Retrieve settings from Registry\r\n\tsVersion = oRegKey.GetValue(\"Version\")\r\n\tsAuthor = oRegKey.GetValue(\"Author\")\r\n\tsSerial = oRegKey.GetValue(\"Serial\")\r\nEnd Sub<\/pre>\n<p><a href=\"http:\/\/dirk.schuermans.me\/?p=144\" target=\"_self\">&#8211; Continue to Part 4<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to the third part! In the previous part, part 2, we&#8217;ve learned how to write stuff to the registry. In this part you&#8217;ll learn how to read from it.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[38,6],"tags":[],"_links":{"self":[{"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/posts\/114"}],"collection":[{"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=114"}],"version-history":[{"count":3,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":785,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions\/785"}],"wp:attachment":[{"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dirk.schuermans.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}