本帖最后由 apang 于 2014-12-10 00:42 编辑
LNK快捷方式的属性主要包括以下几项:
1.目标(T)
2.起始位置(S)
3.快捷键(K)
4.运行方式(R)
5.备注(O)
6.快捷方式图标(C)
7.参数
以下为一个实例,先创建一个 notepad.exe 的桌面快捷方式,然后获取快捷方式属性值,再修改它。
创建快捷方式:- Dim WshShell, strDesk, strWinDir, objLink
- Set WshShell = CreateObject("WScript.Shell") ''创建对象
- strDesk = WshShell.SpecialFolders("DeskTop") ''桌面文件夹路径
- strWinDir = WshShell.ExpandenVironmentStrings("%WinDir%") ''系统文件夹路径
- Set objLink = WshShell.CreateShortcut(strDesk & "\NotePad.LNK")
- objLink.TargetPath = strWinDir & "\system32\notepad.exe" ''目标路径
- objLink.WorkingDirectory = strWinDir & "\system32" ''工作目录(起始位置)
- objLink.WindowStyle = 1 ''窗口风格(运行方式 1=常规,3=最大化,7=最小化)
- objLink.Description = "记事本" ''描述(备注)
- objLink.IconLocation = strWinDir & "\system32\notepad.exe, 0" ''设置图标
- objLink.Save
复制代码 获取快捷方式属性值:- Dim objShell, objFolder, objFolderItem, objShellLink, s
- Set objShell = CreateObject("Shell.Application") ''创建对象
- Set objFolder = objShell.NameSpace(&H00) ''桌面文件夹路径
- Set objFolderItem = objFolder.ParseName("NotePad.LNK")
- Set objShellLink = objFolderItem.GetLink ''创建快捷方式对象
- s = "目标路径:" & objShellLink.Path & vbLf
- s = s & "工作目录:" & objShellLink.WorkingDirectory & vbLf
- s = s & "快捷键:" & objShellLink.Hotkey & vbLf
- s = s & "运行方式:" & objShellLink.ShowCommand & vbLf
- s = s & "描述:" & objShellLink.Description & vbLf
- WScript.Echo s
复制代码 修改快捷方式属性值:- Dim objShell, objFolder, strWinDir, objFolderItem, objShellLink
- Set objShell = CreateObject("Shell.Application") ''创建对象
- Set objFolder = objShell.NameSpace(&H00) ''桌面文件夹路径
- strWinDir = objShell.NameSpace(&H24).Self.Path ''系统文件夹路径
- Set objFolderItem = objFolder.ParseName("NotePad.LNK")
- Set objShellLink = objFolderItem.GetLink ''创建快捷方式对象
- objShellLink.Path = strWinDir & "\NotePad.exe" ''修改目标路径
- objShellLink.WorkingDirectory = objFolder.Self.Path ''修改工作目录为桌面
- objShellLink.Hotkey = 1614 ''修改快捷键为 Ctrl + Alt + N
- ''Shift=256,Ctrl=512,Alt=1024,N(虚拟键位)=78,累加后值为1614
- ''虚拟键码表:http://msdn.microsoft.com/en-us/library/dd375731(VS.85).aspx
- objShellLink.ShowCommand = 3 ''修改运行方式(1=常规 3=最大化 7=最小化)
- objShellLink.Description = "这是一个快捷方式" ''修改描述
- objShellLink.Arguments = WScript.ScriptFullName ''增加参数
- objShellLink.SetIconLocation strWinDir & "\explorer.exe", 0 ''修改图标
- objShellLink.Save ''保存修改
复制代码
|