
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("本程序只允许同时运行一个!");
}
}
}
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 :