本帖最后由 yu2n 于 2017-1-27 14:46 编辑
Mark. 墙内资料不好找。- 'VBS 使用 Shell.Application 创建快捷方式
- Option Explicit
-
- Main
- '================================================================================
- Sub Main()
- '================================================================================
- Dim exePath, lnkPath
- '在当前目录创建
- exePath = "Evenicle・Rance.exe"
- lnkPath = "イブニクル・ランス版.lnk"
- If CreateLink(exePath, lnkPath) Then
- Msgbox lnkPath & " 创建成功!", vbInformation, WScript.ScriptName
- Else
- Msgbox lnkPath & " 创建失败!", vbCritical, WScript.ScriptName
- End If
-
- '在当前用户桌面创建
- exePath = "Evenicle・Rance.exe"
- lnkPath = CreateObject("Wscript.Shell").SpecialFolders("Desktop") & "\イブニクル・ランス版.lnk"
- If CreateLink(exePath, lnkPath) Then
- Msgbox lnkPath & " 创建成功!", vbInformation, WScript.ScriptName
- Else
- Msgbox lnkPath & " 创建失败!", vbCritical, WScript.ScriptName
- End If
- End Sub
-
-
- '================================================================================
- '使用 Shell.Application 创建快捷方式
- '================================================================================
- Function CreateLink(ByVal exePath, ByVal lnkPath)
- Dim exeDir, exeName, lnkDir, lnkName
- Dim objFS, objShell, objFolder, objFolderItem, objShellLink
- Set objFS = CreateObject("Scripting.FileSystemObject")
- Set objShell = CreateObject("Shell.Application")
- CreateLink = False
- exeName = Split(exePath,"\")(UBound(Split(exePath,"\"))) '设置路径
- exeDir = Left(exePath, Len(exePath) - Len(exeName))
- lnkName = Split(lnkPath,"\")(UBound(Split(lnkPath,"\")))
- lnkDir = Left(lnkPath, Len(lnkPath) - Len(lnkName))
- If exeDir = "" Then exeDir = objFS.GetFolder(".").Path & "\"
- If lnkDir = "" Then lnkDir = exeDir
- Set objFolder = objShell.NameSpace(lnkDir) '获取快捷方式对象
- If objFolder Is Nothing Then Exit Function
- Set objFolderItem = objFolder.ParseName(lnkName)
- If objFolderItem Is Nothing Then
- objFS.CreateTextFile lnkPath, true
- Set objFolderItem = objFolder.ParseName(lnkName)
- If objFolderItem Is Nothing Then
- objFS.DeleteFile lnkPath
- Exit Function
- End If
- End If
- Set objShellLink = objFolderItem.GetLink '设置快捷方式属性
- objShellLink.Path = exePath
- objShellLink.Arguments = ""
- objShellLink.WorkingDirectory = exeDir
- objShellLink.Hotkey = 0
- objShellLink.ShowCommand = 1
- objShellLink.Description = ""
- objShellLink.SetIconLocation exePath, 0
- objShellLink.Save()
- CreateLink = True
- End Function
复制代码
|