Jim Lawless' Blog


A Lightweight Alternative to Windows Shortcuts

Originally published on: Fri, 07 Aug 2009 00:35:49 +0000

Some time ago, I needed to provide a desktop shortcut for an application. Rather than using the normal shell API's to create a shortcut on the Windows desktop, I wondered if I could make an EXE tiny enough so that it was almost the same size as a typical shortcut.

I used this pet project as an excuse to learn a little about the Netwide Assembler (NASM32). I opted to use some of the Visual C++ 5.0 runtime libraries and linker, so my NASM code probably looks different than most you'll see elsewhere.

I wrote a small program that simply calls WinExec passing in "notepad.exe" as the argument.

The resulting EXE is about 2K in size ... bigger than most of my shortcuts, but a worthwhile effort. I had rewritten this so that it would work properly with a separate linker and had gotten the EXE down to a very tiny size. Unfortunately, I no longer have that source.


; A Lightweight Alternative to Windows Shortcuts
;
; License: MIT / X11
; Copyright (c) 2009 by James K. Lawless
; jimbo@radiks.net http://www.radiks.net/~jimbo
; http://www.mailsend-online.com
;
; Permission is hereby granted, free of charge, to any person
; obtaining a copy of this software and associated documentation
; files (the "Software"), to deal in the Software without
; restriction, including without limitation the rights to use,
; copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the
; Software is furnished to do so, subject to the following
; conditions:
;
; The above copyright notice and this permission notice shall be
; included in all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
; OTHER DEALINGS IN THE SOFTWARE.
;
   extern _WinExec@8
   global _main
   global _mainCRTStartup
   SECTION .text
_mainCRTStartup:
   push dword 1
   push dword child
   call _WinExec@8
   ret
_main:
   ret

   SECTION .data
child: db "notepad.exe",0

To assemble and link this program, I used the following batch file:


nasm -l %1.lst -f win32 %1.asm
link %1 /defaultlib:kernel32.lib

Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless



Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

stumbleupon Save to StumbleUpon
digg Digg it
reddit Save to Reddit
facebook Share on Facebook
twitter Share on Twitter
aolfav More bookmarks


Previous post: BSave and BLoad for the Commodore 64
Next post:Embedding JavaScript in a Batch File


About Jim ...


Click **here**
to try out MailWrench;
a command-line SMTP /
SMTPS (Google Gmail)
mailer for Windows.


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

A JavaScript REPL for Android Devices

MailSend is Free

My Blog Engine

The October 10th Bug

A Review of Kevin Mitnick's Book Ghost in the Wires

Spellbound by Web Programming

Backlinks to my Blog Posts

Play MP3 Files with Python on Windows


Random Posts

Rhino JavaScript to EXE with launch4j

Obfuscated Perl

Envy

Java in a Windows EXE with launch4j

A TCP Command Line Interface in Rhino JavaScript

An Embedded Mini-Interpreter

Flirting with Forth

An SMTP Server Simulator in Perl

Tracing XSLT with a Tiny Java Web Server

Understanding TRS-80 CMD Files


Full List of Posts

http://www.mailsend-online.com/bloglist.htm


Recent Posts from my Other Blog

Remembering Dr. San Guinary

Why Some Web Sites will go Dark on Jan 18th

SNL Superhero Skit

More Ruby Games

My Ruby Game Challenge Entry

Steal this Bookmarklet

Nerd Toys

Learn New Jargon, You Must

Spot the Wiebe

Tech Magazine Glory Days

Book Review : Paull Allen - Idea Man

A 90's Experiment in Online Systems - The U.S. West CommunityLink Service