WScript, objet

Expose des propriétés qui fournissent le chemin d'accès de l'hôte de script en cours d'exécution (WScript.exe ou cscript.exe), ses arguments, ainsi que le mode de travail (interactif ou par lots). L'objet WScript fournit également des méthodes pour créer et lire des objets.

Exemple

L'exemple suivant illustre l'utilisation d'un fichier .wsf unique pour deux tâches dans différents langages de script (VBScript et JScript). La fonctionnalité de ces deux tâches est identique : chacune crée un raccourci pointant vers le script en cours d'exécution et un raccourci d'URL pointant vers 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 = "Raccourci script"
   oShellLink.WorkingDirectory = strDesktop
   oShellLink.Save

   set oUrlLink = WshShell.CreateShortcut(strDesktop & "\Microsoft Web Site.url")
   oUrlLink.TargetPath = "http://www.microsoft.com"
   oUrlLink.Save
</script>
</job>

<job id="js">
<script language="javascript">
   var WshShell = new ActiveXObject("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 = "Raccourci script";
   oShellLink.WorkingDirectory = strDesktop;
   oShellLink.Save();

   var oUrlLink = WshShell.CreateShortcut(strDesktop + "\\Microsoft Web Site.url");
   oUrlLink.TargetPath = "http://www.microsoft.com";
   oUrlLink.Save();
</script>
</job>

</package>

Pour plus d'informations, reportez-vous à la rubrique Exécution de vos scripts.

Propriétés

Application, propriété | Arguments, propriété | FullName, propriété | Name, propriété | Path, propriété | ScriptFullName, propriété | ScriptName, propriété | StdErr, propriété | StdIn, propriété | StdOut, propriété | Version, propriété

Méthodes

CreateObject, méthode | ConnectObject, méthode | DisconnectObject, méthode | Echo, méthode | GetObject, méthode | Quit, méthode | Sleep, méthode

Voir aussi

WshShell, objet