Advertisement
jcunews

Shortcut.vbs

Mar 25th, 2019 (edited)
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub help
  2.   wscript.echo "shortcut [options] {shortcut file} {target [arguments...]}" _
  3.     & vbcrlf & "Options:" & vbcrlf _
  4.     & "/dir {path}       Set working directory." & vbcrlf _
  5.     & "/desc {str}       Set description." & vbcrlf _
  6.     & "/hk {str}         Set hotkey. e.g.: ctrl+alt+f9" & vbcrlf _
  7.     & "/icon {path,num}  Set icon. e.g.: d:\dir\file.dll,-2" & vbcrlf _
  8.     & "/show {num}       Set show mode. 0=normal, 3=maximized, 7=minimized"
  9.   wscript.quit 1
  10. end sub
  11.  
  12. if wscript.arguments.count < 2 then help
  13. scf = ""
  14. tgt = ""
  15. arg = ""
  16. dir = empty
  17. desc = empty
  18. hk = empty
  19. icon = empty
  20. show = empty
  21. i = 0
  22. do while i < wscript.arguments.count
  23.   s = wscript.arguments(i)
  24.   if scf = "" then
  25.     if left(s, 1) = "/" then
  26.       s = ucase(mid(s, 2))
  27.       if s = "DIR" then
  28.         i = i + 1
  29.         if i >= wscript.arguments.count then help
  30.         dir = wscript.arguments(i)
  31.       elseif s = "DESC" then
  32.         i = i + 1
  33.         if i >= wscript.arguments.count then help
  34.         desc = wscript.arguments(i)
  35.       elseif s = "HK" then
  36.         i = i + 1
  37.         if i >= wscript.arguments.count then help
  38.         hk = wscript.arguments(i)
  39.       elseif s = "ICON" then
  40.         i = i + 1
  41.         if i >= wscript.arguments.count then help
  42.         icon = wscript.arguments(i)
  43.       elseif s = "SHOW" then
  44.         i = i + 1
  45.         if i >= wscript.arguments.count then help
  46.         show = wscript.arguments(i)
  47.       else
  48.         help
  49.       end if
  50.     else
  51.       scf = s
  52.     end if
  53.   elseif tgt = "" then
  54.     tgt = s
  55.   else
  56.     if (instr(s, " ") > 0) or (instr(s, "&") > 0) or (instr(s, "|") > 0) or (instr(s, ">") > 0) or (instr(s, "<") > 0) then s = """" & s & """"
  57.     if arg = "" then
  58.       arg = s
  59.     else
  60.       arg = arg & " " & s
  61.     end if
  62.   end if
  63.   i = i + 1
  64. loop
  65. if (scf = "") or (tgt = "") then help
  66.  
  67. set fs = createobject("scripting.filesystemobject")
  68. if fs.fileexists(tgt) then
  69.   tgt = fs.getfile(tgt).path
  70. elseif fs.folderexists(tgt) then
  71.   tgt = fs.getfolder(tgt).path
  72. end if
  73. set sc = createobject("wscript.shell").createshortcut(scf)
  74. sc.targetpath = tgt
  75. sc.arguments = arg
  76. if dir <> empty then sc.workingdirectory = dir
  77. if hk <> empty then sc.hotkey = hk
  78. if show <> empty then sc.windowstyle = show
  79. if desc <> empty then sc.description = desc
  80. if icon <> empty then sc.iconlocation = icon
  81. sc.save
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement