Show/Hide Toolbars

EmEditor Help

Navigation: EmEditor Help > Macro Reference > Tutorial

EmEditor Macro Reference: Create a Shortcut

Scroll Prev Top Next More
EmEditor Home - EmEditor Help - EmEditor Macro Reference - Tutorial

Create a Shortcut

To create a shortcut, use the CreateShortcut Method of a WshShell Object.

The following example code creates a shortcut on the desktop to an opened file.

[JavaScript]

if( document.FullName == "" ) {

   alert( "The file is untitled." );

}

else {

   WshShell = new ActiveXObject( "WScript.Shell" );

   strDesktop = WshShell.SpecialFolders("Desktop");

   oShellLink = WshShell.CreateShortcut(strDesktop + "\\Shortcut to My File.lnk");

   oShellLink.TargetPath = document.FullName;

   oShellLink.WindowStyle = 1;

   oShellLink.Description = "Shortcut to My File";

   oShellLink.WorkingDirectory = strDesktop;

   oShellLink.Save();

}

[VBScript]

If document.FullName = "" Then

   alert "The file is untitled."

Else

   Set WshShell = CreateObject( "WScript.Shell" )

   strDesktop = WshShell.SpecialFolders("Desktop")

   set oShellLink = WshShell.CreateShortcut(strDesktop & "\Shortcut to My File.lnk")

   oShellLink.TargetPath = document.FullName

   oShellLink.WindowStyle = 1

   oShellLink.Description = "Shortcut to My File"

   oShellLink.WorkingDirectory = strDesktop

   oShellLink.Save

End If

References

g Microsoft MSDN Library: CreateShortcut Method

Copyright © 2003-2016 by Emurasoft, Inc.