home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / wsh.cab / shortcut.js < prev    next >
Text File  |  1997-09-16  |  2KB  |  62 lines

  1. // Windows Script Host Sample Script
  2. //
  3. // ------------------------------------------------------------------------
  4. //               Copyright (C) 1996-1997 Microsoft Corporation
  5. //
  6. // You have a royalty-free right to use, modify, reproduce and distribute
  7. // the Sample Application Files (and/or any modified version) in any way
  8. // you find useful, provided that you agree that Microsoft has no warranty,
  9. // obligations or liability for any Sample Application Files.
  10. // ------------------------------------------------------------------------
  11.  
  12.  
  13. // This sample demonstrates how to use the WSHShell object to create a shortcut
  14. // on the desktop.
  15. var vbOKCancel = 1;
  16. var vbInformation = 64;
  17. var vbCancel = 2;
  18.  
  19. var L_Welcome_MsgBox_Message_Text   = "This script will create a shortcut to Notepad on your desktop.";
  20. var L_Welcome_MsgBox_Title_Text     = "Windows Scripting Host Sample";
  21. Welcome();
  22.  
  23. // ********************************************************************************
  24. // *
  25. // * Shortcut related methods.
  26. // *
  27.  
  28. var WSHShell = WScript.CreateObject("WScript.Shell");
  29.  
  30.  
  31. // Read desktop path using WshSpecialFolders object
  32. var DesktopPath = WSHShell.SpecialFolders("Desktop");
  33.  
  34. // Create a shortcut object on the desktop
  35. var MyShortcut = WSHShell.CreateShortcut(DesktopPath + "\\Shortcut to notepad.lnk");
  36.  
  37. // Set shortcut object properties and save it
  38. MyShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings("%windir%\\notepad.exe");
  39. MyShortcut.WorkingDirectory = WSHShell.ExpandEnvironmentStrings("%windir%");
  40. MyShortcut.WindowStyle = 4;
  41. MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings("%windir%\\notepad.exe, 0");
  42. MyShortcut.Save();
  43.  
  44. WScript.Echo("A shortcut to Notepad now exists on your Desktop.");
  45.  
  46. //////////////////////////////////////////////////////////////////////////////////
  47. //
  48. // Welcome
  49. //
  50. function Welcome() {
  51.     var WSHShell = WScript.CreateObject("WScript.Shell");
  52.     var intDoIt;
  53.  
  54.     intDoIt =  WSHShell.Popup(L_Welcome_MsgBox_Message_Text,
  55.                               0,
  56.                               L_Welcome_MsgBox_Title_Text,
  57.                               vbOKCancel + vbInformation );
  58.     if (intDoIt == vbCancel) {
  59.         WScript.Quit();
  60.     }
  61. }
  62.