Creating desktop shortcuts from the command line?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know how to create a desktop shortcut to an executable using the
command line/batch file?

I've tried: copy c:\application.exe c:\documents and
settings\%username%\desktop\shortcut to application.lnk

and it doesn't seem to work. It creats an icon on the desktop, but clicking
it does nothing. I've tried copy and xcopy and all the switches, but none
seem to create shortcuts. I've looked at other shorcuts (automatically
created) and they all seem to be in the form of: shortcut.lnk

I am stumped. Any 411 would be great. Thanks...
 
Peter said:
Does anyone know how to create a desktop shortcut to an executable using the
command line/batch file?

I've tried: copy c:\application.exe c:\documents and
settings\%username%\desktop\shortcut to application.lnk

and it doesn't seem to work. It creats an icon on the desktop, but clicking
it does nothing. I've tried copy and xcopy and all the switches, but none
seem to create shortcuts. I've looked at other shorcuts (automatically
created) and they all seem to be in the form of: shortcut.lnk

I am stumped. Any 411 would be great. Thanks...

No way to do it using standard batch commands that I know of. You can do
this using windows script, either vbscript or javascript. For examples see
http://msdn.microsoft.com/library/en-us/script56/html/wsconcreatingshortcut.asp.
--
Tom Porterfield
MS-MVP Windows
http://support.telop.org

Please post all follow-ups to the newsgroup only.
 
Curious as to why you want to do this when drag and drop in Windows
works so easily to create shortcuts?

Bill

in message Does anyone know how to create a desktop shortcut to an executable using
the
command line/batch file?

I've tried: copy c:\application.exe c:\documents and
settings\%username%\desktop\shortcut to application.lnk

and it doesn't seem to work. It creats an icon on the desktop, but
clicking
it does nothing. I've tried copy and xcopy and all the switches, but
none
seem to create shortcuts. I've looked at other shorcuts (automatically
created) and they all seem to be in the form of: shortcut.lnk

I am stumped. Any 411 would be great. Thanks...
 
Peter said:
Does anyone know how to create a desktop shortcut to an executable
using the command line/batch file?

I've tried: copy c:\application.exe c:\documents and
settings\%username%\desktop\shortcut to application.lnk
Hi,

For starters, never use %username% to get a user's profile path.

You should use the environment variable USERPROFILE instead of the
username, because sometimes the user profile path contains more than
just the username (e.g. <username>.<domain>, <username>.000,
<username>.windows)

Back to your issue:

You cannot create a shortcut by just copy the exe file.

You can use a VBScript to create the shortcut:
http://groups.google.co.uk/group/mi...cript/msg/e8cc3cc8e6ee0fa9?dmode=source&hl=en

Alternatively:

Some free command line tools for shortcut creation:

Marty List's shortcut.exe
http://optimumx.com/download/#Shortcut

MakeScut
http://www.scriptlogic.com/products/scriptingtoolkit/Default.asp
 
The reason is that we have a custom VB application that installs itself but
the programmers never thought to make life easy and put a shortcut to it
anywhere. I'm scripting an old version uninstall, new version install and
shortcut creation. I know that "create shortcut" is so easy via mouse -- but
my end users are dumber than the mouse itself. ;)
 
The solution I ended up using was Wscript to make a .vbs file. Using the:

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("AllUsersDesktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\shortcut name.lnk")
oShellLink.TargetPath = "c:\application folder\application.exe"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = "c:\application folder\application.ico"
oShellLink.Description = "Shortcut Script"
oShellLink.WorkingDirectory = "c:\application folder"
oShellLink.Save


did the trick.
THANKS ALL!
 
Back
Top