首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

用 Visual C# 2005 建立捷徑 (2) - WSH 參考與核心屬性設定

     編輯:關於C語言

加入 WSH 參考

VS2005 Express:右鍵專案 → Add Reference → COM 標籤 → 選取 Windows Script Host Object Model。

加入參考對話框

建立捷徑完整程式碼

using System;
using IWshRuntimeLibrary;

class Program
{
    static void Main(string[] args)
    {
        WshShell shell = new WshShell();
        IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
            Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) +
            "\\" + "Allen's Application.lnk"
        );
        
        shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
        shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
        shortcut.Windowstyle = 1;
        shortcut.Description = "Launch Allen's Application";
        shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
        shortcut.Save();
    }
}

核心屬性詳細說明

TargetPath

捷徑指向目標位置。範例指向本應用程式組件位置。

WorkingDirectory

應用程式工作目錄。使用者未指定目錄時,作為載入/儲存檔案的預設路徑。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved