{"id":20,"date":"2019-12-18T17:25:00","date_gmt":"2019-12-18T17:25:00","guid":{"rendered":"https:\/\/sunnydays.info\/?p=30"},"modified":"2021-02-20T15:57:31","modified_gmt":"2021-02-20T07:57:31","slug":"c%e8%ae%be%e7%bd%ae%e5%bc%80%e6%9c%ba%e5%90%af%e5%8a%a8%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/sunnydays.info\/?p=20","title":{"rendered":"C#\u8bbe\u7f6e\u5f00\u673a\u542f\u52a8\u7a0b\u5e8f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5c1d\u8bd5<a href=\"https:\/\/www.cnblogs.com\/daban\/archive\/2012\/10\/26\/2740583.html\">\u53c2\u8003\u4e00\u7bc7\u6587\u7ae0<\/a>\u6765\u7ed9\u81ea\u5df1\u7684app\u6dfb\u52a0\u5f00\u673a\u542f\u52a8\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u53c2\u8003\u7684\u4ee3\u7801\u4f1a\u9047\u5230\u6ce8\u518c\u8868\u6743\u9650\u7684\u95ee\u9898\uff0c\u7a0b\u5e8f\u8c03\u7528\u8c03\u7528\u5f00\u673a\u542f\u52a8\u7684\u65f6\u5019\u4f1a\u63d0\u793a\uff1a\u201c\u5bf9\u6ce8\u518c\u8868\u9879\u201cHKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\u201d\u7684\u8bbf\u95ee\u88ab\u62d2\u7edd\u3002 \u201d\u641c\u7d22\u4e86\u4e00\u4e0b\uff0c\u4e3b\u8981\u7684\u539f\u56e0\u662f\u8bbf\u95ee HKEY_LOCAL_MACHINE \u8fd9\u4e00\u6ce8\u518c\u8868\u5206\u652f\u9700\u8981\u7ba1\u7406\u5458\u6743\u9650\u3002\u4e0d\u60f3\u4e00\u4e2a\u7b80\u5355\u7684app\u53bb\u7533\u8bf7\u6ce8\u518c\u8868\u6743\u9650\uff0c\u8bd5\u4e86\u4e00\u4e0b\u53ef\u4ee5\u4f7f\u7528HKEY_CURRENT_USER \u8fd9\u4e00\u5206\u652f\u6765\u8fbe\u5230\u540c\u6837\u7684\u5f00\u673a\u542f\u52a8\u7684\u6548\u679c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>private void \u5f00\u673a\u542f\u52a8ToolStripMenuItem_Click(object sender, EventArgs e)\n{\n            if (\u5f00\u673a\u542f\u52a8ToolStripMenuItem.Checked)\n            {\n                \u5f00\u673a\u542f\u52a8ToolStripMenuItem.Checked = false;\n                \/\/ MessageBox.Show(\"\u6ca1\u6709\u9009\u4e2d\");\n                \/\/\u83b7\u53d6\u7a0b\u5e8f\u6267\u884c\u8def\u5f84..\n                string starupPath = Application.ExecutablePath;\n                \/\/class Micosoft.Win32.RegistryKey. \u8868\u793aWindow\u6ce8\u518c\u8868\u4e2d\u9879\u7ea7\u8282\u70b9,\u6b64\u7c7b\u662f\u6ce8\u518c\u8868\u88c5.\n                RegistryKey loca = Registry.CurrentUser;\n                RegistryKey run = loca.CreateSubKey(@\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\");\n\n                try\n                {\n                    \/\/SetValue:\u5b58\u50a8\u503c\u7684\u540d\u79f0\n                    run.DeleteValue(\"proxydisable\");\n                    MessageBox.Show(\"\u5df2\u505c\u6b62\u5f00\u673a\u8fd0\u884c!\", \"\u63d0\u793a\", MessageBoxButtons.OK, MessageBoxIcon.Information);\n                    loca.Close();\n                }\n                catch (Exception ee)\n                {\n                    MessageBox.Show(ee.Message.ToString(), \"\u63d0\u793a\", MessageBoxButtons.OK, MessageBoxIcon.Error);\n                }\n            }\n            else\n            {\n                \u5f00\u673a\u542f\u52a8ToolStripMenuItem.Checked = true;\n                \/\/\u83b7\u53d6\u7a0b\u5e8f\u6267\u884c\u8def\u5f84..\n                string starupPath = Application.ExecutablePath;\n                \/\/class Micosoft.Win32.RegistryKey. \u8868\u793aWindow\u6ce8\u518c\u8868\u4e2d\u9879\u7ea7\u8282\u70b9,\u6b64\u7c7b\u662f\u6ce8\u518c\u8868\u88c5.\n                RegistryKey loca = Registry.CurrentUser;\n                RegistryKey run = loca.CreateSubKey(@\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\");\n\n                try\n                {\n                    \/\/SetValue:\u5b58\u50a8\u503c\u7684\u540d\u79f0\n                    run.SetValue(\"proxydisable\", starupPath);\n                    MessageBox.Show(\"\u5df2\u542f\u7528\u5f00\u673a\u8fd0\u884c!\", \"\u63d0\u793a\", MessageBoxButtons.OK, MessageBoxIcon.Information);\n                    loca.Close();\n                }\n                catch (Exception ee)\n                {\n                    MessageBox.Show(ee.Message.ToString(), \"\u63d0\u793a\", MessageBoxButtons.OK, MessageBoxIcon.Error);\n                }\n            }\n        }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c1d\u8bd5\u53c2\u8003\u4e00\u7bc7\u6587\u7ae0\u6765\u7ed9\u81ea\u5df1\u7684app\u6dfb\u52a0\u5f00\u673a\u542f\u52a8\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u53c2\u8003\u7684\u4ee3\u7801\u4f1a\u9047\u5230\u6ce8\u518c\u8868\u6743\u9650\u7684\u95ee\u9898\uff0c\u7a0b\u5e8f\u8c03\u7528\u8c03\u7528\u5f00\u673a\u542f\u52a8 &hellip; <a href=\"https:\/\/sunnydays.info\/?p=20\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">C#\u8bbe\u7f6e\u5f00\u673a\u542f\u52a8\u7a0b\u5e8f<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[9,10],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-3","tag-c","tag-10"],"_links":{"self":[{"href":"https:\/\/sunnydays.info\/index.php?rest_route=\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sunnydays.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sunnydays.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sunnydays.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sunnydays.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20"}],"version-history":[{"count":1,"href":"https:\/\/sunnydays.info\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":61,"href":"https:\/\/sunnydays.info\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions\/61"}],"wp:attachment":[{"href":"https:\/\/sunnydays.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sunnydays.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sunnydays.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}