Solved

Create Shortcut File (LNK) via command line

Posted on 2000-04-24
14
11,127 Views
Last Modified: 2008-03-03
Hello Experts,

I am seeking for a tool that lets me create a Windows shortcut file (.lnk) file from within a batch file or via command line.

Additional reqired features:

* must work on Windows 9x and Windows NT.

* must be as small as possible, since intended use is Logon-Scripts over slow RAS links, so no libraries, VB runtimes, Scripting host, ect, just one standalone .exe file.

* parameter passing either via environment variables or plain text file (ini file), since the tools command line very likely cannot hold enough characters to specify all aspects of a lnk file.

Just to make everything clear, a sample of how I'd like to create a link:

Set title=Edit-a-file
set exefile=c:\winnt\system32\notepad.exe
set workdir=c:\temp
...
...
more set statements to define the lnk file symbol, shortcut key, ...
...
...

makelnk "c:\winnt\profiles\all users\desktop\Notepad.lnk"

So who can help me to get such a program "mklink.exe" ...?

P.S. somewhere I found a hint how to create a lnk file via DDE. Unfortunately the author didn't give any details (just said it was possible), and didn't cover the topic how to send DDE commands from the command line (probably a tool is available somewhere). I would accept such a solution as well, if the DDE sender tool is pretty small...

Thanks,

...Armin
armin.linder@adlon.de
0
Comment
Question by:arminl
  • 6
  • 4
  • 2
  • +2
14 Comments
 
LVL 9

Expert Comment

by:cymbolic
ID: 2744114
Why can't you:
Make the link on your local machine, set theproperties as yo0u like them, and just transfer the created .lnk file to the user's desktop.  I think this will work for you.  These files are less than 1k in size.
0
 
LVL 22

Expert Comment

by:cookre
ID: 2744480
The problem with that is that the newer LNK files carry full path info (including server name) with them.

LNKs that will reside on C and refer only to C will be just fine with that approach.


Have you tried SHORTCUT.EXE from the NT4 Resource Kit:

shortcut: [-? -h -f -c -r -s] [[-t] target [[-n] name]] [-d working
directory]
        [-a Arguments] [-i Iconfile] [-x Icon index] [-u {all|[natdix]}]
        [-l logfile]


  -? -h This help
  -f Force overwrite of an existing short cut
  -c Change existing shortcut
  -s Make shortcut non tracking (Stupid)
  -r Resolve broken shortcut
  -t target Specifies the target of the shortcut
  -n name Specifies the file name of the shortcut file
  -d directory Specifies the directory name to start the application in
  -a arguments Specifies the arguments passed when the shortcut is used
  -i iconfile Specifiles the file the icon is in
  -x index Specifies the index into the icon file
  -u [spec] Dumps the contents of a shortcut. 'all' is the same as
'natdix'
               but the letters of 'natdix' can be specified to display
specific
               fields in the shortcut (repeats allowed, and order
followed)
  -l logfile record error messages in specified file

 
0
 
LVL 4

Author Comment

by:arminl
ID: 2746075
Cymbolic:
simply lack of flexibility.

Cookre:
the UNC path in the link is not an issue, it can be fixed setting the LinkResolveIgnoreLinkinfo policy.

I also have knowledge of shortcut.exe, but

