惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
B
Blog
P
Proofpoint News Feed
美团技术团队
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
有赞技术团队
有赞技术团队
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
H
Help Net Security
罗磊的独立博客
L
LangChain Blog
GbyAI
GbyAI
腾讯CDC
T
The Blog of Author Tim Ferriss
Microsoft Security Blog
Microsoft Security Blog

博客园 - 水如烟(LzmTW)

.NET的变量在代码集中是不安全的 HOW TO:获取硬盘物理序列号(VB.NET) 一个简单的CodeAccessPermission生成器 认识一下Attribute HOW TO:端口打印(比较粗糙) 标记法定义和创建数据库(四) 标记法定义和创建数据库 Sql2005数据类型与Framework类型的对应关系 HOW TO:重启程序(WinForm) HOW TO:设置默认打印机 HOW TO:避免“将COM对象与其基础RCW分开后不能再使用该对象”错误 HOW TO:控制是否允许用户退出ExcelApplication的Workbook 树和自联表(五) 树和自联表(六) 树和自联表(四) 树和自联表(一) 行政区划数据数据库的设计(脚本) 行政区划数据数据库的设计(七) 行政区划数据数据库的设计(六)
一个创建快捷方式类
水如烟(LzmTW) · 2007-02-08 · via 博客园 - 水如烟(LzmTW)

Author:水如烟

利用了WScript.Shell

示例:

Namespace LzmTW.uSystem.uIO
    
Public Class ShortcutDemo'示例,创建当前程序的快捷方式到桌面
        Public Shared Sub CreateCurrentAppShortCutOnDesktop()
            
