Udostępnij za pośrednictwem


Save Method (Windows Script Host) 

Saves a shortcut object to disk.


object.Save 

Arguments

  • object
    WshShortcut or WshUrlShortcut object.

Remarks

After using the CreateShortcut method to create a shortcut object and set the shortcut object's properties, the Save method must be used to save the shortcut object to disk. The Save method uses the information in the shortcut object's FullName property to determine where to save the shortcut object on a disk. You can only create shortcuts to system objects. This includes files, directories, and drives (but does not include printer links or scheduled tasks).

Example

The following example demonstrates the use of a single .wsf file for two jobs in different script languages (VBScript and JScript). Each job creates a shortcut to the script being run and a URLshortcut to www.microsoft.com.

<package>

   <job id="vbs">

      <script language="VBScript">

         set WshShell = WScript.CreateObject("WScript.Shell")

         strDesktop = WshShell.SpecialFolders("Desktop")

         set oShellLink = WshShell.CreateShortcut(strDesktop & "\Shortcut Script.lnk")

         oShellLink.TargetPath = WScript.ScriptFullName

         oShellLink.WindowStyle = 1

         oShellLink.Hotkey = "CTRL+SHIFT+F"

         oShellLink.IconLocation = "notepad.exe, 0"

         oShellLink.Description = "Shortcut Script"

         oShellLink.WorkingDirectory = strDesktop

         oShellLink.Save

         set oUrlLink = WshShell.CreateShortcut(strDesktop & "\Microsoft Web Site.url")

         oUrlLink.TargetPath = "https://www.microsoft.com"

         oUrlLink.Save

      </script>

   </job>



   <job id="js">

      <script language="JScript">

         var WshShell = WScript.CreateObject("WScript.Shell");

         strDesktop = WshShell.SpecialFolders("Desktop");

         var oShellLink = WshShell.CreateShortcut(strDesktop + "\\Shortcut Script.lnk");

         oShellLink.TargetPath = WScript.ScriptFullName;

         oShellLink.WindowStyle = 1;

         oShellLink.Hotkey = "CTRL+SHIFT+F";

         oShellLink.IconLocation = "notepad.exe, 0";

         oShellLink.Description = "Shortcut Script";

         oShellLink.WorkingDirectory = strDesktop;

         oShellLink.Save();

         var oUrlLink = WshShell.CreateShortcut(strDesktop + "\\Microsoft Web Site.url");

         oUrlLink.TargetPath = "https://www.microsoft.com";

         oUrlLink.Save();

      </script>

   </job>

</package>

Applies To:

WshShortcut Object| WshUrlShortcut Object

See Also

Reference

FullName Property (WScript Object)
TargetPath Property
WindowStyle Property
Hotkey Property
IconLocation Property
Description Property (Windows Script Host)
WorkingDirectory Property (Windows Script Host)

Concepts

Running Your Scripts