{"id":3388,"date":"2017-12-15T10:08:35","date_gmt":"2017-12-15T02:08:35","guid":{"rendered":"http:\/\/www.bookcard.net\/wordpress\/?p=3388"},"modified":"2018-01-16T16:22:55","modified_gmt":"2018-01-16T08:22:55","slug":"windows_run_web_browser_open_url","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/windows_run_web_browser_open_url\/","title":{"rendered":"Windows\u555f\u52d5\u700f\u89bd\u5668\u4e26\u6253\u958b\u7db2\u9801"},"content":{"rendered":"<figure id=\"attachment_3389\" aria-describedby=\"caption-attachment-3389\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2017\/12\/Windows_Run_Web_Browser_Open_URL.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3389\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2017\/12\/Windows_Run_Web_Browser_Open_URL.jpg\" alt=\"\" width=\"1024\" height=\"768\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2017\/12\/Windows_Run_Web_Browser_Open_URL.jpg 1024w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2017\/12\/Windows_Run_Web_Browser_Open_URL-300x225.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2017\/12\/Windows_Run_Web_Browser_Open_URL-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-3389\" class=\"wp-caption-text\">Windows\u555f\u52d5\u700f\u89bd\u5668\u4e26\u6253\u958b\u7db2\u9801<\/figcaption><\/figure>\n<p>\u555f\u52d5\u700f\u89bd\u5668\u6700\u7c21\u55ae\u7684\u65b9\u6cd5\u662f\u4f7f\u7528ShellExecute(),\u4f46\u7121\u8fd4\u56de\u9032\u7a0b\u53e5\u70b3,\u8981\u95dc\u9589\u700f\u89bd\u5668\u53ea\u80fd\u67e5\u627e\u7a97\u53e3.\u66f4\u597d\u7684\u65b9\u6cd5\u662fCreateProcess()\u555f\u52d5\u700f\u89bd\u5668\u65b0\u9032\u7a0b\u4e26\u6253\u5e36\u7db2\u9801,\u4e26\u8fd4\u56de\u9032\u7a0b\u53e5\u67c4,\u65b9\u4fbf\u95dc\u9589\u700f\u89bd\u5668.<\/p>\n<p>BOOL CreateProcess(LPCTSTR lpApplicationName,\/\/\u57f7\u884c\u6a21\u584a\u540d\u586b\u7a7aNULL\u5373\u53ef<\/p>\n<p>LPTSTR\u00a0 lpCommandLine,\/\/\u547d\u4ee4\u884c\u586b\u201d<a href=\"https:\/\/www.bookcard.net\/wordpress\/windows_default_web_browser_path\/\">\u700f\u89bd\u5668Path<\/a>+\u7a7a\u683c+\u7db2\u9801URL\u201d<\/p>\n<p>LPSECURITY_ATTRIBUTES lpProcessAttributes,\/\/\u9032\u7a0b\u5c6c\u6027\u00a0 LPSECURITY_ATTRIBUTES lpThreadAttributes,\/\/\u7dda\u7a0b\u5c6c\u6027<\/p>\n<p>BOOL bInheritHandles,\u00a0 \/\/\u7e7c\u627f\u9032\u7a0b\u53e5\u67c4false<\/p>\n<p>DWORD dwCreationFlags, \/\/\u5275\u5efa\u6a19\u8a8c\u586bCREATE_NEW_CONSOLE<\/p>\n<p>LPVOID lpEnvironment, \/\/\u9032\u7a0b\u74b0\u5883<\/p>\n<p>LPCTSTR lpCurrentDirectory,\/\/ \u9032\u7a0b\u7684\u5de5\u4f5c\u8def\u5f91\u586bNULL<\/p>\n<p>LPSTARTUPINFO lpStartupInfo, \/\/STARTUPINFO\u7d50\u69cb<\/p>\n<p>LPPROCESS_INFORMATION lpProcessInformation\/\/PROCESS_INFORMATION\u7d50\u69cb<\/p>\n<p>);<\/p>\n<ol>\n<li>\u8981\u6ce8\u610f\u7684\u662f\u547d\u4ee4\u884clpCommandLine:<a href=\"https:\/\/www.bookcard.net\/wordpress\/windows_default_web_browser_path\/\">\u700f\u89bd\u5668Path<\/a>+\u7a7a\u683c+\u7db2\u9801URL<\/li>\n<li>\u547d\u4ee4\u884c\u6700\u597d\u4f7f\u7528\u5bec\u5b57\u7b26Unicode\u5426\u5247\u8def\u5f91\u6709\u6f22\u5b57\u6216\u975eASCII\u78bc\u5247\u7121\u6cd5\u904b\u884c<\/li>\n<li>\u8fd4\u56de\u4e0d\u70bafalse\u5247\u8abf\u7528\u6210\u529f<\/li>\n<li>\u4fdd\u5b58lpProcessInformation\u8fd4\u56de\u700f\u89bd\u5668\u65b0\u9032\u67c4<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>\u4e0b\u9eb5\u7d66\u6253\u958b\u7db2\u9801\u6e90\u4ee3\u78bc,\u4fbf\u65bc<\/p>\n<p>bool Open_Url(char * url,char * browser_Path)<\/p>\n<p>{<\/p>\n<p>int result = 0;<\/p>\n<p>char CommandA[2056];<\/p>\n<p>WCHAR CommandW[2056];<\/p>\n<p>int length;<\/p>\n<p>SECURITY_ATTRIBUTES Security_Attributes_Process;\/\/ \u9032\u7a0b\u5c6c\u6027<\/p>\n<p>SECURITY_ATTRIBUTES Security_Attributes_Thread;\/\/ \u7dda\u7a0b\u5c6c\u6027<\/p>\n<p>STARTUPINFO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Startup_Info;\/\/ \u555f\u52d5\u4fe1\u606f<\/p>\n<p>PROCESS_INFORMATION Process_Information;\/\/\u00a0 \u9032\u7a0b\u4fe1\u606f<\/p>\n<p>strcpy(CommandA,browser_Path);<\/p>\n<p>strcat(CommandA,&#8221; &#8220;);<\/p>\n<p>strcat(CommandA,url);<\/p>\n<p>\/\/ \u8f49\u63dbUNICODE<\/p>\n<p>length = MultiByteToWideChar(CP_ACP, NULL, CommandA, strlen(CommandA), CommandW, sizeof(CommandW));<\/p>\n<p>CommandW[length] = NULL;<\/p>\n<p>\/\/ \u9032\u7a0b\u5c6c\u6027<\/p>\n<p>Security_Attributes_Process.nLength\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = sizeof(SECURITY_ATTRIBUTES);<\/p>\n<p>Security_Attributes_Process.lpSecurityDescriptor = NULL;<\/p>\n<p>Security_Attributes_Process.bInheritHandle\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = true;<\/p>\n<p>\/\/ \u7dda\u7a0b\u5c6c\u6027<\/p>\n<p>Security_Attributes_Thread.nLength\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = sizeof(SECURITY_ATTRIBUTES);<\/p>\n<p>Security_Attributes_Thread.lpSecurityDescriptor\u00a0 = NULL;<\/p>\n<p>Security_Attributes_Thread.bInheritHandle\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = true;<\/p>\n<p>\/\/ \u555f\u52d5\u4fe1\u606f<\/p>\n<p>ZeroMemory( &amp;Startup_Info, sizeof(STARTUPINFO) );<\/p>\n<p>Startup_Info.cb = sizeof(STARTUPINFO);<\/p>\n<p>ZeroMemory( &amp;Process_Information, sizeof(PROCESS_INFORMATION) );<\/p>\n<p>\/\/ \u5275\u5efa\u9032\u7a0b<\/p>\n<p>result = CreateProcessW(NULL,<\/p>\n<p>CommandW,<\/p>\n<p>&amp;Security_Attributes_Process,<\/p>\n<p>&amp;Security_Attributes_Thread,<\/p>\n<p>FALSE,<\/p>\n<p>CREATE_NEW_CONSOLE,<\/p>\n<p>NULL,<\/p>\n<p>NULL,<\/p>\n<p>&amp;Startup_Info,<\/p>\n<p>&amp;Process_Information);<\/p>\n<p>\/\/ \u7372\u53d6\u9032\u7a0b\u53e5\u67c4<\/p>\n<p>if(result != 0)<\/p>\n<p>return true;<\/p>\n<p>else<\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u555f\u52d5\u700f\u89bd\u5668\u6700\u7c21\u55ae\u7684\u65b9\u6cd5\u662f\u4f7f\u7528ShellExecute(),\u4f46\u7121\u8fd4\u56de\u9032\u7a0b\u53e5\u70b3,\u8981\u95dc\u9589\u700f\u89bd\u5668\u53ea\u80fd\u67e5\u627e\u7a97\u53e3.\u66f4\u597d\u7684\u65b9 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/windows_run_web_browser_open_url\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">Windows\u555f\u52d5\u700f\u89bd\u5668\u4e26\u6253\u958b\u7db2\u9801<\/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":[51,6],"tags":[3,8,42],"class_list":["post-3388","post","type-post","status-publish","format-standard","hentry","category-windows","category-network","tag-windows","tag-network","tag-computer","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/comments?post=3388"}],"version-history":[{"count":1,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3388\/revisions"}],"predecessor-version":[{"id":3390,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3388\/revisions\/3390"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=3388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=3388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=3388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}