{"id":2834,"date":"2026-05-26T19:03:15","date_gmt":"2026-05-26T11:03:15","guid":{"rendered":"https:\/\/cocozq.com\/?p=2834"},"modified":"2026-05-26T19:03:15","modified_gmt":"2026-05-26T11:03:15","slug":"tauri-%e5%ba%94%e7%94%a8%e4%b8%ad%e8%b0%83%e7%94%a8%e7%b3%bb%e7%bb%9f%e5%91%bd%e4%bb%a4%e5%bc%b9%e5%87%ba%e9%bb%91%e8%89%b2%e7%aa%97%e5%8f%a3%e7%9a%84%e9%97%ae%e9%a2%98%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/cocozq.com\/?p=2834","title":{"rendered":"Tauri \u5e94\u7528\u4e2d\u8c03\u7528\u7cfb\u7edf\u547d\u4ee4\u5f39\u51fa\u9ed1\u8272\u7a97\u53e3\u7684\u95ee\u9898\u5206\u6790"},"content":{"rendered":"<h1>Tauri \u5e94\u7528\u4e2d\u8c03\u7528\u7cfb\u7edf\u547d\u4ee4\u5f39\u51fa\u9ed1\u8272\u7a97\u53e3\u7684\u95ee\u9898\u5206\u6790<\/h1>\n<h2>\u95ee\u9898\u73b0\u8c61<\/h2>\n<p>\u5728 CocoMarkdown \u8bbe\u7f6e\u754c\u9762\u4e2d\uff0c\u5f00\u542f&#8221;\u5173\u8054 .md \u6587\u4ef6&#8221;\u6216&#8221;\u53f3\u952e\u83dc\u5355&#8221;\u9009\u9879\u65f6\uff0c\u5c4f\u5e55\u4e0a\u4f1a\u5feb\u901f\u95ea\u8fc7\u591a\u4e2a\u9ed1\u8272\u63a7\u5236\u53f0\u7a97\u53e3\u3002<\/p>\n<h2>\u6839\u56e0\u5206\u6790<\/h2>\n<h3>\u76f4\u63a5\u539f\u56e0<\/h3>\n<p>Rust \u4ee3\u7801\u4f7f\u7528 <code>std::process::Command<\/code> \u6216 <code>tokio::process::Command<\/code> \u6267\u884c <code>reg<\/code> \u547d\u4ee4\u64cd\u4f5c Windows \u6ce8\u518c\u8868\u65f6\uff0c<strong>\u9ed8\u8ba4\u884c\u4e3a\u4f1a\u521b\u5efa\u4e00\u4e2a\u53ef\u89c1\u7684\u63a7\u5236\u53f0\u7a97\u53e3<\/strong>\u3002<\/p>\n<p>\u4ee5\u6587\u4ef6\u5173\u8054\u6ce8\u518c\u4e3a\u4f8b\uff0c\u9700\u8981\u8fde\u7eed\u6267\u884c 5 \u6b21 <code>reg add<\/code> \u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-rust line-numbers\">std::process::Command::new(\"reg\")\n    .args([\"add\", key, \"\/v\", val_name, \"\/d\", val_data, \"\/f\"])\n    .output()\n<\/code><\/pre>\n<p>\u6bcf\u6b21\u8c03\u7528\u90fd\u4f1a\u77ed\u6682\u5f39\u51fa\u4e00\u4e2a cmd \u7a97\u53e3\uff0c\u547d\u4ee4\u6267\u884c\u5b8c\u6bd5\u540e\u7a97\u53e3\u81ea\u52a8\u5173\u95ed\uff0c\u7528\u6237\u770b\u5230\u7684\u5c31\u662f\u9ed1\u8272\u7a97\u53e3\u5feb\u901f\u95ea\u73b0\u3002<\/p>\n<h3>\u6df1\u5c42\u539f\u56e0<\/h3>\n<p>Windows \u7cfb\u7edf\u4e2d\uff0c\u8fdb\u7a0b\u521b\u5efa\u65f6\u901a\u8fc7 <code>CreateProcess<\/code> API \u7684 <code>dwCreationFlags<\/code> \u53c2\u6570\u63a7\u5236\u662f\u5426\u663e\u793a\u7a97\u53e3\u3002Rust \u6807\u51c6\u5e93\u548c tokio \u7684 <code>Command<\/code> \u5728 Windows \u4e0a\u9ed8\u8ba4\u4f7f\u7528 <code>0<\/code> \u4f5c\u4e3a\u521b\u5efa\u6807\u5fd7\uff0c\u5373\u4e0d\u8bbe\u7f6e\u4efb\u4f55\u7279\u6b8a\u6807\u5fd7\uff0c\u8fd9\u610f\u5473\u7740\uff1a<\/p>\n<ul>\n<li>\u5f53\u542f\u52a8\u7684\u662f\u63a7\u5236\u53f0\u7a0b\u5e8f\uff08\u5982 <code>reg.exe<\/code>\u3001<code>cmd.exe<\/code>\uff09\u65f6\uff0cWindows \u4f1a\u4e3a\u5176\u5206\u914d\u4e00\u4e2a\u65b0\u7684\u63a7\u5236\u53f0\u7a97\u53e3<\/li>\n<li>\u8be5\u7a97\u53e3\u5728\u8fdb\u7a0b\u5b58\u6d3b\u671f\u95f4\u4e00\u76f4\u53ef\u89c1\uff0c\u8fdb\u7a0b\u9000\u51fa\u540e\u5173\u95ed<\/li>\n<li>\u7531\u4e8e <code>reg add<\/code> \u6267\u884c\u5f88\u5feb\uff08\u6beb\u79d2\u7ea7\uff09\uff0c\u7a97\u53e3\u8868\u73b0\u4e3a&#8221;\u4e00\u95ea\u800c\u8fc7&#8221;<\/li>\n<\/ul>\n<h3>\u5bf9\u6bd4\uff1aLinux\/macOS \u65e0\u6b64\u95ee\u9898<\/h3>\n<p>\u5728 Linux \u548c macOS \u4e0a\uff0c\u5b50\u8fdb\u7a0b\u9ed8\u8ba4\u7ee7\u627f\u7236\u8fdb\u7a0b\u7684\u6807\u51c6\u8f93\u5165\u8f93\u51fa\uff0c\u4e0d\u4f1a\u521b\u5efa\u65b0\u7684\u7ec8\u7aef\u7a97\u53e3\uff0c\u56e0\u6b64\u4e0d\u5b58\u5728\u6b64\u95ee\u9898\u3002\u8fd9\u662f Windows \u5e73\u53f0\u7279\u6709\u7684\u884c\u4e3a\u3002<\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<h3>\u65b9\u6848\uff1a\u8bbe\u7f6e CREATE_NO_WINDOW \u6807\u5fd7<\/h3>\n<p>Windows API \u63d0\u4f9b\u4e86 <code>CREATE_NO_WINDOW<\/code>\uff08\u503c\u4e3a <code>0x08000000<\/code>\uff09\u521b\u5efa\u6807\u5fd7\uff0c\u544a\u77e5\u7cfb\u7edf\u4e0d\u8981\u4e3a\u5b50\u8fdb\u7a0b\u521b\u5efa\u63a7\u5236\u53f0\u7a97\u53e3\u3002<\/p>\n<pre><code class=\"language-rust line-numbers\">#[cfg(target_os = \"windows\")]\nconst CREATE_NO_WINDOW: u32 = 0x08000000;\n\ntokio::process::Command::new(\"reg\")\n    .args([\"add\", key, \"\/v\", val_name, \"\/d\", val_data, \"\/f\"])\n    .creation_flags(CREATE_NO_WINDOW)  \/\/ \u5173\u952e\uff1a\u963b\u6b62\u521b\u5efa\u63a7\u5236\u53f0\u7a97\u53e3\n    .output()\n    .await\n<\/code><\/pre>\n<p><code>creation_flags<\/code> \u65b9\u6cd5\u7531 <code>std::os::windows::process::CommandExt<\/code> trait \u63d0\u4f9b\uff0c<code>tokio::process::Command<\/code> \u5df2\u5185\u7f6e\u652f\u6301\uff0c\u65e0\u9700\u624b\u52a8 import\u3002<\/p>\n<h3>\u4e3a\u4ec0\u4e48\u4e0d\u7528\u5176\u4ed6\u65b9\u6848<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u65b9\u6848<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u7f3a\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>CREATE_NO_WINDOW<\/code><\/td>\n<td>\u76f4\u63a5\u963b\u6b62\u521b\u5efa\u7a97\u53e3<\/td>\n<td>\u65e0<\/td>\n<\/tr>\n<tr>\n<td><code>.stdin(Stdio::null())<\/code><\/td>\n<td>\u91cd\u5b9a\u5411\u6807\u51c6\u8f93\u5165<\/td>\n<td>\u4e0d\u5f71\u54cd\u7a97\u53e3\u521b\u5efa\uff0c\u7a97\u53e3\u4ecd\u4f1a\u5f39\u51fa<\/td>\n<\/tr>\n<tr>\n<td>\u542f\u52a8\u9690\u85cf\u7a97\u53e3\u7684 cmd<\/td>\n<td><code>cmd \/c start \/min reg ...<\/code><\/td>\n<td>\u590d\u6742\u4e14\u4ecd\u6709\u77ed\u6682\u7a97\u53e3<\/td>\n<\/tr>\n<tr>\n<td>\u4f7f\u7528 <code>winreg<\/code> crate<\/td>\n<td>\u76f4\u63a5\u8c03\u7528 Windows Registry API<\/td>\n<td>\u9700\u8981\u989d\u5916\u4f9d\u8d56\uff0c\u529f\u80fd\u7b49\u4ef7<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u9644\u52a0\u4fee\u590d\uff1aUI \u963b\u585e\u95ee\u9898<\/h2>\n<p>\u539f\u59cb\u4ee3\u7801\u8fd8\u5b58\u5728\u53e6\u4e00\u4e2a\u95ee\u9898\uff1a<code>reg<\/code> \u547d\u4ee4\u4f7f\u7528\u540c\u6b65\u7684 <code>std::process::Command::output()<\/code> \u6267\u884c\uff0c\u4f1a\u963b\u585e Tauri \u4e3b\u7ebf\u7a0b\uff0c\u5bfc\u81f4 UI \u51bb\u7ed3\u3002<\/p>\n<p>\u4fee\u590d\u65b9\u5f0f\uff1a\u5c06\u547d\u4ee4\u6539\u4e3a <code>async<\/code>\uff0c\u4f7f\u7528 <code>tokio::process::Command<\/code> \u66ff\u4ee3 <code>std::process::Command<\/code>\uff0c\u4f7f\u6ce8\u518c\u8868\u64cd\u4f5c\u5728\u540e\u53f0\u7ebf\u7a0b\u6c60\u6267\u884c\uff0c\u4e0d\u963b\u585e UI\u3002<\/p>\n<pre><code class=\"language-rust line-numbers\">\/\/ \u4fee\u590d\u524d\uff1a\u540c\u6b65\uff0c\u963b\u585e UI\n#[tauri::command]\nfn register_file_association() -&gt; Result&lt;(), String&gt; {\n    std::process::Command::new(\"reg\")\n        .args([...])\n        .output()  \/\/ \u963b\u585e\u5f53\u524d\u7ebf\u7a0b\n        .map_err(|e| e.to_string())?;\n    Ok(())\n}\n\n\/\/ \u4fee\u590d\u540e\uff1a\u5f02\u6b65\uff0c\u4e0d\u963b\u585e UI\n#[tauri::command]\nasync fn register_file_association() -&gt; Result&lt;(), String&gt; {\n    tokio::process::Command::new(\"reg\")\n        .args([...])\n        .creation_flags(CREATE_NO_WINDOW)  \/\/ \u4e0d\u5f39\u9ed1\u7a97\n        .output()\n        .await  \/\/ \u5f02\u6b65\u7b49\u5f85\uff0c\u4e0d\u963b\u585e UI\n        .map_err(|e| e.to_string())?;\n    Ok(())\n}\n<\/code><\/pre>\n<h2>\u603b\u7ed3<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u95ee\u9898<\/th>\n<th>\u539f\u56e0<\/th>\n<th>\u4fee\u590d<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u9ed1\u8272\u7a97\u53e3\u95ea\u73b0<\/td>\n<td>Windows \u9ed8\u8ba4\u4e3a\u63a7\u5236\u53f0\u7a0b\u5e8f\u521b\u5efa\u53ef\u89c1\u7a97\u53e3<\/td>\n<td>\u6dfb\u52a0 <code>.creation_flags(CREATE_NO_WINDOW)<\/code><\/td>\n<\/tr>\n<tr>\n<td>UI \u963b\u585e\u51bb\u7ed3<\/td>\n<td>\u540c\u6b65\u547d\u4ee4\u963b\u585e Tauri \u4e3b\u7ebf\u7a0b<\/td>\n<td>\u6539\u4e3a <code>async<\/code> + <code>tokio::process::Command<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6b64\u95ee\u9898\u9002\u7528\u4e8e\u6240\u6709\u5728 Tauri\/Electron \u7b49 WebView \u6846\u67b6\u4e2d\u8c03\u7528 Windows \u7cfb\u7edf\u547d\u4ee4\u7684\u573a\u666f\uff0c\u5efa\u8bae\u5bf9\u6240\u6709 <code>reg<\/code>\u3001<code>cmd<\/code>\u3001<code>powershell<\/code> \u7b49\u63a7\u5236\u53f0\u7a0b\u5e8f\u7684\u8c03\u7528\u7edf\u4e00\u6dfb\u52a0 <code>CREATE_NO_WINDOW<\/code> \u6807\u5fd7\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cocozq.com\/zq\/wp-content\/uploads\/2026\/05\/tauri_win_terminal_blink.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tauri \u5e94\u7528\u4e2d\u8c03\u7528\u7cfb\u7edf\u547d\u4ee4\u5f39\u51fa\u9ed1\u8272\u7a97\u53e3\u7684\u95ee\u9898\u5206\u6790 \u95ee\u9898\u73b0\u8c61 \u5728 CocoMarkdown \u8bbe\u7f6e\u754c\u9762\u4e2d\uff0c\u5f00\u542f &hellip; <a href=\"https:\/\/cocozq.com\/?p=2834\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Tauri \u5e94\u7528\u4e2d\u8c03\u7528\u7cfb\u7edf\u547d\u4ee4\u5f39\u51fa\u9ed1\u8272\u7a97\u53e3\u7684\u95ee\u9898\u5206\u6790&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-2834","post","type-post","status-publish","format-standard","hentry","category-22","hfeed"],"_links":{"self":[{"href":"https:\/\/cocozq.com\/index.php?rest_route=\/wp\/v2\/posts\/2834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cocozq.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cocozq.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cocozq.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cocozq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2834"}],"version-history":[{"count":1,"href":"https:\/\/cocozq.com\/index.php?rest_route=\/wp\/v2\/posts\/2834\/revisions"}],"predecessor-version":[{"id":2835,"href":"https:\/\/cocozq.com\/index.php?rest_route=\/wp\/v2\/posts\/2834\/revisions\/2835"}],"wp:attachment":[{"href":"https:\/\/cocozq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cocozq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cocozq.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}