VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Create shortcut

by phuongthanh37 (3 Submissions)
Category: Files/File Controls/Input/Output
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Create Shortcut

Inputs
Shortcut Name, Target Name, Start In, SIcon...
Code Returns
Shortcut link to target name

Rate Create shortcut

Option Explicit
Function TaoShortCut(TenFileShortCut As String, sName As String, _
      Optional sParam As String, Optional sStratIn As String, _
      Optional sIcon As String, Optional sComment As String)
Dim OBJ As Object, oShellLink As Object
Set OBJ = CreateObject("wscript.shell")
Set oShellLink = OBJ.CreateShortcut(TenFileShortCut)
With oShellLink
  .TargetPath = sName
  .Arguments = sParam
  .WorkingDirectory = sStratIn
  If sIcon = "" Then sIcon = sName
  .IconLocation = sIcon
  .Description = sComment
  .Save
End With
End Function
Function TaoShortCutOnDeskTop(TenFileShortCut As String, sName As String, _
      Optional sParam As String, Optional sStratIn As String, _
      Optional sIcon As String, Optional sComment As String)
Dim OBJ As Object, oShellLink As Object
Set OBJ = CreateObject("wscript.shell")
Set oShellLink = OBJ.CreateShortcut(TenFileShortCut)
Set oShellLink = OBJ.CreateShortcut(OBJ.SpecialFolders("Desktop") & "\" & TenFileShortCut)
With oShellLink
  .TargetPath = sName
  .Arguments = sParam
  .WorkingDirectory = sStratIn
  If sIcon = "" Then sIcon = sName
  .IconLocation = sIcon
  .Description = sComment
  .Save
End With
End Function
Private Sub Form_Load()
TaoShortCut "C:\Short1.Lnk", "E:\WINDOWS\system32\notepad.exe", , , , "Create shortcut by phuongthanh37"
TaoShortCutOnDeskTop "Short2.lnk", "%SystemRoot%\explorer.exe", "/e", "%HOMEDRIVE%%HOMEPATH%", "%SystemRoot%\explorer.exe,1", "Create shortcut by phuongthanh37"
End Sub

Download this snippet    Add to My Saved Code

Create shortcut Comments

No comments have been posted about Create shortcut. Why not be the first to post a comment about Create shortcut.

Post your comment

Subject:
Message:
0/1000 characters