明天的明天 永远的永远 未知的一切 我与你一起承担 ??

是非成败转头空 青山依旧在 几度夕阳红 。。。
随笔 - 1277, 文章 - 0, 评论 - 214, 阅读 - 321万
  博客园  :: 首页  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

ClickOne :添加ClickOnce程序的快捷方式

Posted on   且行且思  阅读(810)  评论(1编辑  收藏  举报
复制代码
代码
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

编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示