How to create Shell Links on Windows?

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

···


(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))

Timon Christl wrote:

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


(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))

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

···


dc -e
4ddod3dddn1-89danrn10-dan3+ann6dan2an13dn1+dn2-dn3+5ddan2/9+an13nap

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

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/)

Chris
http://clabs.org/blogki

Anders Borch wrote:

Timon Christl wrote:


(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))

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

p is a predicate and thus itself a function. f takes the predicate and a
list x and applies p to each element of x. Those elements where p
returns true form the output of f. This means that f is nothing else
than a filter function.

An example call would be

f Odd x

where Odd would be a function that takes one integer argument and
returns 1 or 0, depending on wether the argument is odd or even.

To go back to the topic of this group, here is a 1:1 conversion of that
function to ruby (working on arrays as lists and using a Proc object for
the predicate):

def f(p,x)
if x== then

else
if p.call(x.first) then
return [x.first]+f(p,x[1…-1])
else
return f(p,x[1…-1])
end
end
end

f(Proc.new { |x| (x%2)==1 },[1,2,3,4,5])

···


(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))

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

···

----- Original Message -----
From: “Chris Morris” chrismo@clabs.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, July 07, 2003 9:12 AM
Subject: Re: How to create Shell Links on Windows?

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

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/)


Hal Fulton
hal9000@hypermetrics.com

Chris Morris wrote:

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

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.

···


(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))

Hal E. Fulton wrote:

I can’t answer your question – my eventual goal is
to know less about Windows, not more – but your

Me too. That’s why I’m using ruby. Porting ruby scripts will be much
easier than porting entire Delphi/C/C++ programs, and I will have to do
that one day for my personal collection of homemade tools.

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.

Yes I know about Apollo, but getting it to work with my trusty old
Delphi 3 could mean a bit of work, plus the code looked rather messy.
I’ve also tried to make my own binding (and even managed to define
ruby-callable classes and methods in Delphi, and call them), but I gave
it up later. Instead I wrote my own small OO language, which has the
same object model as ruby, but without the nifty stuff (modules, blocks,
mixins, continuations etc are all missing, but classes, meta-classs,
singleton methods are present) and of course with a much smaller class
library. It was roughly the same amount of work as creating a complete
binding to ruby, and much more fun (at least if you know how to write
compilers, which I do).

The problem is, I want to replace a small Delphi-written tool that is
only meant to be used on my home PC by a even smaller ruby script. It
would be a cleverly written one-liner if I use some of the usual unix
tools (ls, tail, sort and ln), but starting up a complete cygwin shell
takes a lot longer on my system than starting up a delphi executable (or
rubyw.exe).

···


(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))

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 :slight_smile: has some good reference
code.

···


Chris
http://clabs.org/blogki

Just thought I’d point out native Unix utils for win32. Windows
filesystems don’t support symlinking(ln) but the other tools work great.

http://unxutils.sourceforge.net/

Emiel

···

Hal E. Fulton wrote:

I can’t answer your question – my eventual goal is
to know less about Windows, not more – but your

Me too. That’s why I’m using ruby. Porting ruby scripts will be much
easier than porting entire Delphi/C/C++ programs, and I will have to do
that one day for my personal collection of homemade tools.

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.

Yes I know about Apollo, but getting it to work with my trusty old
Delphi 3 could mean a bit of work, plus the code looked rather messy.
I’ve also tried to make my own binding (and even managed to define
ruby-callable classes and methods in Delphi, and call them), but I gave
it up later. Instead I wrote my own small OO language, which has the
same object model as ruby, but without the nifty stuff (modules, blocks,
mixins, continuations etc are all missing, but classes, meta-classs,
singleton methods are present) and of course with a much smaller class
library. It was roughly the same amount of work as creating a complete
binding to ruby, and much more fun (at least if you know how to write
compilers, which I do).

The problem is, I want to replace a small Delphi-written tool that is
only meant to be used on my home PC by a even smaller ruby script. It
would be a cleverly written one-liner if I use some of the usual unix
tools (ls, tail, sort and ln), but starting up a complete cygwin shell
takes a lot longer on my system than starting up a delphi executable (or
rubyw.exe).


E F van de Laar
+31648183479
www.il.fontys.nl/~emiel

I assume you’re porting to Linux? I assume you know about Kylix?

···

on 7/8/03 1:24 PM, Timon Christl at me@christltimon.de wrote:

Hal E. Fulton wrote:
The problem is, I want to replace a small Delphi-written tool that is
only meant to be used on my home PC by a even smaller ruby script. It
would be a cleverly written one-liner if I use some of the usual unix
tools (ls, tail, sort and ln), but starting up a complete cygwin shell
takes a lot longer on my system than starting up a delphi executable (or
rubyw.exe).


Regards,
JJ

Finally using a Mac!

The above is a mistaken attribution. I was replying to
the OP, and someone replied to my reply. The paragraph
above was from one of those other people.

Hal

···

----- Original Message -----
From: “John Johnson” jj5412@earthlink.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, July 09, 2003 6:38 AM
Subject: Re: How to create Shell Links on Windows?

on 7/8/03 1:24 PM, Timon Christl at me@christltimon.de wrote:

Hal E. Fulton wrote:
The problem is, I want to replace a small Delphi-written tool that is
only meant to be used on my home PC by a even smaller ruby script. It
would be a cleverly written one-liner if I use some of the usual unix
tools (ls, tail, sort and ln), but starting up a complete cygwin shell
takes a lot longer on my system than starting up a delphi executable (or
rubyw.exe).

I assume you’re porting to Linux? I assume you know about Kylix?


Hal Fulton
hal9000@hypermetrics.com

John Johnson wrote:

Hal E. Fulton wrote:
The problem is, I want to replace a small Delphi-written tool that is
only meant to be used on my home PC by a even smaller ruby script. It
would be a cleverly written one-liner if I use some of the usual unix
tools (ls, tail, sort and ln), but starting up a complete cygwin shell
takes a lot longer on my system than starting up a delphi executable (or
rubyw.exe).

I assume you’re porting to Linux? I assume you know about Kylix?

No, I’m not porting to Linux. Windows users may use scripts to make life
easier, just as Linux users do, and that little Delphi program shall get
replaced by a even smaller ruby script because I don’t want to recompile
it after small changes (and these do occur from time to time, I’m too
lazy to write it in a more generic and configurable way, plus it would
not be a small tool anymore).

I’m looking forward to the day I can trash my Windows partition and use
only Linux (or maybe some flavour of BSD), but then I would not just
port my little tools, I would completely rewrite them. Until then I want
to get along with Windows as comfortable as possible, and Ruby is very
useful for that.

···

on 7/8/03 1:24 PM, Timon Christl at me@christltimon.de wrote:


(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))