{"id":3323,"date":"2014-03-20T10:41:28","date_gmt":"2014-03-20T01:41:28","guid":{"rendered":"http:\/\/auctionpro.co.kr\/?p=3323"},"modified":"2021-07-07T10:32:01","modified_gmt":"2021-07-07T01:32:01","slug":"c-registry-%eb%a9%94%ec%84%9c%eb%93%9c","status":"publish","type":"post","link":"https:\/\/www.auctionpro.co.kr\/?p=3323","title":{"rendered":"C# Registry  \uba54\uc11c\ub4dc"},"content":{"rendered":"<p>\uc18c\uc2a4<\/p>\n<pre class=\"lang:c# decode:true \">public static void RegistrySet() { \/\/ \/\/ This code example produces output similar to the following: \/\/ \/\/NoSuchName: Return this default if NoSuchName does not exist. \/\/(Default): 5280 \/\/TestLong: 12345678901234 \/\/TestArray(0): One \/\/TestArray(1): Two \/\/TestArray(2): Three \/\/TestExpand: My path: %path% \/\/TestExpand2: My path: D:\\Program Files\\Microsoft.NET\\\u2026 \/\/ \/\/Use the registry editor to examine the key. \/\/Press the Enter key to delete the key\r\n\r\n\/\/ The name of the key must include a valid root.\r\nconst string userRoot = \"HKEY_CURRENT_USER\";\r\nconst string subkey = \"RegistrySetValueExample\";\r\nconst string keyName = userRoot + \"\\\\\" + subkey;\r\n\r\n\/\/ An int value can be stored without specifying the\r\n\/\/ registry data type, but long values will be stored\r\n\/\/ as strings unless you specify the type. Note that\r\n\/\/ the int is stored in the default name\/value\r\n\/\/ pair.\r\nRegistry.SetValue(keyName, \"\", 5280);\r\nRegistry.SetValue(keyName, \"TestLong\", 12345678901234,\r\nRegistryValueKind.QWord);\r\n\r\n\/\/ Strings with expandable environment variables are\r\n\/\/ stored as ordinary strings unless you specify the\r\n\/\/ data type.\r\nRegistry.SetValue(keyName, \"TestExpand\", \"My path: %path%\");\r\nRegistry.SetValue(keyName, \"TestExpand2\", \"My path: %path%\",\r\nRegistryValueKind.ExpandString);\r\n\r\n\/\/ Arrays of strings are stored automatically as\r\n\/\/ MultiString. Similarly, arrays of Byte are stored\r\n\/\/ automatically as Binary.\r\nstring[] strings = { \"One\", \"Two\", \"Three\" };\r\nRegistry.SetValue(keyName, \"TestArray\", strings);\r\n\r\n\/\/ Your default value is returned if the name\/value pair\r\n\/\/ does not exist.\r\nstring noSuch = (string)Registry.GetValue(keyName,\r\n\"NoSuchName\",\r\n\"Return this default if NoSuchName does not exist.\");\r\nConsole.WriteLine(\"\\r\\nNoSuchName: {0}\", noSuch);\r\n\r\n\/\/ Retrieve the int and long values, specifying\r\n\/\/ numeric default values in case the name\/value pairs\r\n\/\/ do not exist. The int value is retrieved from the\r\n\/\/ default (nameless) name\/value pair for the key.\r\nint tInteger = (int)Registry.GetValue(keyName, \"\", -1);\r\nConsole.WriteLine(\"(Default): {0}\", tInteger);\r\nlong tLong = (long)Registry.GetValue(keyName, \"TestLong\",\r\nlong.MinValue);\r\nConsole.WriteLine(\"TestLong: {0}\", tLong);\r\n\r\n\/\/ When retrieving a MultiString value, you can specify\r\n\/\/ an array for the default return value.\r\nstring[] tArray = (string[])Registry.GetValue(keyName,\r\n\"TestArray\",\r\nnew string[] { \"Default if TestArray does not exist.\" });\r\nfor (int i = 0; i &lt; tArray.Length; i++)\r\n{\r\nConsole.WriteLine(\"TestArray({0}): {1}\", i, tArray[i]);\r\n}\r\n\r\n\/\/ A string with embedded environment variables is not\r\n\/\/ expanded if it was stored as an ordinary string.\r\nstring tExpand = (string)Registry.GetValue(keyName,\r\n\"TestExpand\",\r\n\"Default if TestExpand does not exist.\");\r\nConsole.WriteLine(\"TestExpand: {0}\", tExpand);\r\n\r\n\/\/ A string stored as ExpandString is expanded.\r\nstring tExpand2 = (string)Registry.GetValue(keyName,\r\n\"TestExpand2\",\r\n\"Default if TestExpand2 does not exist.\");\r\nConsole.WriteLine(\"TestExpand2: {0}\u2026\",\r\ntExpand2.Substring(0, 40));\r\n\r\nConsole.WriteLine(\"\\r\\nUse the registry editor to examine the key.\");\r\nConsole.WriteLine(\"Press the Enter key to delete the key.\");\r\nConsole.ReadLine();\r\nRegistry.CurrentUser.DeleteSubKey(subkey);\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>\uc18c\uc2a4 public static void RegistrySet() { \/\/ \/\/ This code example produces output similar to the following: \/\/ \/\/NoSuchName: Return this default if NoSuchName does <a class=\"mh-excerpt-more\" href=\"https:\/\/www.auctionpro.co.kr\/?p=3323\" title=\"C# Registry  \uba54\uc11c\ub4dc\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10],"tags":[],"class_list":["post-3323","post","type-post","status-publish","format-standard","hentry","category-devc"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/3323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3323"}],"version-history":[{"count":0,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/3323\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}