WSF/SHELL - MACRO
SCRIPT: CreaLink.wsf

<package>
<job id="vbs">
<?job error="true" debug="true" ?>
<reference object="Excel.Sheet" reference="true"/>
<script language="VBScript">
   ' Crea un link alla calcolatrice di sistema
   set WshShell = WScript.CreateObject("WScript.Shell")
   strDesktop = WshShell.SpecialFolders("Desktop")
   set WshSysEnv = WshShell.Environment("SYSTEM")
   set oShellLink = WshShell.CreateShortcut(strDesktop & "\Sechi Link.lnk")
   oShellLink.TargetPath = WshSysEnv("WINDIR") & "\system32\calc.exe"
   oShellLink.WindowStyle = 1
   oShellLink.Hotkey = "CTRL+ALT+SHIFT+C"
   oShellLink.IconLocation = "calc.exe, 0"
   oShellLink.Description = "Wsf Shortcut"
   oShellLink.WorkingDirectory = strDesktop
   oShellLink.Save

   ' Crea un link a www.brescianet.com
   set oUrlLink = WshShell.CreateShortcut(strDesktop & "\www.bresciaNet.com.url")
   oUrlLink.TargetPath = "http://www.brescianet.com"
   oUrlLink.Save

   wscript.echo ">> Creati sul desktop i link a www.brescianet.com e alla calcolatrice"
</script>
</job>
</package>

Oppure in forma VBScript

VBScript: CreaLink.vbs

   ' Crea un link alla calcolatrice di sistema
   set WshShell = WScript.CreateObject("WScript.Shell")
   strDesktop = WshShell.SpecialFolders("Desktop")
   set WshSysEnv = WshShell.Environment("SYSTEM")
   set oShellLink = WshShell.CreateShortcut(strDesktop & "\Sechi Link.lnk")
   oShellLink.TargetPath = WshSysEnv("WINDIR") & "\system32\calc.exe"
   oShellLink.WindowStyle = 1
   oShellLink.Hotkey = "CTRL+ALT+SHIFT+C"
   oShellLink.IconLocation = "calc.exe, 0"
   oShellLink.Description = "Wsf Shortcut"
   oShellLink.WorkingDirectory = strDesktop
   oShellLink.Save

   ' Crea un link a www.brescianet.com
   set oUrlLink = WshShell.CreateShortcut(strDesktop & "\www.brescianet.com.url")
   oUrlLink.TargetPath = "http://www.brescianet.com"
   oUrlLink.Save

   wscript.echo ">> Creati sul desktop i link a www.brescianet.com e alla calcolatrice"

I files ".wsf" sono molto simili ai vbs, ma permettono di fare anche altre cose. Ad esempio permettono di includere le librerie esterne e di far convivere parti di programma scritte in vbscript e in jscript. E' possibile quindi collegarsi ad un oggetto non solo alle sue proprietà e ai suoi metodi ma anche condividendo la sua libreria di costanti. Per farlo basta aggiungere un REFERENCE="TRUE" quando si specifica l'oggetto da istanziare.
Ad esempio lo script wsf

<package>
   <job id="CostantiExcel">
      <?job error="true" debug="true" ?>
      <reference object="Excel.Sheet" reference="true"/>
      <script language="VBScript">
         WScript.Echo "xlUp = " & eval("xlUp")
         WScript.Echo "xlLeft = " & eval("xlLeft")
         WScript.Echo "xlRight = " & eval("xlRight")
         WScript.Echo "xlDown = " & eval("xlDown")
      </script>
   </job>
</package>

fornisce il seguente output:



mentre il corrispondente script vbs

  WScript.Echo "xlUp = " & eval("xlUp")
  WScript.Echo "xlLeft = " & eval("xlLeft")
  WScript.Echo "xlRight = " & eval("xlRight")
  WScript.Echo "xlDown = " & eval("xlDown")

non riesce a valorizzare le costanti indicate come si vede dal seguente output:

ESEMPIO ESECUZIONE

Eseguendo lo script ...



vengono creati sulla scrivania i due link in figura