a) it does not work with Windows 9x (but there is another program named shortcut.exe in the Windows 95 resource kit that works for 98 as well, but not for NT .-()
b) I searched all of the disks in my Technet Subscription, especially the various Resource Kits, but there was no shortcut.exe program :-(

Rumours say there is another NT Resource Kit CD called "supplemental two" which must be ordered separately from Microsoft, but I haven't verified this yet.

....Armin

0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 15

Expert Comment

by:simonet
ID: 2747494
I have written a program that does what you need. It's function is pretty much the same of SHORTCUT.EXE.

It's free and can be downloaded from here:
http://www.bhnet.com.br/~simonet/extras/makelnk.zip

Documentation is enclosed in the ZIP file.

Yours,

Alex


0
 
LVL 15

Expert Comment

by:simonet
ID: 2747529
By the way, MAKELNK meets all your requirements: it's small, does the job, is a simple standalone EXE (requires no other files to work), works with Win95/98/NT/2000.

Yours,

Alex
0
 
LVL 4

Author Comment

by:arminl
ID: 2750672
Hi Alex,

the program looks promising. Tested it on WNT, W2000, and W98. Links are created in several directories:

/L
1  desktop (OK)
2  Favorites (OK)
3  Program Files (OK)
4  Start Menu (OK)
5  Autostart (not corresponding with doc)
6  (hangs)
7  Appdata (not corresponding with doc)

The line I used to test was:

makelnk /T "%windir%\poledit.exe" /D "Test Link" /L 1 /G "Testgroup"

I increased /L by one and started the line 7 times.

A Testgroup never was created anywhere. Do you have a sample at hand how to create a groiup?

All Icons are put in the user profile directories. How can I create links in "all users" and "default user" profile directories?

Thnx,

Armin
0
 
LVL 15

Expert Comment

by:simonet
ID: 2751558
I'll take a look at it and get back to you.

Yours,

Alex
0
 
LVL 4

Author Comment

by:arminl
ID: 2754788
I have also tried to get "shortcut.exe" for nt, and bought the Windows NT Workstation Resource Kit SUpplement 4, which is the latest issue of the Resource kit (I was told).

A shortcut.exe for NT is not contained in that package.

So where do I get it ...?

....Armin
0
 
LVL 1

Expert Comment

by:l8knight
ID: 2755258
Have you thought of using "Windows Scripting" (JavaScript, VBScript)... there is a method in the WSHShell Object for creating shortcuts.

Extract from WSHOBJ.DOCW

shShell.CreateShortcut
The CreateShortcut method creates a WshShortcut object and returns it. If the shortcut title ends with ".URL," a WshURLShortcut object is created.
Syntax
WshShell.CreateShortcut(strPathname) = objShortcut
Example
' This code fragment creates a shortcut
' to the currently executing script
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set oShellLink = WshShell.CreateShortcut("Current Script.lnk")
oShellLink.TargetPath = Wscript.ScriptFullName
oShellLink.Save
Set oUrlLink = WshShell.CreateShortcut("Microsoft Web Site.URL")
oUrlLink.TargetPath = "http://www.microsoft.com"
oUrlLink.Save
See Also
WshShortcut object, WshUrlShortcut object

hope this helps

l8knight

0
 
LVL 22

Expert Comment

by:cookre
ID: 2755941
The folks in Redmond CLAIM it's on the NT4 Server and Workstation Resource Kits as well as the 95 Resource Kit.

I found it on the 95 CD, but could only find the WSH script on the Sep 99 NT utilities CD.
0
 
LVL 4

Author Comment

by:arminl
ID: 2756624
Whs is not installed on any machine, and what I am after is just a standalone .exe.

Simonets exe looked really promising and has worked pretty good in some way, so if he manages to get the group things right that's exactly what I am after.

Regarding the Redmond folks: I guess that the program is on the Ressource Kit Supplemental 2 only.

....Armin
0
 
LVL 15

Accepted Solution

by:
simonet earned 200 total points
ID: 2926117
I have rewritten the application and tested it. Everything should be ok now.

Please re-download it from the link I gave you in my first comment:

http://www.bhnet.com.br/~simonet/extras/makelnk.zip 

sorry for the delay.

Yours,

Alex
0
 
LVL 4

Author Comment

by:arminl
ID: 3173471
Answer accepted
0
 
LVL 4

Author Comment

by:arminl
ID: 3173472
While alex program still does show some unexpected behavior when it comes to create a shortcut where I want it it does at least create a shortcut, and I can always move it where I need it. Wrinting a piece of software deserves an "excellent" ranking though.

Armin
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
This code tracks birthdays 3 82
Regular Expression Calculator Tester 2 82
T-SQL:  Sigh---Boy, this is fun.... 12 57
Difference between List and Array in Python 5 94
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question