WshShell Object
Provides access to the native Windows shell.
You create a WshShell object whenever you want to run a program locally, manipulate the contents of the registry, create a shortcut, or access a system folder. The WshShell object provides the Environment collection. This collection allows you to handle environmental variables (such as WINDIR, PATH, or PROMPT).
The following example demonstrates the creation of a shortcut to the script being run and a URL shortcut to 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
</script>
</job>
<job id="js">
<script language="JScript">
var WshShell = WScript.CreateObject("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();
</script>
</job>
</package>
Article is correct. D.Read is incorrect - there is no typo
The poster above stating that ' var WshShell = ... ' is not JScript is incorrect.
$0
$0 var WshShell = WScript.CreateObject("WScript.Shell");$0
$0
$0This is valid javascript/JScript, and it has proven to work as a WSH script on my installation of Windows 7.$0
$0
$0WScript is a global object with the CreateObject method which should be used to access COM objects.$0
$0
- 5/1/2012
- F Yip
typo in JScript example
The JScript example contains this line:
That is VBScript not JScript (obviously a simple copy and paste error and lack of QA).
Should be corrected with "new ActiveXObject"
var WshShell = WScript.CreateObject("WScript.Shell");
That is VBScript not JScript (obviously a simple copy and paste error and lack of QA).
Should be corrected with "new ActiveXObject"
- 4/24/2012
- Derek Read