• c# 创建快捷方式


    之前网上找了几个方法,创建快捷方式,到windows 7 下竟然报错,或没有权限,今天经过一番搜索,终于找到一个很简单的方法:

    首先添加以下引用:COM下Windows Script Host Object Model

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using IWshRuntimeLibrary;
    using System.IO; 
    
    
    namespace WindowsFormsTest3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                IWshShell_Class shell = new IWshShell_ClassClass();
                var shortcut = shell.CreateShortcut(System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory) + "\" + new FileInfo(Application.ExecutablePath).Name + ".lnk") as IWshShortcut;
                shortcut.TargetPath = Application.ExecutablePath;
                shortcut.Save();
            }
        }
    }

    创建URL快捷方式

    private bool createShortcut(string url)
            {
                var deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                using (var sw = new StreamWriter(deskDir + "\网上阅卷系统.url"))
                {
                    sw.WriteLine("[InternetShortcut]");
                    sw.WriteLine("URL=" + url);
                    sw.Flush();
                }
    
                return true;
            }
  • 相关阅读:
    【NOI D2T1】量子通信(容斥原理+卡常)
    CF1555D Say No to Palindromes(线段树)
    CF1554B Cobb
    CF1554A Cherry
    【做题笔记】UVA10162 Last Digit
    【做题记录】CF1223D Sequence Sorting
    CF39H
    UVA10763
    题解 AT2361 [AGC012A] AtCoder Group Contest
    このブログについて | About this blog
  • 原文地址:https://www.cnblogs.com/nanfei/p/2963498.html
Copyright © 2020-2023  润新知