How to create Shell Links on Windows?

T

Timon Christl

Is there an easy way to create or modify shell links (.lnk) with ruby on
windows? I know how to do that in C/C++ or Delphi, and I know that there
is a scripting object named ShellLinkObject.Application that could be
used by scripting languages (=>ruby, via the winole module), but
unfortunately it is only available on Win2000 or XP because these have a
newer version of the windows shell (5.00 as opposed to 4.71).
 
A

Anders Borch

Timon said:
Is there an easy way to create or modify shell links (.lnk) with ruby on
windows? I know how to do that in C/C++ or Delphi, and I know that there
is a scripting object named ShellLinkObject.Application that could be
used by scripting languages (=>ruby, via the winole module), but
unfortunately it is only available on Win2000 or XP because these have a
newer version of the windows shell (5.00 as opposed to 4.71).

sorry I cannot help you ou there... also I cannot figure out your sig...
what parameters am I supposed to give to f?
 
H

Hal E. Fulton

----- Original Message -----
From: "Chris Morris" <[email protected]>
To: "ruby-talk ML" <[email protected]>
Sent: Monday, July 07, 2003 9:12 AM
Subject: Re: How to create Shell Links on Windows?

The following depends on the Windows Scripting Host to be installed, but
this should exist on most systems by now:

def create_shortcut(targetFileName, linkName)
shell = WIN32OLE.new("WScript.Shell")
scut = shell.CreateShortcut(linkName + '.lnk')
scut.TargetPath = File.expand_path(targetFileName)
scut.Save
scut
end

(btw, this is included in my rag-tag util lib you can get here:
http://www.clabs.org/dl/clutil/)

I can't answer your question -- my eventual goal is
to know less about Windows, not more -- but your
mention of Delphi caught my eye. I haven't really
touched Delphi in years, but I was always impressed
by it.

I assume you know about the Ruby/Delphi bridge that
someone has made? I think it's called Apollo... I can't
quite remember the author, but it's in the RAA.

When I tested it out, I was very impressed with it. And
offhand I'd say it's possible that if Delphi exposes
some bit of functionality, then Apollo might very likely
expose that same bit to Ruby.

Cheers,
Hal
 
T

Timon Christl

Chris said:
The following depends on the Windows Scripting Host to be installed, but
this should exist on most systems by now:

def create_shortcut(targetFileName, linkName)
shell = WIN32OLE.new("WScript.Shell")
scut = shell.CreateShortcut(linkName + '.lnk')
scut.TargetPath = File.expand_path(targetFileName)
scut.Save
scut
end

I do not intend to surrender to the evil Windows Scripting Host, thus
this solution is not applicable for me. My home PC with Win98SE does not
have WSH installed, never had, and never will.

The tool in question where I need to create Win23 shell links is a small
Delphi-written tool which scans a directory tree for subdirectories with
a certain naming scheme, creates a new directory, the name of which is
derived from the results of the search, and finally (re)creates a shell
link named "Latest" pointing to that newly created directory. It is a
tool purely for private use, and one day I thought it would be nice if
that program was a ruby script instead of a Delphi-compiled .exe, so I
ran into the problem of how to create links.
 
C

Chris Morris

I do not intend to surrender to the evil Windows Scripting Host, thus
this solution is not applicable for me. My home PC with Win98SE does not
have WSH installed, never had, and never will.

Then I guess your other option is to check out WIN32API and call the same
stuff in the Shell.dll (whatever it's actually called) directly. I'm sure
the ShellApi.pas (whatever it's actually called :) has some good reference
code.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top