home *** CD-ROM | disk | FTP | other *** search
/ Practical Windows/DOS 1999 November / PW48.ISO / WINMEDIC.ZIP / CreateShortcut.vbs < prev    next >
Encoding:
Text File  |  1999-07-11  |  1.5 KB  |  41 lines

  1. Option Explicit
  2.  
  3. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  4. ' This script shows how to use VBScript and the scripting host
  5. ' to create a desktop shortcut to Notepad and set hotkeys for it
  6. '
  7. ' Requirements: VBScript version 5
  8. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  9. 'Create some global variables
  10. Dim sMsg, sTitle, iResponse     'For message box
  11. Dim oShell, sPath, oShortcut    'For creating shortcut
  12. Dim sWindows, sNotepad        'Path to Windows directory and Notepad
  13.  
  14. sMsg = "Do you want to create a shortcut for " & _
  15.        "Notepad on your desktop?"
  16. sTitle = "Creating Shortcut"
  17. iResponse = MsgBox(sMsg, vbOKCancel + vbInformation, sTitle)
  18. If iResponse = vbCancel then
  19.     Wscript.Echo "Ending without creating shortcut"     
  20.     WScript.Quit
  21. End If
  22.  
  23. 'Create a shell object and use it to create a shortcut
  24. Set oShell = WScript.CreateObject("WScript.Shell")
  25. sPath = oShell.SpecialFolders("Desktop")
  26. Set oShortcut = oShell.CreateShortcut(sPath & "\New Notepad.lnk")
  27. sWindows = oShell.ExpandEnvironmentStrings("%windir%")
  28. sNotepad = sWindows & "\Notepad.exe"
  29. oShortcut.TargetPath = sNotepad
  30. oShortcut.WorkingDirectory = oShell.SpecialFolders("MyDocuments")
  31. oShortcut.WindowStyle = 1
  32. oShortcut.IconLocation = sNotepad & ",0"
  33. oShortcut.Hotkey = "ALT+CTRL+N"
  34. oShortcut.Description = "Shortcut created by a VBScript Program"
  35. oShortcut.Save
  36.  
  37. Set oShortcut = Nothing
  38. WScript.Echo "New shortcut to Notepad has been created"
  39. WScript.Quit
  40.  
  41.