代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
创建快捷方式
作者:
asion
/ 发布于
2011/4/26
/
781
<div><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> System.Runtime.InteropServices;</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">互动服务 </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> IWshRuntimeLibrary; </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> System; </span><span style="color: rgb(0,0,255)">namespace</span><span style="color: rgb(0,0,0)"> myMethod { </span><span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">class</span><span style="color: rgb(0,0,0)"> CreateLink { </span><span style="color: rgb(0,128,0)">/*</span><span style="color: rgb(0,128,0)"> 1.首先要添加引用. * 选择 COM 选项卡并选择 Windows Script Host Object Model * * 2.引用命名空间 * using System.Runtime.InteropServices;//互动服务 * using IWshRuntimeLibrary; * * 3.创建快捷方式(注释中有详细说明) </span><span style="color: rgb(0,128,0)">*/</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><summary></span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> 创建快捷方式方法的参数为:快捷方式名 + 描述 + 参数+ 自定义图标 +快捷键 </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"></summary></span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><param name="strLINKpath"></span><span style="color: rgb(0,128,0)">输入要在何处创建快递方式。默认为系统桌面。</span><span style="color: rgb(128,128,128)"></param></span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><param name="strAPPname"></span><span style="color: rgb(0,128,0)">快捷方式的名称。</span><span style="color: rgb(128,128,128)"></param></span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><param name="intStyle"></span><span style="color: rgb(0,128,0)">目标应用程序窗口类型(1.Normal window普通窗口,3.Maximized最大化窗口,7.Minimized最小化)</span><span style="color: rgb(128,128,128)"></param></span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><param name="strAppDescription"></span><span style="color: rgb(0,128,0)">快捷方式的描述 </span><span style="color: rgb(128,128,128)"></param></span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><param name="strICONpath"></span><span style="color: rgb(0,128,0)">自定义快捷方式图标的路径,默认为源文件的图标。 </span><span style="color: rgb(128,128,128)"></param></span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><param name="strArguments"></span><span style="color: rgb(0,128,0)">设置应用程序的启动参数,如"/xx /xx"</span><span style="color: rgb(128,128,128)"></param></span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><param name="strHotKey"></span><span style="color: rgb(0,128,0)">设置快捷键 如:"CTRL+ALT+S"</span><span style="color: rgb(128,128,128)"></param></span><span style="color: rgb(128,128,128)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">static</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> myMethod_CreateLINK(</span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> strLINKpath, </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> strAPPname , </span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)"> intStyle, </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> strAppDescription , </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> strICONpath, </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> strArguments, </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> strHotKey) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">实例化WshShell对象 </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> WshShell shell </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> WshShell(); </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">通过该对象的 CreateShortcut 方法来创建 IWshShortcut 接口的实例对象 </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> IWshShortcut shortcut; </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> ( strLINKpath </span><span style="color: rgb(0,0,0)">==</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">""</span><span style="color: rgb(0,0,0)"> ) { shortcut </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> (IWshShortcut)shell.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Desktop) </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">\\</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> strAPPname </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">.lnk</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); } </span><span style="color: rgb(0,0,255)">else</span><span style="color: rgb(0,0,0)"> { shortcut </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> (IWshShortcut)shell.CreateShortcut(strLINKpath </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">\\</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> strAPPname </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">.lnk</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); } </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">设置快捷方式的目标所在的位置(源程序完整路径) </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> shortcut.TargetPath </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> System.Reflection.Assembly.GetExecutingAssembly().Location; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">应用程序的工作目录 </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。 </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> shortcut.WorkingDirectory </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> System.Environment.CurrentDirectory; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">目标应用程序窗口类型(1.Normal window普通窗口,3.Maximized最大化窗口,7.Minimized最小化) </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">switch</span><span style="color: rgb(0,0,0)"> ( intStyle ) { </span><span style="color: rgb(0,0,255)">case</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">1</span><span style="color: rgb(0,0,0)">: shortcut.WindowStyle </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">1</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">break</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">case</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">3</span><span style="color: rgb(0,0,0)">: shortcut.WindowStyle </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">3</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">break</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">case</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">7</span><span style="color: rgb(0,0,0)">: shortcut.WindowStyle </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">7</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">break</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">default</span><span style="color: rgb(0,0,0)"> : shortcut.WindowStyle </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">1</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">break</span><span style="color: rgb(0,0,0)">; } </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">快捷方式的描述 </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> shortcut.Description </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> strAppDescription; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">可以自定义快捷方式图标.(如果不设置,则将默认源文件图标.) </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)">(strICONpath </span><span style="color: rgb(0,0,0)">!=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">""</span><span style="color: rgb(0,0,0)">) shortcut.IconLocation </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> strICONpath; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">设置应用程序的启动参数(如果应用程序支持的话) </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (strAppDescription </span><span style="color: rgb(0,0,0)">!=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">""</span><span style="color: rgb(0,0,0)">) shortcut.Arguments </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> strAppDescription; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">设置快捷键(如果有必要的话.) 如:"CTRL+ALT+D";</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (strHotKey </span><span style="color: rgb(0,0,0)">!=</span><span style="color: rgb(128,0,0)">""</span><span style="color: rgb(0,0,0)">) shortcut.Hotkey </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> strHotKey; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">保存快捷方式 </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> shortcut.Save(); } } }</span></div>
试试其它关键字
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
asion
贡献的其它代码
(
10
)
.
只允许运行一个窗体实例
.
C#可移动按钮“相关代码”
.
XML操作演练
.
创建快捷方式
.
自定义不规则窗体和控件
.
自定义后缀名
.
自动粘合桌面边缘
.
设置窗体效果AnimateWindow
.
全局快捷键
.
模拟QQ振屏功能
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3