views:

100

answers:

4

I know a topic already exists like that but I do not want to use a VB script.

I would hope you can create a shortcut using a command line in DOS.

Please post some example that would be great.

Thanks!

AA

+2  A: 
mklink /D c:\vim "C:\Program Files (x86)\Vim"

More Info Here

And Cygwin's ln - s

http://en.wikipedia.org/wiki/Symbolic_link#Cygwin_symbolic_links

Hamish Grubijan
subst is a dos hack for drive letters only, It has nothing to do with shortcuts.
John Knoeller
@John: Man....remember those subst commands...its used to create a drive letter for a real nested subdirectory...like an alias for it...
tommieb75
@tommieb75: good times, man, good times ;)
John Knoeller
A symlink isn't really an option for the vast majority of programs. Windows isn't UNIX and many Windows programs assume stuff to reside in their application directories. If you symlink them they almost certainly won't work anymore. I suspect you want a Shell link (aka shortcut) for which John's solution is actually the proper one.
Joey
+1  A: 

You can't create a shortcut in a .bat file without invoking an external program.

However, every version of Windows since Win2k has a built in scripting language called Windows Script Host

Here is a small WSH script that I wrote a few years ago that can be called from a .bat file, just save this text as shortcut.wsf, it contains useage information in the script.

<package>
 <job id="MakeShortcut">
  <runtime>
   <description>Create a shortcut (.lnk) file.</description>
   <named
     name = "Target"
     helpstring = "the target script"
     type = "string"
     required = "true"
   />
   <named
     name = "Args"
     helpstring = "arguments to pass to the script"
     type = "string"
     required = "false"
   />
   <unnamed
     name = "basename"
     helpstring = "basename of the lnk file to create"
     type = "string"
     required = "false"
   />
  </runtime>

  <script language="JScript">

   if ( ! WScript.Arguments.Named.Exists("Target"))
   {
      WScript.Arguments.ShowUsage();
      WScript.Quit(2);
   }

   target = WScript.Arguments.Named.Item("Target");
   WScript.Echo("target " + target);
   args   = WScript.Arguments.Named.Item("Args");
   WScript.Echo("args " + args);
   base = WScript.Arguments.Unnamed.Item(0);
   WScript.Echo("base " + base);

   fso   = WScript.CreateObject("Scripting.FileSystemObject");
   //path  = fso.GetParentFolderName(WScript.ScriptFullName);
   path  = fso.GetAbsolutePathName(".");
   WScript.Echo("path = " + path);
   Shell = WScript.CreateObject("WScript.Shell");

   short = fso.BuildPath(path,base);
   if ( ! fso.GetExtensionName(base))
      short = short + ".lnk";

   link  = Shell.CreateShortcut(short);
   link.TargetPath   = fso.BuildPath(path, target);
   if (args != null && args != "")
      link.Arguments = args;
   else
      link.Arguments = base;
   //link.Description = "Sound Forge script link";
   //link.HotKey = "ALT+CTRL+F";
   //link.IconLocation = fso.BuildPath(path, target) + ", 2";
   //link.WindowStyle = "1"
   //link.WorkingDirectory = path;
   link.Save();

  </script>
 </job>
</package>

run it without any arguments to get useage

c:\> shortcut.wsf
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Create a shortcut (.lnk) file.
Usage: shortcut.wsf /Target:value [/Args:value] [basename]

Options:

Target   : the target script
Args     : arguments to pass to the script
basename : basename of the lnk file to create
John Knoeller
There is also PowerShell which is way better ;)
Hamish Grubijan
_All_ Versions of Windows since Win98 have WSH, PowerShell is only included by default on Win7 and Server 2008. In terms of code portability there's no contest.
John Knoeller
A: 

Creating a shortcut in the .lnk format is basically impossible from a batch file without calling an external program of some kind. The file spec can be found here, and a quick glace will explain.

Creating a .url format shortcut is quite easy as the format is a simple text file. The spec can be found here. This format has a few disadvantages, but may accomplish your goal.

Chris S
What you linked is *not* the specification but a reverse-engineering of the format. You can find the actual spec at http://msdn.microsoft.com/en-us/library/dd871305(PROT.10).aspx
Joey
A: 

you can get shortcut.exe from the resource kit.

ghostdog74

related questions