WScript 对象

该对象的属性可以提供正在运行的脚本宿主 (WScript.exe 或 cscript.exe) 的路径、参数以及工作模式(交互式或批处理)。WScript 对象还提供了创建和读取对象的方法。

示例

下例演示了如何在两个使用不同脚本语言(VBScript and JScript)的任务中使用同一个 .wsf 文件。这两个任务的功能相同——创建一个快捷方式,指向当前执行的脚本;一个 URL 快捷方式,指向 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 = "Shortcut 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 = "Shortcut 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>

详细信息请参阅:运行脚本

属性

Application 属性 | Arguments 属性 | FullName 属性 | Name 属性 | Path 属性 | ScriptFullName 属性 | ScriptName 属性 | StdErr 属性 | StdIn 属性 | StdOut 属性 | Version 属性

方法

CreateObject 方法 | ConnectObject 方法 | DisconnectObject 方法 | Echo 方法 | GetObject 方法 | Quit 方法 | Sleep 方法

请参阅

WshShell 对象