Creating desktop shortcuts from the command line?

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...
 
T

Tom Porterfield

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.
 
B

Bill Sharpe

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...
 
T

Torgeir Bakken \(MVP\)

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
 
G

Guest

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. ;)
 
G

Guest

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top