zoukankan      html  css  js  c++  java
  • ClickOne :添加ClickOnce程序的快捷方式

    代码
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using Microsoft.Win32;
    using IWshRuntimeLibrary;

    namespace Iwp.IwpMain
    {
        
    static class MainClass
        {
            
    /// <summary>
            
    /// 应用程序的主入口点。
            
    /// </summary>
            [STAThread]
            
    static void Main()
            {

                
                
    string startpath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\程序\\旅游ERP系统\\旅行社机票管理系统.appref-ms";

                
    //开机自启动 "C:\Documents and Settings\Administrator\「开始」菜单\程序\旅游ERP系统\旅行社机票管理系统.appref-ms"
                ////RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                
    ////string sRtn = key.GetValue("myprog", "notexist").ToString();
                
    ////if (sRtn == "notexist")
                
    ////{
                
    ////    key.SetValue("myprog", startpath);
                
    ////}
                
    ////else
                
    ////{
                
    ////    if (sRtn != startpath)
                
    ////        key.SetValue("myprog", startpath);
                
    ////}

                
    //创建快捷方式
                WshShell shell = new WshShell();
                IWshShortcut shortcut 
    = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\旅游ERP系统222.lnk");
                shortcut.TargetPath 
    = startpath;
                shortcut.WorkingDirectory 
    = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\程序\\旅游ERP系统";
                shortcut.WindowStyle 
    = 2;
                
    ////shortcut.Arguments = "/p XMAPGL /nologo";  //指向目标运行的参数
                shortcut.Description = "旅游ERP系统";
                shortcut.IconLocation 
    = System.Environment.CurrentDirectory + "\\" + "icon.ico"//System.Environment.SystemDirectory + "\\" + "shell32.dll, 163"; 
                

                shortcut.Save();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(
    false);

                
    //fMain mainfrm = new fMain();
                
    //myform.CustomerForm = mainfrm;

                Boolean createdNew;
                System.Threading.Mutex m 
    = new System.Threading.Mutex(true"myprog"out createdNew);
                
    if (createdNew)
                {
                    Application.Run(
    new Form1());
                    m.ReleaseMutex();
                }
                
    else
                {
                    MessageBox.Show(
    "本程序只允许同时运行一个!");
                }


            }

        }

    需要注意的细节:string startpath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\程序\\旅游ERP系统\\旅行社机票管理系统.appref-ms";

    这里必需在启动pc机器开始>程序中存在的,否则创建快捷方式后指向无效。。。。

    需要的dll :

    /Files/Fooo/Interop.IWshRuntimeLibrary.rar

  • 相关阅读:
    dpdk优化相关 转
    常用的TCP Option
    c10k C10M
    Linux惊群效应详解
    bloomfilter 以及count min sketch
    Squid 搭建正向代理服务器
    Openflow的架构+源码剖析 转载
    Hyperscan与Snort的集成方案
    动态图
    psutil 模块
  • 原文地址:https://www.cnblogs.com/Fooo/p/1689894.html
Copyright © 2011-2022 走看看