views:

5117

answers:

3

I'm normally a Linux guy, but I need to write a batch script on Windows to change the target of some shortcuts. Is there a command to do that?

A: 

Type HELP ASSOC in a command prompt. I think that is what you are looking for.

Or maybe you want to create shortcuts and then I think you'll want to use this which works well for me.

kenny
It appears the assoc command changes file associations. Not what I'm looking for. I don't want to create shortcut files either, I just need to change the target.
Mark A. Nicolosi
+4  A: 

I doubt there is a way to do it with a batch script. It's doable in VBScript, though.

Set sh = CreateObject("WScript.Shell")
Set shortcut = sh.CreateShortcut("C:\Wherever\Shortcut.lnk")
shortcut.TargetPath = "C:\Wherever\Whatever.txt"
shortcut.Save

Save the script in a file ending in vbs and run it from the command line using cscript whatever.vbs.

(Don't be fooled by the name -- CreateShortcut is used to both create and modify shortcuts.)

Tmdean
and he can call a vbscript file from his batch file with cscript
kenny
Excellent. This would be perfect. I'll still write a batch script, because I don't want to learn VB, but use your VB script. Thanks Tmdean and Kenny!
Mark A. Nicolosi
+1  A: 

There isn't a native program that comes with windows to achieve this. I scoured the internet for this same functionality awhile ago and stumbled upon the free software XXMKLINK.

[http://www.xxcopy.com/xxcopy38.htm][1]

With XXMKLINK, you can write a batch file for software installation which has been done by specialized instllation programs. Basically, XXMKLINK is to gather the information from a command line and package it into a shortcut.

Command syntax of XXMKLINK:

xxmklink spath opath [ arg [ wdir [ desc [ mode [ icon[:n] ]]]]]

where 

  spath     path of the shortcut (.lnk added as needed)
  opath     path of the object represented by the shortcut
  arg       argument string (use quotes with space, see below)
  wdir      path of the working directory (for "Start in")
  desc      description string (shown in Shosrtcut's Properties)
  mode      display mode (1:Normal [default], 3:Maximized, 7:Minimized)
  icon[:n]  icon file [with optional icon index value n]

  In addition to the above, the following switches are supported
  which can be placed in any position in the command line.

  /p        prompts before action
  /q        no output when successful (quiet)
  /e        checks error condition strictly

The downside is you'll need to copy the xxmklink exe onto each computer with the batch script.

A link to download it is available at the bottom of the linked page.