{"id":138,"date":"2014-09-05T15:54:48","date_gmt":"2014-09-05T15:54:48","guid":{"rendered":"http:\/\/www.danieledavi.com\/blog\/?p=138"},"modified":"2014-09-05T15:54:48","modified_gmt":"2014-09-05T15:54:48","slug":"how-to-use-windows-registry-in-your-net-c-application","status":"publish","type":"post","link":"https:\/\/www.danieledavi.com\/blog\/2014\/09\/how-to-use-windows-registry-in-your-net-c-application\/","title":{"rendered":"How to use Windows registry in your .Net C# application"},"content":{"rendered":"<p>In this article I will show how to read and use in your .Net C# application informations stored in\u00a0the Windows registry. First of all let&#8217;s see the easiest way to store some information in the server registry.<\/p>\n<p>You can use the &#8220;regedit&#8221; command to edit the register or you can directly use a register file. Today I&#8217;ll show this option.<\/p>\n<div id=\"attachment_140\" style=\"width: 310px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/www.danieledavi.com\/blog\/wp-content\/uploads\/2014\/09\/csharp-image.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-140\" class=\"size-full wp-image-140\" src=\"http:\/\/www.danieledavi.com\/blog\/wp-content\/uploads\/2014\/09\/csharp-image.png\" alt=\"C Sharp\" width=\"300\" height=\"300\" srcset=\"https:\/\/www.danieledavi.com\/blog\/wp-content\/uploads\/2014\/09\/csharp-image.png 300w, https:\/\/www.danieledavi.com\/blog\/wp-content\/uploads\/2014\/09\/csharp-image-150x150.png 150w, https:\/\/www.danieledavi.com\/blog\/wp-content\/uploads\/2014\/09\/csharp-image-50x50.png 50w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-140\" class=\"wp-caption-text\">C#<\/p><\/div>\n<p>First of all create a file and call it, say, &#8220;myApp1.reg&#8221; where myApp1 it will be the name you want to give to the Registry Key of your app. If you want a different name, change it but be careful and backup you registry before to take any action on the Registry. You&#8217;ll overwrite eventually key with the same name.<\/p>\n<p>Let&#8217;s see now what to write inside our\u00a0&#8220;myApp1.reg&#8221;<\/p>\n<p>Windows Registry Editor Version 5.00<\/p>\n<pre>[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\YourBrand\\myApp1]\r\n\"aPath\"=\"E:\\\\myFooFolder\\\\\"\r\n\"aTimer\"=\"30\"\r\n\"aServer\"=\"localhost\"\r\n\"aVariable\"=\"begood\"\r\n\"whateveryouwant\"=\"desired-value-here\"\r\n<\/pre>\n<p>&#8230; and so on.<\/p>\n<p>You can store any key you want and give the relative value. The string\u00a0on the left part will be also the variable you&#8217;ll use in your application. The right part is the value.<br \/>\nNow save the file and double click on it. Confirm (if you are sure of what you are doing) and take a look on how to retrieve these information in your application.<\/p>\n<p>First of all you have to add the line<\/p>\n<pre>using Microsoft.Win32;<\/pre>\n<p>on the top of your file, before the class declaration.<\/p>\n<p>Second you need to get the registry Key you create before<\/p>\n<pre>private RegistryKey yourAppKey = Registry.LocalMachine.OpenSubKey(\"SOFTWARE\\\\Wow6432Node\\\\YourBrand\\\\myApp1\", false);\r\n<\/pre>\n<p>Third you can create and assign the variables of your application with the value take from the registry<\/p>\n<pre> \r\nprivate string use_aPath;\r\nprivate int use_aTimer;\r\nprivate string use_aServer;\r\nprivate string use_aVariable;\r\nprivate string use_whateveryouwant;\r\n\r\nuse_aPath = yourAppKey.GetValue(\"aPath\").ToString();\r\nuse_aTimer = yourAppKey.GetValue(\"aTimer\").ConvertTo&lt;int&gt;(0);\r\nuse_aServer = yourAppKey.GetValue(\"aServer\").ToString();\r\nuse_aVariable = yourAppKey.GetValue(\"aVariable\").ToString();\r\nuse_whateveryouwant = yourAppKey.GetValue(\"whateveryouwant\").ToString();\r\n<\/pre>\n<p>Et voil\u00e0 from now you have all you variables retrieved from the registry and ready to be used.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article I will show how to read and use in your .Net C# application informations stored in\u00a0the Windows registry. First of all let&#8217;s see the easiest way to store some information in the server registry. You can use the &#8220;regedit&#8221; command to edit the register or you can directly use a register file. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[12],"tags":[43,44,46,42,47,45],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p90hsv-2e","jetpack-related-posts":[{"id":131,"url":"https:\/\/www.danieledavi.com\/blog\/2014\/08\/html-parser-in-classic-asp\/","url_meta":{"origin":138,"position":0},"title":"HTML Parser in Classic ASP","author":"Daniele Dav\u00ec","date":"August 28, 2014","format":false,"excerpt":"Today I'll show you a script written in classic ASP that can use some server vulnerability to provide traffic from an unaware website to another one through another unaware server. It's quite simple, so I'm not going to explain it in details. This malicious code was founded on a server,\u2026","rel":"","context":"In &quot;Classic ASP&quot;","block_context":{"text":"Classic ASP","link":"https:\/\/www.danieledavi.com\/blog\/category\/programming\/classic-asp\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.danieledavi.com\/blog\/wp-content\/uploads\/2014\/08\/AspClassic.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":142,"url":"https:\/\/www.danieledavi.com\/blog\/2014\/09\/how-to-read-a-pop3-server-mail-folder-with-c\/","url_meta":{"origin":138,"position":1},"title":"How to read a Pop3 server mail folder with C#","author":"Daniele Dav\u00ec","date":"September 8, 2014","format":false,"excerpt":"Let's see how to read emails from a pop3 Server. After setting some variables, we'll create a connection to the Pop3 Server and we'll try to autenticate with user and password. After we'll take a bunch of messages and we'll start to iterate some operation per each message. The message\u2026","rel":"","context":"In &quot;.Net C#&quot;","block_context":{"text":".Net C#","link":"https:\/\/www.danieledavi.com\/blog\/category\/programming\/dot-net-c-sharp\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.danieledavi.com\/blog\/wp-content\/uploads\/2014\/09\/csharp-image.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":308,"url":"https:\/\/www.danieledavi.com\/blog\/2017\/08\/android-toast-equivalent-in-ios\/","url_meta":{"origin":138,"position":2},"title":"Android Toast equivalent in iOS","author":"Daniele Dav\u00ec","date":"August 5, 2017","format":false,"excerpt":"If you wonder what the Java Toast equivalent of this iOS Objective C event would be than you are in the right place. Below is a sample of what I have written for iOS and Xamarin.iOS. This behave pretty much the\u00a0same as Alert in Java using a Toast in place\u2026","rel":"","context":"In &quot;.Net C#&quot;","block_context":{"text":".Net C#","link":"https:\/\/www.danieledavi.com\/blog\/category\/programming\/dot-net-c-sharp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":175,"url":"https:\/\/www.danieledavi.com\/blog\/2017\/05\/spam-how-everything-started\/","url_meta":{"origin":138,"position":3},"title":"SPAM: how everything started","author":"Daniele Dav\u00ec","date":"May 24, 2017","format":false,"excerpt":"\u00a0 The year was 1994. The Internet was young and there were a lot of clever people trying to figure out what to do with this new medium and exploring the possibilities that it opened up. In particular, there was a pair of attorneys in Arizona, Laurence Canter and Martha\u2026","rel":"","context":"In &quot;Courses Notes&quot;","block_context":{"text":"Courses Notes","link":"https:\/\/www.danieledavi.com\/blog\/category\/courses-notes\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.danieledavi.com\/blog\/wp-content\/uploads\/2017\/05\/6a00d83452d6c969e200e54f71aa398833-800wi-264x300.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":719,"url":"https:\/\/www.danieledavi.com\/blog\/2021\/02\/happiness-as-an-organisational-performance-metric\/","url_meta":{"origin":138,"position":4},"title":"Happiness as an organisational performance metric","author":"Daniele Dav\u00ec","date":"February 23, 2021","format":false,"excerpt":"Are \u201chappy\u201d workforces more productive?You would be surprised to know that the problem on how to quantify happiness is well known and solved from decades.\u00a0You can measure your \"employee turnover\" or attrition rate and infer happiness.\u00a0You can use a more direct approach, similarly to the way you quantify your customer's\u2026","rel":"","context":"In &quot;Agile&quot;","block_context":{"text":"Agile","link":"https:\/\/www.danieledavi.com\/blog\/category\/agile-2\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":607,"url":"https:\/\/www.danieledavi.com\/blog\/2020\/10\/product-owners-dont-need-to-be-technical-to-be-good\/","url_meta":{"origin":138,"position":5},"title":"Product owners don&#8217;t need to be technical to be good &#8211; part 1","author":"Daniele Dav\u00ec","date":"October 28, 2020","format":false,"excerpt":"Today I want to write about the product owner (PO) or product manager (PM) role and not to provide a definition or list responsibilities but address a specific myth. I am talking about the myth of the existence and the need of a technical PO.","rel":"","context":"In &quot;Agile&quot;","block_context":{"text":"Agile","link":"https:\/\/www.danieledavi.com\/blog\/category\/agile-2\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"amp_validity":null,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/posts\/138"}],"collection":[{"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/comments?post=138"}],"version-history":[{"count":1,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/posts\/138\/revisions"}],"predecessor-version":[{"id":141,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/posts\/138\/revisions\/141"}],"wp:attachment":[{"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/media?parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/categories?post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/tags?post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}