Dim args(My.Application.CommandLineArgs.Count - 1As String
            My.Application.CommandLineArgs.CopyTo(args, 
0)Dim appName As String = My.Application.Info.Title
            
Dim mShortcut As WshShortcut
            mShortcut 
= WshShortcut.CreateIn(Environment.SpecialFolder.Desktop, appName)
            
With mShortcut
                .TargetPath 
= Application.ExecutablePath
                .Arguments 
= String.Join(",", args)
                .Description 
= My.Application.Info.Description
                .Hotkey 
= Keys.Control Or Keys.Alt Or Keys.A
                .WindowStyle 
= WshWindowStyle.WshMaximizedFocus
                .WorkingDirectory 
= .SpecialFolder(Environment.SpecialFolder.MyDocuments)
                
'.SetDefaultIcon()
                .Save()
                .Dispose()
            
End With
        
End Sub
    
End Class
End Namespace

类:

Option Strict OffImports System.ComponentModelNamespace LzmTW.uSystem.uIO
    
Public Class WshShortcut
        
Implements IDisposablePrivate gComIWshShortcut As Object
        
Private gComIWshShell3 As ObjectSub New()
            gComIWshShell3 
= CreateObject("WScript.Shell")
        
End Sub''' <summary>
        ''' 打开或准备创建
        ''' </summary>
        ''' <param name="PathLink">快捷方式全名</param>
        ''' <remarks>如要创建或修改,配置参数后需要保存</remarks>
        Public Sub Create(ByVal PathLink As String)
            
If Not PathLink.ToLower.EndsWith(".lnk"Then
                PathLink 
= PathLink & ".lnk"
            
End If

            OnlyMeDispose()

            gComIWshShortcut 

= gComIWshShell3.CreateShortcut(PathLink)
        
End Sub'舍去不用
        Private Sub Load(ByVal PathLink As String)
            gComIWshShortcut.Load(PathLink)
        
End Sub''' <summary>
        ''' 保存(创建或更改当前快捷方式)
        ''' </summary>
        Public Sub Save()
            gComIWshShortcut.Save()
        
End Sub''' <summary>
        ''' 目标
        ''' </summary>
        Public Property TargetPath() As String
            
Get
                
Return gComIWshShortcut.TargetPath
            
End Get
            
Set(ByVal value As String)
                gComIWshShortcut.TargetPath 
= value
            
End Set
        
End Property''' <summary>
        ''' 目标参数
        ''' </summary>
        Public Property Arguments() As String
            
Get
                
Return gComIWshShortcut.Arguments
            
End Get
            
Set(ByVal value As String)
                gComIWshShortcut.Arguments 
= value
            
End Set
        
End Property''' <summary>
        ''' 备注
        ''' </summary>
        Public Property Description() As String
            
Get
                
Return gComIWshShortcut.Description
            
End Get
            
Set(ByVal value As String)
                gComIWshShortcut.Description 
= value
            
End Set
        
End Property''' <summary>
        ''' 快捷方式全名
        ''' </summary>
        Public ReadOnly Property FullName() As String
            
Get
                
Return gComIWshShortcut.FullName
            
End Get
        
End Property''' <summary>
        ''' 快捷键
        ''' </summary>
        Public Property Hotkey() As Keys
            
Get
                
Return KeysConverter.ConvertFromString(gComIWshShortcut.Hotkey)
            
End Get
            
Set(ByVal value As Keys)
                gComIWshShortcut.Hotkey 
= KeysConverter.ConvertTo(value, GetType(String))
            
End Set
        
End Property''' <summary>
        ''' 图标位置
        ''' </summary>
        Public Property IconLocation() As String
            
Get
                
Return gComIWshShortcut.IconLocation
            
End Get
            
Set(ByVal value As String)
                gComIWshShortcut.IconLocation 
= value
            
End Set
        
End Property''' <summary>
        ''' 相对路径
        ''' </summary>
        Public WriteOnly Property RelativePath() As String
            
Set(ByVal value As String)
                gComIWshShortcut.RelativePath 
= value
            
End Set
        
End Property''' <summary>
        ''' 运行方式
        ''' </summary>
        Public Property WindowStyle() As WshWindowStyle
            
Get
                
Return gComIWshShortcut.WindowStyle
            
End Get
            
Set(ByVal value As WshWindowStyle)
                gComIWshShortcut.WindowStyle 
= value
            
End Set
        
End Property''' <summary>
        ''' 起始位置
        ''' </summary>
        Public Property WorkingDirectory() As String
            
Get
                
Return gComIWshShortcut.WorkingDirectory
            
End Get
            
Set(ByVal value As String)
                gComIWshShortcut.WorkingDirectory 
= value
            
End Set
        
End PropertyPrivate Sub OnlyMeDispose()
            
If gComIWshShortcut Is Nothing Then Return

            System.Runtime.InteropServices.Marshal.ReleaseComObject(gComIWshShortcut)
            gComIWshShortcut 

= Nothing
        
End Sub''' <summary>
        ''' 释放内存
        ''' </summary>
        Public Sub Dispose() Implements System.IDisposable.Dispose
            OnlyMeDispose()

            System.Runtime.InteropServices.Marshal.ReleaseComObject(gComIWshShell3)
            gComIWshShell3 

= Nothing
        
End Sub''以下为补充

        
''' <summary>
        ''' 默认图标位置
        ''' </summary>
        Public Function DefaultIcon() As String
            
Return "%SystemRoot%system32SHELL32.dll,30"
        
End FunctionPublic Sub SetDefaultIcon()
            
Me.IconLocation = Me.DefaultIcon
        
End Sub''' <summary>
        ''' 获取常用目录
        ''' </summary>
        Public Function SpecialFolder(ByVal folder As Environment.SpecialFolder) As String
            
Return Environment.GetFolderPath(folder)
        
End Function''' <summary>
        ''' 在指定目录下打开或准备创建快捷方式
        ''' </summary>
        ''' <param name="folder">目录</param>
        ''' <param name="name">快捷方式名称</param>
        ''' <remarks>如要创建或修改,配置参数后需要保存</remarks>
        Public Shared Function CreateIn(ByVal folder As Environment.SpecialFolder, ByVal name As StringAs WshShortcut
            
Dim mShortcut As New WshShortcut
            
Dim mPathLink As String = String.Concat(mShortcut.SpecialFolder(folder), "\", name)
            mShortcut.Create(mPathLink)
            
Return mShortcut
        
End FunctionPrivate Shared KeysConverter As New KeysConverter
    
End Class
End Namespace

Namespace LzmTW.uSystem.uIO
    
Public Enum WshWindowStyle
        
'WshHide = 0
        WshNormalFocus = 1
        
'WshMinimizedFocus = 2
        WshMaximizedFocus = 3
        
'WshNormalNoFocus = 4
        'WshMinimizedNoFocus = 6
        WshMinimizedFocus = 7
    
End Enum
End Namespace