ホームページ
バックエンド開発
C#.Net チュートリアル
C# 純粋なコードによるデスクトップ ショートカット、プログラム メニュー項目の作成、お気に入りへの Web ページの追加の詳細な説明 (図)



C# 純粋なコードによるデスクトップ ショートカット、プログラム メニュー項目の作成、お気に入りへの Web ページの追加の詳細な説明 (図)
c#通过纯代码创建桌面快捷方式、创建程序菜单项、将网页添加到收藏夹
开始菜单》程序菜单项:
添加到收藏夹:
相关函数代码:
public const int SW_SHOWNORMAL = 1; /// <summary> /// 创建快捷方式。 /// </summary> /// <param name="shortcutPath">快捷方式路径。</param> /// <param name="targetPath">目标路径。</param> /// <param name="workingDirectory">工作路径。</param> /// <param name="description">快捷键描述。</param> public static bool CreateShortcut(string shortcutPath, string targetPath, string workingDirectory, string description, string iconLocation = null) { try { CShellLink cShellLink = new CShellLink(); IShellLink iShellLink = (IShellLink)cShellLink; iShellLink.SetDescription(description); iShellLink.SetShowCmd(SW_SHOWNORMAL); iShellLink.SetPath(targetPath); iShellLink.SetWorkingDirectory(workingDirectory); if (!string.IsNullOrEmpty(iconLocation)) { iShellLink.SetIconLocation(iconLocation, 0); } IPersistFile iPersistFile = (IPersistFile)iShellLink; iPersistFile.Save(shortcutPath, false); Marshal.ReleaseComObject(iPersistFile); iPersistFile = null; Marshal.ReleaseComObject(iShellLink); iShellLink = null; Marshal.ReleaseComObject(cShellLink); cShellLink = null; return true; } catch //(System.Exception ex) { return false; } }
ログイン後にコピー
/// <summary> /// 创建桌面快捷方式 /// </summary> /// <param name="targetPath">可执行文件路径</param> /// <param name="description">快捷方式名称</param> /// <param name="iconLocation">快捷方式图标路径</param> /// <param name="workingDirectory">工作路径</param> /// <returns></returns> public static bool CreateDesktopShortcut(string targetPath, string description, string iconLocation = null, string workingDirectory = null) { if (string.IsNullOrEmpty(workingDirectory)) { workingDirectory = Shortcut.GetDeskDir(); } return Shortcut.CreateShortcut(Shortcut.GetDeskDir() + "\\" + description + ".lnk", targetPath, workingDirectory, description, iconLocation); } /// <summary> /// 创建程序菜单快捷方式 /// </summary> /// <param name="targetPath">可执行文件路径</param> /// <param name="description">快捷方式名称</param> /// <param name="menuName">程序菜单中子菜单名称,为空则不创建子菜单</param> /// <param name="iconLocation">快捷方式图标路径</param> /// <param name="workingDirectory">工作路径</param> /// <returns></returns> public static bool CreateProgramsShortcut(string targetPath, string description, string menuName, string iconLocation = null, string workingDirectory = null) { if (string.IsNullOrEmpty(workingDirectory)) { workingDirectory = Shortcut.GetProgramsDir(); } string shortcutPath = Shortcut.GetProgramsDir(); if (!string.IsNullOrEmpty(menuName)) { shortcutPath += "\\" + menuName; if (!System.IO.Directory.Exists(shortcutPath)) { try { System.IO.Directory.CreateDirectory(shortcutPath); } catch //(System.Exception ex) { return false; } } } shortcutPath += "\\" + description + ".lnk"; return Shortcut.CreateShortcut(shortcutPath, targetPath, workingDirectory, description, iconLocation); } /// <summary> /// 将网页添加到收藏夹 /// </summary> /// <param name="url">要添加到收藏夹的网址</param> /// <param name="description">标题</param> /// <param name="folderName">收藏文件夹名称</param> /// <param name="iconLocation">图标文件路径</param> /// <param name="workingDirectory">工作路径</param> /// <returns></returns> public static bool AddFavorites(string url, string description, string folderName, string iconLocation = null, string workingDirectory = null) { if (string.IsNullOrEmpty(workingDirectory)) { workingDirectory = Shortcut.GetProgramsDir(); } string shortcutPath = Shortcut.GetFavoriteDir(); if (!string.IsNullOrEmpty(folderName)) { shortcutPath += "\\" + folderName; if (!System.IO.Directory.Exists(shortcutPath)) { try { System.IO.Directory.CreateDirectory(shortcutPath); } catch //(System.Exception ex) { return false; } } } shortcutPath += "\\" + description + ".lnk"; return Shortcut.CreateShortcut(shortcutPath, url, workingDirectory, description, iconLocation); }
ログイン後にコピー
以上がC# 純粋なコードによるデスクトップ ショートカット、プログラム メニュー項目の作成、お気に入りへの Web ページの追加の詳細な説明 (図)の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事
R.E.P.O.説明されたエネルギー結晶と彼らが何をするか(黄色のクリスタル)
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最高のグラフィック設定
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
アサシンのクリードシャドウズ:シーシェルリドルソリューション
1週間前
By DDD
R.E.P.O.誰も聞こえない場合はオーディオを修正する方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:Myriseのすべてのロックを解除する方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック
Gmailメールのログイン入り口はどこですか?
7444
15


CakePHP チュートリアル
1371
52


Steamのアカウント名の形式は何ですか
76
11


NYTの接続はヒントと回答です
10
6



C# を使用した Active Directory のガイド。ここでは、Active Directory の概要と、C# での動作方法について、構文と例とともに説明します。

C# データ グリッド ビューのガイド。ここでは、SQL データベースまたは Excel ファイルからデータ グリッド ビューをロードおよびエクスポートする方法の例について説明します。
