Windows Shortcuts

  • Thread starter Mehr, Assaph (Assaph)
  • Start date
M

Mehr, Assaph (Assaph)

Hi All,

Does anyone know how to programmatically create windows shortcuts (.lnk
files) using Ruby?
Have been googling for a couple of days without much luck.


Cheers,
Assaph

________________________________
Assaph Mehr
Email: (e-mail address removed)
Phone: +61-2-9352 9247
Auslabs (Avaya Labs Australia)
_______________________________
 
C

Chris Morris

Mehr said:
Hi All,

Does anyone know how to programmatically create windows shortcuts (.lnk
files) using Ruby?
Have been googling for a couple of days without much luck.
This is a method that depends on the Windows Scripting Host being
installed, which it is by default on 2k and XP, I believe ... possibly
others, but I don't know for sure.

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

The method returns the scut instance because there are other things you
can do with it that this default method glosses over. This method is
apart of my anemic clUtil lib (BSD license) you can get here:
http://www.clabs.org/dl/clutil/ (see also http://www.clabs.org/ruby.htm).
 
S

Shashank Date

=begin

Hi Assaph,

How about this?

Mehr said:
Does anyone know how to programmatically create windows shortcuts (.lnk
files) using Ruby?

=end
require 'win32ole'

shell = WIN32OLE.new("WScript.Shell")

# Desktop shortcut
strDesktop = shell.SpecialFolders("Desktop")
oShellLink = shell.CreateShortcut(strDesktop + "\\Shortcut Script.lnk")
oShellLink.TargetPath = "c:\\atest\\tst_shortcut.rb" #WScript.ScriptFullName
oShellLink.WindowStyle = 1
oShellLink.Hotkey = "CTRL+SHIFT+F"
oShellLink.IconLocation = "notepad.exe, 0"
oShellLink.Description = "Shortcut Script"
oShellLink.WorkingDirectory = strDesktop
oShellLink.Save

# URL shortcut
oUrlLink = shell.CreateShortcut(strDesktop + "\\Rubyforge.url")
oUrlLink.TargetPath = "http://rubyforge.org/"
oUrlLink.Save

__END__
 

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,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top