• Editing Shortcuts via a batch file?

    Home » Forums » AskWoody support » Windows » Windows – other » Editing Shortcuts via a batch file?

    Author
    Topic
    #406447

    Is it possible to edit shortcuts using a batch file?
    My scenario – I have a group of shortcuts I use to launch an Access DB in various configurations. For backup purposes I copy the folder containing the shortcuts and DB to a new folder daily. So the shortcuts all have to be updated with the new path. Opening 6+ shortcuts to edit manually is annoying (but not fatal) so it got me wondering about an update with a batch file.

    Thanks

    Viewing 7 reply threads
    Author
    Replies
    • #842885

      You can create shortcuts using VBS file.

      This is an example (from Microsoft):

      ‘ ********************************************************************************
      ‘ *
      ‘ * Shortcut related methods.
      ‘ *

      Dim WSHShell
      Set WSHShell = WScript.CreateObject(“WScript.Shell”)

      Dim MyShortcut, MyDesktop, DesktopPath

      ‘ Read desktop path using WshSpecialFolders object
      DesktopPath = WSHShell.SpecialFolders(“Desktop”)

      ‘ Create a shortcut object on the desktop
      Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & “Shortcut to notepad.lnk”)

      ‘ Set shortcut object properties and save it
      MyShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings(“%windir%notepad.exe”)
      MyShortcut.WorkingDirectory = WSHShell.ExpandEnvironmentStrings(“%windir%”)
      MyShortcut.WindowStyle = 4
      MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings(“%windir%notepad.exe, 0”)
      MyShortcut.Save

      WScript.Echo “A shortcut to Notepad now exists on your Desktop.”

      ‘ ********************************************************************************

      If your new folder is created every day using certain rules, you can automate this process by automatically changing second argument in Set MyShortcut line. Remember, a new shortcut will override previous one without any warning.

    • #842886

      You can create shortcuts using VBS file.

      This is an example (from Microsoft):

      ‘ ********************************************************************************
      ‘ *
      ‘ * Shortcut related methods.
      ‘ *

      Dim WSHShell
      Set WSHShell = WScript.CreateObject(“WScript.Shell”)

      Dim MyShortcut, MyDesktop, DesktopPath

      ‘ Read desktop path using WshSpecialFolders object
      DesktopPath = WSHShell.SpecialFolders(“Desktop”)

      ‘ Create a shortcut object on the desktop
      Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & “Shortcut to notepad.lnk”)

      ‘ Set shortcut object properties and save it
      MyShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings(“%windir%notepad.exe”)
      MyShortcut.WorkingDirectory = WSHShell.ExpandEnvironmentStrings(“%windir%”)
      MyShortcut.WindowStyle = 4
      MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings(“%windir%notepad.exe, 0”)
      MyShortcut.Save

      WScript.Echo “A shortcut to Notepad now exists on your Desktop.”

      ‘ ********************************************************************************

      If your new folder is created every day using certain rules, you can automate this process by automatically changing second argument in Set MyShortcut line. Remember, a new shortcut will override previous one without any warning.

    • #843613

      Would it make more sense to think of the copy as the backup and keep the production file in the same folder? No need to update the shortcuts and the folder/files can be made read-only as soon as they are copied.

    • #843614

      Would it make more sense to think of the copy as the backup and keep the production file in the same folder? No need to update the shortcuts and the folder/files can be made read-only as soon as they are copied.

    • #843772

      Catherine

      To change a shortcut I would use the old NT4 Resource Kit utility called SHORTCUT, or perhaps a similarly named one from Marty List, here via Jerry Shulman’s RegHacks website.

      Is there any rule which defines the new path name? If, say, it contains the date, then a BATch file could be knocked up fairly easily. Just describe what you want!

      John

      • #843961

        The new subdirectory is always something like June23_2004.

        • #844456

          I agree with Gfamily – create the folder called “Today” or “Current” and rename it to “June23_2004” when you need to create a new one. The reason is: somebody else can create a shortcut also if folders are on the server.

      • #843962

        The new subdirectory is always something like June23_2004.

    • #843773

      Catherine

      To change a shortcut I would use the old NT4 Resource Kit utility called SHORTCUT, or perhaps a similarly named one from Marty List, here via Jerry Shulman’s RegHacks website.

      Is there any rule which defines the new path name? If, say, it contains the date, then a BATch file could be knocked up fairly easily. Just describe what you want!

      John

    • #844514

      If you want to do this from Access itself (or Visual Basic) you can use Windows Script Host in VB/VBA. For sample code see attached text file (exported code module from an Access db). The ResetShortcutProperties procedure takes one argument, the new path where database file & shortcuts are located, and updates any shortcut file (.LNK) found in specified folder. Typically I need to do this for secured databases, where it is necessary to specify path to workgroup file, etc in the shortcut arguments. The procedure worked correctly with both secured db and non-secured db shortcuts. Code may have to be modified depending on how the shortcuts are configured; the sub assumes that path/name of database file is always first argument following target (path to executable), followed by path/name of workgroup file, then any other options. The paths are delimited by double-quotes in event of spaces in path. Code requires references to WSH and Scripting Runtime as noted in comments at top of module.

      HTH

    • #844515

      If you want to do this from Access itself (or Visual Basic) you can use Windows Script Host in VB/VBA. For sample code see attached text file (exported code module from an Access db). The ResetShortcutProperties procedure takes one argument, the new path where database file & shortcuts are located, and updates any shortcut file (.LNK) found in specified folder. Typically I need to do this for secured databases, where it is necessary to specify path to workgroup file, etc in the shortcut arguments. The procedure worked correctly with both secured db and non-secured db shortcuts. Code may have to be modified depending on how the shortcuts are configured; the sub assumes that path/name of database file is always first argument following target (path to executable), followed by path/name of workgroup file, then any other options. The paths are delimited by double-quotes in event of spaces in path. Code requires references to WSH and Scripting Runtime as noted in comments at top of module.

      HTH

    Viewing 7 reply threads
    Reply To: Editing Shortcuts via a batch file?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: