【原】给ClickOnce技术添加创建桌面快捷方式

参考文献:

http://m.cnblogs.com/14104/1314213.html

 

Program.cs 代码

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;

namespace TestClickOnce
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {   
            bool bCreatedNew;
            Mutex m = new Mutex(false, "TestClickOnceClientName", out bCreatedNew);

            if (bCreatedNew)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
               
            }
            else
            {
                               //MessageBox.Show("程序已经运行,\n\n原因分析:\n\t 1、查看任务栏是否已有窗口存在?\n\t 2、查看任务栏右边是否有一个红色小图标, 可单击图标打开原窗口!", "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            CreateDesktopShortCut();
        }


        private static void CreateDesktopShortCut()
        {

            string path = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
            if (!path.EndsWith("\\"))
            {
                path += "\\";
            }
            path += @"程序\我的程序名称";
            if (System.IO.Directory.Exists(path))
            {
                string desktop = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                if (!desktop.EndsWith("\\"))
                {
                    desktop += "\\";
                }
                foreach (String file in System.IO.Directory.GetFiles(path))
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(file);
                    if (!System.IO.File.Exists(desktop + fi.Name))
                    {
                        fi.CopyTo(desktop + fi.Name);
                    }
                }
            }
        }


    }
}

 

当使用ClickOnce 安装 程序后, 当关闭窗口时,会自动创建桌面快捷方式。

 

posted @ 2010-04-22 10:54  上善若水-water  Views(2171)  Comments(1)    收藏  举报