Questions tagged [wsh]

For questions relating to Windows Script Host (WSH), a language-independent scripting host for the Windows operating system. It allows scripts to be run from both the graphical Windows desktop (via WScript.exe) and the command prompt (via CScript.exe).

Windows Script Host (sometimes abbreviated as WSH), in both Wscript.exe and Cscript.exe guises, can run VBScript (*.VBS, *.VBE) and JScript (*.JS, *.JSE), via Microsoft-provided script engines that are bundled with the OS and installed by default.

In addition to VBScript and JScript, there are third-party script engines for WSH that you can download to allow the use of Python, REXX, Perl, and other languages. (The script engines that add into WSH are distinct from standalone script interpreters that might exist for those languages, on Windows).

Multiple languages can be mixed in Windows Script Files (*.WSF). These types of scripts may also be used to link many other external scripts together using a src parameter on the <script> tag in a manner similar to HTML. A WSF makes reference to each script module in a very basic XML hierarchy and it's a package that can be organized in jobs.

Regardless of whether the UI is console-based or graphical, the same underlying script engine is used. In UI mode, the host is WScript.exe (used by default); in console mode, the host is CScript.exe.

The Windows Script Host has been part of every Microsoft Windows operating system's installation since Windows 98.

In 2006, Microsoft released v1.0 of Windows PowerShell, which could be conceived as a replacement for, or successor of, Windows Script Host. PowerShell is now included in every Windows OS. Even so, WSH is still included in every Windows OS, and many Wscript programs will continue to be in service, for many years.

References:

Related tags:

1078 questions
7
votes
2 answers

Run a bat file from javascript

I'm trying to run a bat file using javascript. I've tried using powershell but it didn't seem to work properly. Here is the code I tried: var oShell = WScript.CreateObject("WScript.Shell"); oShell.Exec("D:"); oShell.Exec("cd…
morha13
  • 1,847
  • 3
  • 21
  • 42
7
votes
1 answer

WScript.Shell Run gives "No application is associated with the specified file for this operation." when opening images.

I am facing an issue while trying to open an image file from a Silverlight app in Windows 10 using WScript.Shell. The code is as follows. try { dynamic shell = AutomationFactory.CreateObject("WScript.Shell"); …
7
votes
2 answers

Is it possible to pipe a script to WScript?

I would like to execute a simple VBScript/JScript generated by my application using the Windows Script Host (wscript.exe or cscript.exe) without generating a temporary script file. I did not find a command line option to read the script form the…
niks
  • 2,316
  • 1
  • 15
  • 15
7
votes
4 answers

How to find the window Title of Active(foreground) window using Window Script Host

I want to find the title of the window which is currently active(having focus) using Window Script Host(WSH) because I want my WSH script to Sendkeys only If the desired window is active. Note* I am not in a condition to use the alternative i.e…
7
votes
3 answers

Creating a scripting language

Can somebody please guide me in the right direction of creating a scripting language that targets the WSH (Windows Scripting Host)? I have googled for it, but there seem to be far fewer links related to this than when I originally searched for it a…
anon271334
7
votes
3 answers

Updating values from external workbook automatically

I have the following workbook setup: Workbook A has a link to x amount of workbook B's and fetches data from them. The workbooks B have links to some other workbooks and fetches data from them. Workbook A is a kind of "summary" of what all the…
John Snow
  • 5,214
  • 4
  • 37
  • 44
6
votes
3 answers

JScript Enumerator and list of properties

Consider the following WSH snippet: var query = GetObject("winmgmts:").ExecQuery("SELECT Name FROM Win32_Printer", "WQL", 0); var e = new Enumerator(query); for ( ; !e.atEnd(); e.moveNext ()) { var p = e.item(); WScript.Echo(p.Name + " ("…
Alexander Gromnitsky
  • 2,949
  • 2
  • 33
  • 38
6
votes
6 answers

CScript/WScript Prevent an error from being blocking

Currently, WScript pops up message box when there is a script error. These scripts are called by other processes, and are ran on a server, so there is nobody to dismiss the error box. What I'd like is for the error message to be dumped to STDOUT,…
FlySwat
  • 172,459
  • 74
  • 246
  • 311
6
votes
3 answers

Setting an environment variable in javascript

How can I set an environment variable in WSH jscript file that calls another program? Here's the reduced test case: envtest.js ---------- var oShell = WScript.CreateObject("WScript.Shell"); var oSysEnv =…
John Smith
  • 4,402
  • 4
  • 32
  • 34
6
votes
1 answer

Is There a Profiler for Windows Scripting Host Code?

Are there any profilers that can profile code that runs under WSH (VBScript, JavaScript, WSF)? Other than hand instrumenting with trace statements, what's a good way to profile code running under WSH?
Patrick Cuff
  • 28,540
  • 12
  • 67
  • 94
6
votes
3 answers

Visual Studio 2017 debugging vbscript

I'd like to debug a vbscript with Visual Studio 2017 Community Edition and followed the steps mentioned here for VS2015: Video I entered cscript.exe /x foo.vbs in the commandline, but no debugger starts. Is there a problem with the 2017th version…
steff123
  • 441
  • 1
  • 4
  • 10
6
votes
2 answers

How to pass an argument that starts with "//" to a wsh script?

If I have the following script (that just prints the first argument to the console): @if (@X)==(@Y) @end /* JScript comment @echo off cscript //E:JScript //nologo "%~f0" %* exit /b %errorlevel% @if (@X)==(@Y) @end JScript comment…
npocmaka
  • 55,367
  • 18
  • 148
  • 187
6
votes
1 answer

Is wsh a reserved word in VBScript?

On Windows 7, I get an error for the following line in my VBScript: Set wsh = WScript.CreateObject("WScript.Shell") Error: Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment: 'wsh' Using any name other…
Sabuncu
  • 5,095
  • 5
  • 55
  • 89
6
votes
3 answers

A .bat or .wsh script that can search for files

I am looking for some examples of a .bat OR .wsh script that can do the following: Recursively read file names in a directory with a user-provided extension (.dll, .exe, etc) Search a user-provided directory for the above file names Generate a txt…
chrome
  • 1,101
  • 2
  • 9
  • 12
6
votes
2 answers

How to use ANSI escape sequences with CSCRIPT on Windows 10?

I'm trying to use the new VT100 ANSI escape sequence capabilities available in the Windows 10 console with CSCRIPT (JScript). But I cannot get it to work. Here is a really simple JScript script: test.js WScript.Echo('\x1B[7mReverse\x1B[0m…
dbenham
  • 127,446
  • 28
  • 251
  • 390