日韩欧美人妻无码精品白浆,夜夜嗨AV免费入口,国产欧美官网在线看,高校回应聋哑女生因长相完美被质疑

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

在網(wǎng)頁上調(diào)起本機C#程序

freeflydom
2024年11月15日 8:47 本文熱度 1485

前言#

網(wǎng)頁調(diào)起電腦程序是經(jīng)常用到的場景,比如百度網(wǎng)盤下載,加入 QQ 群之類的

注冊表操作#

在 Windows 上實現(xiàn)就是通過注冊表,將 Scheme 和對應的程序添加進去。其他系統(tǒng)暫時沒需要就還沒研究,估計也是類似的。

需要配置一下 SchemePrefix ,本文例子中是 demo

在網(wǎng)頁上使用 demo:// 開頭的鏈接就可以喚起本機的程序了~

using System.Diagnostics;
using System.Web;
using Microsoft.Win32;
const string AppName = "DemoApp";
const string SchemePrefix = "demo";
// 初始化注冊表
void InitReg() {
    if (!OperatingSystem.IsWindows()) return;
    var path1 = AppName;
    var path2 = $@"{path1}\shell\open\command";
    // 設置協(xié)議名稱
    var key1 = Registry.ClassesRoot.OpenSubKey(path1, true);
    if (key1 == null) {
        key1 = Registry.ClassesRoot.CreateSubKey(path1);
    }
    key1.SetValue("URL Protocol", "");
    key1.SetValue(null, $"URL:{SchemePrefix}");
    var key2 = Registry.ClassesRoot.OpenSubKey(path2, true);
    if (key2 == null) {
        key2 = Registry.ClassesRoot.CreateSubKey(path2);
    }
    var exePath = Environment.ProcessPath ?? "";
    key2.SetValue(null, $"\"{exePath}\" \"%1\"");
}

參數(shù)解析#

因為是隨手寫的小工具,我也沒有用命令行解析的庫

如果用第三方庫代碼會更優(yōu)雅

這里就做了兩個命令,一個 install 另一個 open

手動執(zhí)行 install 會在注冊表里添加配置,之后這個程序文件就不要移動了,后續(xù)網(wǎng)頁調(diào)起需要執(zhí)行這個程序。

open 命令是網(wǎng)頁調(diào)起時執(zhí)行的,注意命令參數(shù)里的字符需要 URL 轉(zhuǎn)義。

string action = "", value = "";
string[] cmdArgs = Environment.GetCommandLineArgs();
if (cmdArgs.Length > 1) {
    var arg = cmdArgs[1];
    Console.WriteLine($"cmd args: {arg}");
    if (arg.StartsWith($"{SchemePrefix}://")) {
        arg = arg.Replace($"{SchemePrefix}://", "");
    }
    if (arg.EndsWith("/")) {
        arg = arg.Substring(0, arg.Length - 1);
    }
    var split = arg.Split("http://");
    action = split[0];
    value = split.Length > 1 ? split[1] : "";
    Console.WriteLine($"action: {action}, value: {value}");
}
switch (action) {
    case "install":
        Console.WriteLine("init reg...");
        InitReg();
        Console.WriteLine("init reg finished.");
        break;
    case "open":
        var path = HttpUtility.UrlDecode(value);
        Console.WriteLine($"open file/dir: {path}");
        if (OperatingSystem.IsWindows())
            Process.Start($"C:\\Windows\\explorer.exe", path);
        if (OperatingSystem.IsLinux())
            Process.Start("xdg-open", path);
        break;
    default:
        Console.WriteLine("不知道做啥~");
        break;
}

參考資料#

轉(zhuǎn)自https://www.cnblogs.com/deali/p/18546412


該文章在 2024/11/15 8:49:14 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務費用、相關(guān)報表等業(yè)務管理,結(jié)合碼頭的業(yè)務特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved