﻿{"id":600,"date":"2010-01-11T03:51:00","date_gmt":"2010-01-10T19:51:00","guid":{"rendered":"http:\/\/blog.jixin.ntxz.net\/?p=600"},"modified":"2010-07-30T15:40:40","modified_gmt":"2010-07-30T07:40:40","slug":"vs-%e7%94%a8%e4%bb%a3%e7%a0%81%e6%89%93%e5%bc%80%e5%85%b3%e9%97%ad%e9%98%b2%e7%81%ab%e5%a2%99%e4%be%8b%e5%a4%96%e7%ab%af%e5%8f%a3","status":"publish","type":"post","link":"http:\/\/www.ntxz.net\/?p=600","title":{"rendered":"VS \u7528\u4ee3\u7801\u6253\u5f00\/\u5173\u95ed\u9632\u706b\u5899\u4f8b\u5916\u7aef\u53e3"},"content":{"rendered":"<p>\u65b9\u6cd5\u4e00\u3001<\/p>\n<p>&nbsp;<wbr><\/p>\n<p>\u5728\u9632\u706b\u5899\u4e2d\u82e5\u8bbe\u67d0\u4e2a\u7aef\u53e3\u59828888\u4e3a\u4f8b\u5916\uff0c\u5219\u53ef\u6267\u884c\u4e0b\u5217\u6279\u5904\u7406\u7a0b\u5e8f\uff1a<\/p>\n<p>@echo off<br \/>SET LIST=&#8221;HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters<br \/>SET LIST=%LIST%\\FirewallPolicy\\DomainProfile\\GloballyOpenPorts\\List&#8221;<br \/>reg <font color=#ff0099>add<\/font> %LIST% \/v &#8220;8888:TCP&#8221; \/t REG_SZ \/d &#8220;8888:TCP:*:<font color=#0066ff>Enabled<\/font>:8888&#8243; \/f<br \/>:END<\/p>\n<p>\u5c06\u4e0a\u8ff0\u4ee3\u7801\u4fdd\u5b58\u4e3atest.bat\u6587\u4ef6\uff0c\u5728\u547d\u4ee4\u884c\u4e0b\u8fdb\u5165\u8be5\u6587\u4ef6\u76ee\u5f55\u8f93\u5165test.bat\u6216\u76f4\u63a5\u53cc\u51fb\u8fd0\u884c\u5373\u53ef\u3002<\/p>\n<p>&nbsp;<wbr><\/p>\n<p>\u82e5\u5728\u9632\u706b\u5899\u7684\u4f8b\u5916\u7aef\u53e3\u4e2d\u5220\u96648888\uff0c\u5219\u53ef\u6267\u884c\u4e0b\u5217\u4ee3\u7801\uff1a<\/p>\n<p>@echo off<br \/>SET LIST=&#8221;HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\SharedAccess\\Parameters<br \/>SET LIST=%LIST%\\FirewallPolicy\\DomainProfile\\GloballyOpenPorts\\List&#8221;<br \/>reg <font color=#cc0099>delete<\/font> %LIST% \/v &#8220;8888:TCP&#8221; \/f<br \/>:END<\/p>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u8bf4\u767d\u4e86\u5c31\u662f\u76f4\u63a5\u4fee\u6539\u6ce8\u518c\u8868\u3002<\/p>\n<p>\u82e5\u6211\u4eec\u5728C#\u4ee3\u7801\u4e2d\u6267\u884c\u6279\u5904\u7406\u7a0b\u5e8f\u7684\u8bdd\uff0c\u6211\u4eec\u9700\u8981\u5efa\u7acb\u4e00\u4e2a*.bat\u6587\u4ef6\uff0c\u7136\u540e\u7528Process\u6267\u884cbat\u6587\u4ef6\u5373\u53ef\u3002<\/p>\n<p>\u8fd9\u4e2a\u4ee3\u7801\u6211\u5c31\u4e0d\u5199\u4e86\uff0c\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u66f4\u65b9\u4fbf<img decoding=\"async\" src=\"http:\/\/simg.sinajs.cn\/blog\/images\/face\/001.gif\"><\/p>\n<p>&nbsp;<wbr><\/p>\n<p>\u65b9\u6cd5\u4e8c\u3001<\/p>\n<p>\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u8f93\u5165\u4e0b\u9762\u6307\u4ee4\u5373\u53ef\u8bbe8888\u7aef\u53e3\u4e3a\u4f8b\u5916\uff1a<\/p>\n<p>\u53c2\u89c1MSDN: http:\/\/msdn.microsoft.com\/zh-cn\/office\/cc646023(SQL.105).aspx<\/p>\n<p>@echo off<\/p>\n<p>&nbsp;<wbr>netsh firewall <font color=#ff00ff>set<\/font> portopening protocol = TCP port =&nbsp;<wbr>8888 name = SQLPort mode = ENABLE scope&nbsp;<wbr> = SUBNET profile = CURRENT<\/p>\n<p>:END<\/p>\n<p>\u82e5\u5220\u9664\u4e4b\uff0c\u5219\u6267\u884c\uff1a<\/p>\n<p>@echo off<\/p>\n<p>netsh firewall&nbsp;<wbr><font color=#ff00ff>delete<\/font> portopening protocol = TCP port =&nbsp;<wbr>8888<\/p>\n<p>:END<\/p>\n<p>&nbsp;<wbr><\/p>\n<p>\u4e0b\u9762\u7528\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n<p><font color=#0000ff>using<\/font> System.Diagnostics;<\/p>\n<p><font color=#0000ff>using<\/font> System.IO;<\/p>\n<p><font color=#0000ff>private void<\/font>&nbsp;<wbr>AddPort()<\/p>\n<p>{<\/p>\n<p>&nbsp;<wbr><font color=#3399ff>StringBuilder<\/font> sBuilder = new <font color=#3399ff>StringBuilder<\/font>();<\/p>\n<p>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> sBuilder.AppendLine(&#8220;@echo off&#8221;);<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> sBuilder.AppendLine(&#8220;netsh firewall set portopening protocol = TCP port = 8888 name = SQLPort mode = ENABLE scope&nbsp;<wbr> = SUBNET profile = CURRENT&#8221;);<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> sBuilder.Append(&#8220;:END&#8221;);<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> <font color=#3399ff>Stream<\/font> st = new <font color=#0099ff>FileStream<\/font>((@&#8221;C:\\test.bat&#8221;, <font color=#0099ff>FileMode<\/font>.OpenOrCreate);<\/p>\n<p>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> <font color=#0000ff>using<\/font> (<font color=#0099ff>StreamWriter<\/font> sw = <font color=#0000ff>new<\/font> <font color=#0099ff>StreamWriter<\/font>(st) )<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> {<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> sw.Write(sBuilder.ToString());<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> sw.Close();<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> st.Dispose();<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> st.Close();<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> }<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> <font color=#0099ff>Process<\/font> ps = <font color=#0000ff>new<\/font> <font color=#0099ff>Process<\/font>();<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> <font color=#0099ff>ProcessStartInfo<\/font> psi = <font color=#0000ff>new<\/font> <font color=#0099ff>ProcessStartInfo<\/font>(@&#8221;C:\\test.bat&#8221;);<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> psi.UseShellExecute = <font color=#0000ff>false<\/font>;<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> psi.CreateNoWindow = <font color=#0000ff>true<\/font>;<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> ps.StartInfo = psi;<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> ps.Start();<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> <font color=#0000ff>while<\/font> (ps.HasExited == <font color=#0000ff>false<\/font>)<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> { }<br \/>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> System.IO.<font color=#0099ff>File<\/font>.Delete(@&#8221;C:\\port.bat&#8221;);<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65b9\u6cd5\u4e00\u3001 &nbsp; \u5728\u9632\u706b\u5899\u4e2d\u82e5\u8bbe\u67d0\u4e2a\u7aef\u53e3\u59828888\u4e3a\u4f8b\u5916\uff0c\u5219\u53ef\u6267\u884c\u4e0b\u5217\u6279\u5904\u7406\u7a0b\u5e8f\uff1a @echo offS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,8],"tags":[],"class_list":["post-600","post","type-post","status-publish","format-standard","hentry","category-1","category-oldblog"],"views":495,"_links":{"self":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=600"}],"version-history":[{"count":1,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/600\/revisions"}],"predecessor-version":[{"id":791,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=\/wp\/v2\/posts\/600\/revisions\/791"}],"wp:attachment":[{"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=600"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ntxz.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}