【转】添加ClickOnce程序的快捷方式 ,自动运行
2010-04-22 10:58
465 查看
另2篇文章:
http://m.cnblogs.com/23343/1057764.html
标题: 添加ClickOnce程序的快捷方式
- 葵花子 2008-01-29 16:53 阅读:320
- 评论:1 查看评论 | 添加评论 | 返回 ↓
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("本程序只允许同时运行一个!");
}
}
}
}
另一篇:
在ClickOnce应用程序中创建桌面快捷方式
http://www.cnblogs.com/teamleader/articles/1193466.html
http://m.cnblogs.com/23343/1057764.html
标题: 添加ClickOnce程序的快捷方式
- 葵花子 2008-01-29 16:53 阅读:320
- 评论:1 查看评论 | 添加评论 | 返回 ↓
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("本程序只允许同时运行一个!");
}
}
}
}
另一篇:
在ClickOnce应用程序中创建桌面快捷方式
http://www.cnblogs.com/teamleader/articles/1193466.html
相关文章推荐
- android桌面快捷方式添加 删除 更新 自动运行
- 添加ClickOnce程序的快捷方式
- android桌面快捷方式添加 删除 更新 自动运行
- ClickOne :添加ClickOnce程序的快捷方式
- Android 开机自动运行和添加删除桌面快捷方式
- android 快捷方式开发(三)通过程序运行时自动创建
- 设置程序开机运行并添加快捷方式、启用、结束线程
- android桌面快捷方式添加 删除 更新 自动运行
- Android程序首次运行自动创建桌面快捷方式的方法
- android自动添加程序桌面快捷方式
- Android 为程序添加桌面快捷方式
- 【原】给ClickOnce技术添加创建桌面快捷方式
- 将已存在的程序添加快捷方式到任务栏
- Win7旗舰版系统任务栏无法程序锁定不能添加快捷方式图标
- 利用AS3编译器为程序自动添加帧: 方式一:[Frame]元数据标签的应用
- C# 关于开机自动运行程序方式之一
- 添加快捷方式的程序alacarte
- WIN7开始菜单添加程序快捷方式
- ubuntu中将程序的快捷方式添加到“应用程序”中的方法
- Ubuntu下将程序快捷方式添加到启动器