Solved

Create Shortcut File (LNK) via command line

Posted on 2000-04-24
14
11,082 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 15

Expert Comment

by:simonet
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I'll take a look at it and get back to you.

Yours,

Alex
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Author Comment

by:arminl
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Answer accepted
0
 
LVL 4

Author Comment

by:arminl
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now