.net 自定义快捷菜单
2010-09-10 14:39
211 查看
windows.script host object model
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using IWshRuntimeLibrary;
using System.IO;
namespace SunTeckIPC
{
[RunInstaller(true)]
public partial class MyInstall : Installer
{
public MyInstall()
{
InitializeComponent();
}
public override void Install(System.Collections.IDictionary stateSaver)
{
try
{
base.Install(stateSaver);
System.Reflection.Assembly Asm = System.Reflection.Assembly.GetExecutingAssembly();//获取当前程序集信息
System.IO.FileInfo fileinfo = new System.IO.FileInfo(Asm.Location);//获取当前程序集位置
string dbpath = fileinfo.DirectoryName;//获取文件夹名称
string name = fileinfo.Name;//获取文件名称
//去掉后缀
if (name.ToUpper().Contains(".EXE"))
{
name = name.ToUpper().Replace(".EXE", "");
}
//在桌面创建快捷方式
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "//" + name + ".lnk"
);
shortcut.TargetPath = Asm.Location;//目标
shortcut.WorkingDirectory = dbpath;//工作文件夹
shortcut.WindowStyle = 1;//窗体的样式:1为默认,2为最大化,3为最小化
shortcut.Description = "Viss 视频监控";//快捷方式的描述
shortcut.IconLocation = Asm.Location;//图标
shortcut.Save();
//在程序菜单中创建文件夹
if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//" + name))
{
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//" + name);
}
//在程序菜单中创建快捷方式
IWshShortcut shortcut2 = (IWshShortcut)shell.CreateShortcut(
Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//" + name + "//" + name + ".lnk"
);
shortcut2.TargetPath = Asm.Location;
shortcut2.WorkingDirectory = dbpath;
shortcut2.WindowStyle = 1;
shortcut2.Description = "Viss" + "-" + name;
shortcut2.IconLocation = Asm.Location;
shortcut2.Save();
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
public override void Uninstall(System.Collections.IDictionary savedState)
{
base.Uninstall(savedState);
//卸载程序的时候将两个快捷方式删除
System.Reflection.Assembly Asm = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.FileInfo fileinfo = new System.IO.FileInfo(Asm.Location);
string name = fileinfo.Name;
if (name.ToUpper().Contains(".EXE"))
{
name = name.ToUpper().Replace(".EXE", "");
}
if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//" + name))
{
if (Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//").Length > 1)
{
Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//" + name + "//", true);
}
else
{
Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//", true);
}
}
if (System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "//" + name + ".lnk"))
{
System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "//" + name + ".lnk");
}
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using IWshRuntimeLibrary;
using System.IO;
namespace SunTeckIPC
{
[RunInstaller(true)]
public partial class MyInstall : Installer
{
public MyInstall()
{
InitializeComponent();
}
public override void Install(System.Collections.IDictionary stateSaver)
{
try
{
base.Install(stateSaver);
System.Reflection.Assembly Asm = System.Reflection.Assembly.GetExecutingAssembly();//获取当前程序集信息
System.IO.FileInfo fileinfo = new System.IO.FileInfo(Asm.Location);//获取当前程序集位置
string dbpath = fileinfo.DirectoryName;//获取文件夹名称
string name = fileinfo.Name;//获取文件名称
//去掉后缀
if (name.ToUpper().Contains(".EXE"))
{
name = name.ToUpper().Replace(".EXE", "");
}
//在桌面创建快捷方式
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "//" + name + ".lnk"
);
shortcut.TargetPath = Asm.Location;//目标
shortcut.WorkingDirectory = dbpath;//工作文件夹
shortcut.WindowStyle = 1;//窗体的样式:1为默认,2为最大化,3为最小化
shortcut.Description = "Viss 视频监控";//快捷方式的描述
shortcut.IconLocation = Asm.Location;//图标
shortcut.Save();
//在程序菜单中创建文件夹
if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//" + name))
{
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//" + name);
}
//在程序菜单中创建快捷方式
IWshShortcut shortcut2 = (IWshShortcut)shell.CreateShortcut(
Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//" + name + "//" + name + ".lnk"
);
shortcut2.TargetPath = Asm.Location;
shortcut2.WorkingDirectory = dbpath;
shortcut2.WindowStyle = 1;
shortcut2.Description = "Viss" + "-" + name;
shortcut2.IconLocation = Asm.Location;
shortcut2.Save();
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
public override void Uninstall(System.Collections.IDictionary savedState)
{
base.Uninstall(savedState);
//卸载程序的时候将两个快捷方式删除
System.Reflection.Assembly Asm = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.FileInfo fileinfo = new System.IO.FileInfo(Asm.Location);
string name = fileinfo.Name;
if (name.ToUpper().Contains(".EXE"))
{
name = name.ToUpper().Replace(".EXE", "");
}
if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//" + name))
{
if (Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//").Length > 1)
{
Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//" + name + "//", true);
}
else
{
Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "//Viss//", true);
}
}
if (System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "//" + name + ".lnk"))
{
System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "//" + name + ".lnk");
}
}
}
}
相关文章推荐
- 改进uboot,添加自定义快捷菜单
- 改进uboot,添加自定义快捷菜单
- .net 开发微信公众平台(五)-----自定义菜单
- .NET微信公众号开发之创建自定义菜单
- 配置Info.plist (设置状态栏样式、自定义定位时系统弹出的提示语、配置3DTouch应用快捷菜单)
- #AOS应用基础平台# 增加了用户自定义快捷菜单在平铺布局下的用户自定义排序管理
- 模仿快捷分享、从下往上弹出窗口,自定义分享菜单
- 在.Net如何制作自定义的快捷方式(转)
- #AOS应用基础平台# 实现了在用户权限范围内自定义的快捷菜单的导航展示
- c#+Winform实现自定义的“复制、粘贴”右键快捷菜单,多个控件共享使用一个右键菜单。
- .NET微信公众号开发-3.0查询自定义菜单
- c#+Winform实现自定义的“复制、粘贴”右键快捷菜单,多个控件共享使用一个右键菜单
- .NET开发微信公众号之创建自定义菜单
- .NET微信公众号开发-2.0创建自定义菜单
- .NET 自定义注释格式&快捷注释宏
- .NET基础之自定义泛型
- RichEditBox 使用自定义菜单
- php 微信3 自定义菜单
- 使用OptionMenu在屏幕中自定义自己的菜单
- flex 自定义右键菜单