Is there a way to access shortcut properties, specifically the Tarket string? I would like to edit the string and save the new string.
Thanks,
James
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Shortcut Properties (Access 97)
The easiest way to do this is use Windows Script Host (WSH). Simple example:
Public Sub CreateDesktopShortcut(ByRef strShortcut As String)
Dim wsh As New IWshRuntimeLibrary.IWshShell_Class
Dim shrt As New IWshShortcut_Class
Dim strDesktopPath As String
Dim strTarget As String
strDesktopPath = wsh.SpecialFolders(“Desktop”)
strTarget = “C:Program FilesMicrosoft OfficeOfficeWINWORD.EXE”
Set shrt = wsh.CreateShortcut(strDesktopPath & “” & strShortcut & “.lnk”)
With shrt
.TargetPath = Chr(34) & strTarget & Chr(34)
.Arguments = Chr(34) & “C:My DocumentsTest.doc” & Chr(34)
.Hotkey = “CTRL+SHIFT+W”
.IconLocation = strTarget & “, 0”
.Description = strShortcut
.Save
End With
Set wsh = Nothing
Set shrt = Nothing
End Sub
You can use WSH CreateShortcut method to create new shortcut, or to modify existing one. Above example worked in either case. Note use of WSH SpecialFolders property to get Desktop path. Also note use of Chr(34) to delimit target path with double-quotes, which are required if any spaces in path. To use this example you need to set a reference to the Windows Script Host Object Model (Ver 1.0) (IWshRuntimeLibrary) (WSHOM.OCX). For more info on WSH properties/methods refer to MSDN reference (look up CreateShortcut under WSH/Reference/Methods):
Windows Script Host Object Model
Examples are in VBScript but can be modified for use in VBA.
HTH
I can get part of the Target of the shortcut with the following:
Set shrt = wsh.CreateShortcut(strDesktopPath)
strTarket = shrt.TargetPath
shrt.TargetPath is returning everything within the first set of quotes. Any ideas on how to capture the MDB and MDW information which are inclosed in quotes of their own?
As you probably figured out, the shortcut Arguments property will contain any command line arguments, such as path to workgroup file, that follow TargetPath. Example of how you can retrieve these properties with existing shortcut, for anyone interested:
Public Sub GetShortcutProperties(ByRef strShortcut As String)
On Error GoTo Err_Handler
Dim wsh As New IWshRuntimeLibrary.IWshShell_Class
Dim lnk As New IWshShortcut_Class
Dim fso As New IWshRuntimeLibrary.FileSystemObject
Dim strDesktopPath As String
Dim strTarget As String
Dim strArgs As String
Dim strMsg As String
strDesktopPath = wsh.SpecialFolders(“Desktop”)
If fso.FileExists(strDesktopPath & “” & strShortcut & “.lnk”) Then
Set lnk = wsh.CreateShortcut(strDesktopPath & “” & strShortcut & “.lnk”)
‘ Get shortcut properties:
strTarget = lnk.TargetPath
strArgs = lnk.Arguments
Debug.Print “Target: ” & strTarget
Debug.Print “Arguments: ” & strArgs
‘ Change properties if necessary, then save
Else
strMsg = “Shortcut not found.”
MsgBox strMsg, vbExclamation, “NOT FOUND”
‘ Create new shortcut here if necessary, then save
End If
Exit_Sub:
Set wsh = Nothing
Set lnk = Nothing
Set fso = Nothing
Exit Sub
Err_Handler:
Select Case Err.Number
Case 0
Resume Next
Case Else
strMsg = “Error No ” & Err.Number & “: ” & Err.Description
MsgBox strMsg, vbExclamation, “SHORTCUT ERROR”
Resume Exit_Sub
End Select
End Sub
Example of use:
GetShortcutProperties “Shortcut to Northwind”
Target: C:Program FilesMicrosoft OfficeOffice10MSACCESS.EXE
Arguments: “C:Program FilesMicrosoft OfficeOffice10SamplesNorthwind.mdb”
Note that the Arguments property included the quotes, but not the TargetPath. (I used Chr(34) for both when creating shortcut.) But in any event you can test shortcut properties & modify if necessary by using WSH.
HTH
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications