添加ClickOnce程序的快捷方式
2008-01-29 16:53
351 查看
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.Win32;
using IWshRuntimeLibrary;
namespace MyProgram
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
// 显示Splash窗体
Splash.Show();
DoStartup(args);
// 关闭Splash窗体
Splash.Close();
}
static void DoStartup(string[] args)
{
// 做需要的事情
//开机自启动
string startpath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\程序\\我的程序\\程序快捷方式.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) + "\\客户端.lnk");
//string spath = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
//spath = spath + "\\程序\\我的程序\\程序的快捷方式";
//shortcut.TargetPath = spath;//Application.ExecutablePath;
//shortcut.TargetPath = Application.ExecutablePath;
shortcut.TargetPath = startpath;
//shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
shortcut.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\程序\\我的程序";
shortcut.WindowStyle = 1;
shortcut.Description = "我的程序的快捷方式";
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(mainfrm);
m.ReleaseMutex();
}
else
{
MessageBox.Show("本程序只允许同时运行一个!");
}
}
}
}
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.Win32;
using IWshRuntimeLibrary;
namespace MyProgram
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
// 显示Splash窗体
Splash.Show();
DoStartup(args);
// 关闭Splash窗体
Splash.Close();
}
static void DoStartup(string[] args)
{
// 做需要的事情
//开机自启动
string startpath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\程序\\我的程序\\程序快捷方式.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) + "\\客户端.lnk");
//string spath = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
//spath = spath + "\\程序\\我的程序\\程序的快捷方式";
//shortcut.TargetPath = spath;//Application.ExecutablePath;
//shortcut.TargetPath = Application.ExecutablePath;
shortcut.TargetPath = startpath;
//shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
shortcut.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\程序\\我的程序";
shortcut.WindowStyle = 1;
shortcut.Description = "我的程序的快捷方式";
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(mainfrm);
m.ReleaseMutex();
}
else
{
MessageBox.Show("本程序只允许同时运行一个!");
}
}
}
}
相关文章推荐
- ClickOne :添加ClickOnce程序的快捷方式
- 【转】添加ClickOnce程序的快捷方式 ,自动运行
- winform中为安装程序添加卸载的快捷方式
- android自动添加程序桌面快捷方式
- winform中为安装程序添加卸载的快捷方式
- WIN7开始菜单添加程序快捷方式
- Android 程序桌面快捷方式的检测、添加和删除相关网址
- [ubuntu11.04]给程序添加快捷方式
- InstallShield 为卸载程序添加快捷方式
- 【转】 Ubuntu在启动器添加程序快捷方式
- fedora中将程序的快捷方式添加到“应用程序”中的方法
- Ubuntu下将程序快捷方式添加到启动器
- ubuntu12.04中添加程序启动器及桌面快捷方式
- 在launch启动中添加程序快捷方式
- Android 通过程序添加桌面快捷方式
- 安卓添加程序入口的方式 快速添加快捷方式
- ArchLinux添加程序快捷方式
- 【15.03.13】手动快速在Linux桌面上添加一个程序图标快捷方式
- 通过程序在桌面添加快捷方式
- Android中程序向桌面和Launcher添加快捷方式