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).
1,075
questions
710
votes
24
answers
1.0m
views
"rm -rf" equivalent for Windows?
I need a way to recursively delete a folder and its children.
Is there a prebuilt tool for this, or do I need to write one?
DEL /S doesn't delete directories.
DELTREE was removed from Windows 2000+
135
votes
10
answers
135k
views
Windows XP or later Windows: How can I run a batch file in the background with no window displayed?
I know I have already answered a similar question (Running Batch File in background when windows boots up), but this time I need to launch a batch:
from another batch,
without any console window ...
93
votes
1
answer
95k
views
Difference between wscript and cscript
What is the difference between cscript and wscript? Which is best for doing Telnet and FTP automation in Windows?
90
votes
5
answers
300k
views
Can I pass an argument to a VBScript (vbs file launched with cscript)?
I have this script saved in "test.vbs":
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile(workFolder &"\test.txt", 2, True)
File.Write "testing"
File.Close
Set File = ...
38
votes
4
answers
66k
views
How do I set the timezone from command line ?
How can I set the timezone in Windows from command line or from a batch file?
Do I need to use powershell or cscript?
36
votes
3
answers
125k
views
how can I check if a file exists?
I want to check to see if a file exists and if it does, I want to open it and read the 1st line,
If the file doesn't exist or if the file has no contents then I want to fail silently without letting ...
33
votes
6
answers
118k
views
Base64 Encode String in VBScript
I have a web service load driver that's a Windows Script File (WSF), that includes some VBScript and JavaScript files. My web service requires that the incoming message is base64 encoded. I currently ...
26
votes
2
answers
65k
views
How can I download a file with batch file without using any external tools?
First to clarify this question is aimed to HTTP(s) download .For FTP may be I'll ask (and answer) another question.
Here are some similar questions - but I want to be more precise .
Besides ...
23
votes
5
answers
79k
views
Can I pick up environment variables in vbscript WSH script?
Is is possible to read system environment variables in a Windows Scripting Host (WSH) VBS script?
(I am writing a VBScript using Windows Scripting Host for task for a Cruise Control and want to pick ...
23
votes
6
answers
56k
views
Script to make content entry into a text file
How do I include some "text" into a .txt format file without opening the same via a script on Windows?
23
votes
3
answers
8k
views
What is the ProgId or CLSID for IE9's Javascript engine (code-named "Chakra")
Using .NET, I can write an app that hosts a scripting engine that complies with Microsoft's IActiveScript conventions. This includes JScript and VBScript from Microsoft, and also PerlScript, ...
21
votes
3
answers
69k
views
Is it possible to add a directory to DLL search path from a batch file or cmd script?
MSDN says that the function SetDllDirectory() can be used to insert a directory into the DLL Search Path. Can this function be accessed from a batch file or cmd script, perhaps using via cscript?
The ...
20
votes
5
answers
36k
views
Force a VBS to run using cscript instead of wscript
What is the stackoverflow approved (and hence correct) method to force a VBS to run using cscript instead of wscript - irrespective of what the user tries?
A quick Google search shows plenty of ...
20
votes
2
answers
14k
views
Should we use CScript.exe or WScript.exe to run .vbs files? [duplicate]
VBScript (.vbs) files can be run using either cscript.exe or wscript.exe.
What's the difference between these two options?
18
votes
7
answers
26k
views
Running Javascript with CScript?
I'm trying to learn how to run Javascript (instead of VBScript) using CScript.exe, but when I try, I get an error:
cscript temp.js
Input Error: There is no script engine for file extension ".js".
I ...
18
votes
3
answers
41k
views
What is the difference between CreateObject and Wscript.CreateObject?
Does anyone know the reasoning behind having the option using:
Wscript.CreateObject("some.object")
and
CreateObject("some.object")
within VBScript? when I find documentation or examples that use ...
17
votes
3
answers
10k
views
How can I create a javascript library in a separate file and "include" it in another?
First, a caveat. The main script is not run in a webpage. I will be running the .js file in Windows using Windows Script Host.
The problem:
I would like to create a javascript "library" containing a ...
15
votes
7
answers
52k
views
Get the Windows Download folder's path
I have some Excel VBA code that requires knowing the Downloads folder path. How could I do it?
Since you can move around the Downloads folder (and also Documents and most of those folders, via the ...
15
votes
2
answers
8k
views
How can I run a WSH script without seeing the Microsoft header?
When a .vbs script is run from the command line, it will by default show a Microsoft header:
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
...
15
votes
2
answers
15k
views
Prompt dialog in WSH using JScript?
How to open a prompt dialog box in WSH usig JScript??
The only pop-up dialog I've found in the doc is the WshShell.Popup() method. But I need a way to request the user to enter a string, like the ...
14
votes
5
answers
87k
views
VBScript getting results from Shell
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "runas ..."
How do I get the results and display in a MsgBox
14
votes
2
answers
28k
views
How can I write a simple JScript input/output program?
I'm planning on using JavaScript to enter an informatics competition (BIO) tomorrow. However, I can't rely on the examiner having a browser with a decent JavaScript engine, so I was hoping to use ...
13
votes
3
answers
9k
views
How to reference a JScript file from another one?
I am writing some server-side scripts using JScript and WSH. The scripts are getting quite long, and some common functions and variables would fit better in a general library script which I included ...
13
votes
5
answers
34k
views
Capturing output from WshShell.Exec using Windows Script Host
I wrote the following two functions, and call the second ("callAndWait") from JavaScript running inside Windows Script Host. My overall intent is to call one command line program from another. That ...
13
votes
3
answers
7k
views
Classic ASP amazon s3 rest authorisation
I am confused on what I am doing wrong here...
<script language="javascript" runat="server">
function GMTNow(){return new Date().toGMTString()}
</script>
<%
Const AWS_BUCKETNAME = "...
13
votes
4
answers
3k
views
How to get the associated icon of a file in HTA (HTML/Javascript/VBScript)
I'm building an HTA application in which I need to display a list of file with their associated system icon.
I'm using FileSystemObject to list the file but there seem to have no way to get the icon......
12
votes
3
answers
22k
views
cscript - print output on same line on console?
If I have a cscript that outputs lines to the screen, how do I avoid the "line feed" after each print?
Example:
for a = 1 to 10
WScript.Print "."
REM (do something)
next
The expected output ...
12
votes
1
answer
15k
views
passing arguments to javascript through cscript on the command line
I have a small command line JScript routine that I usually run from the command line using cscript in Windows. I'd like to be able to pass in arguments hopefully along the lines of...
%:>cscript ...
11
votes
3
answers
16k
views
cscript jscript JSON
This is a very very (very!!!) strange problem.
I have this JSCRIPT that runs on windows XP and 7 using dos CSCRIPT in a file called testJSON.js.
if ( ! this.JSON ) WScript.Echo("JSON DOESN'T EXISTS")...
11
votes
7
answers
54k
views
Send mail from a Windows script
I would like to send mail from a script on a Windows Server 2003 Standard Edition. I think the server setup is pretty much out of the box.
The mail server is an Exchange one, and when you're on the ...
10
votes
6
answers
9k
views
Advice for Windows XP Scripting, WSH versus PowerShell
After much experience scripting in the Unix/Linux open-source world, using languages such as Bourne Shell, Perl, Python, and Ruby, I now find myself needing to do some Windows XP administration ...
10
votes
2
answers
65k
views
Using VBScript to find most recent file date in a single folder
How could I modify this VBScript to return only the newest file's name and Last Modified date? Currently it returns anything modified in the last 24 hours. I want to look for the most recent file ...
10
votes
5
answers
33k
views
Display a message box with a timeout value
The question comes from code like this.
Set scriptshell = CreateObject("wscript.shell")
Const TIMEOUT_IN_SECS = 60
Select Case scriptshell.popup("Yes or No? leaving this window for 1 min is ...
10
votes
6
answers
60k
views
Failproof Wait for IE to load
Is there a foolproof way for the script to wait till the Internet explorer is completely loaded?
Both oIE.Busy and / or oIE.ReadyState are not working the way they should:
Set oIE = CreateObject("...
10
votes
2
answers
4k
views
How do I use jQuery in Windows Script Host?
I'm working on some code that needs to parse numerous files that contain fragments of HTML. It seems that jQuery would be very useful for this, but when I try to load jQuery into something like ...
9
votes
7
answers
34k
views
How to change cscript.exe to wscript.exe execution for all VBScript files?
After installing the new server, I am facing an issue.
I have lot of .vbs files, all need to run in wscript, reason, I use all those command like WScript.Echo "hello"
I want to be able to see the ...
9
votes
3
answers
11k
views
There's any way to run vbscript directly to wscript or cscript command line
I want to run a vbs command from command line as I would in batch calling
cmd.exe /c "echo.Hello World! & pause"
Obviously this doesn't work
wscript /C MsgBox("Hello world")
I could print the ...
9
votes
2
answers
8k
views
Create COM/ActiveXObject in C#, use from JScript, with simple event
I'd like to create a COM object in C#, and use it via IDispatch from JScript. That part is pretty simple.
I also want to implement simple callbacks on the COM object, similar to the event exposed by ...
9
votes
2
answers
1k
views
What is the %* or $* argument list equivalent for VBScript?
Is there a %* (batch files) or $* (bash script) argument list equivalent for VBScript ?
I want to retrieve the exact command line invocation.
Contrived example:
cscript //nologo script.vbs /arg1:...
9
votes
4
answers
12k
views
How can I save an MSXML2.DomDocument with indenting? (I think it uses MXXMLWriter)
I have an instance of MSXML2.DomDocument.
I wave to save it, with indenting.
This code works, but does not indent:
var dom = new ActiveXObject("MSXML2.DomDocument");
// fiddle with dom here
dom....
9
votes
1
answer
3k
views
Getting ActivePython to work with WSH
I've installed ActivePython 2.7.2 and I'm trying to execute a .pys script via the console with wscript/cscript, [i.e. ActivePython (PythonScript with .pys extension) in Microsoft's WSH(Windows ...
9
votes
3
answers
5k
views
Start excel from Task Scheduler was working, now fails
I've been running my excel 2000 vba program with Task Scheduler and cscript and vbscript for about a year now. A few days ago it stopped working. I can run the program manually. Whenever Task ...
9
votes
2
answers
822
views
Run a vb script using System.Diagnostics.Process but only partially successful in feeding in input text to the process' stdin
Edit: first things first
The point of the vbscript is to act like a REPL or command prompt/bash
environment, it is simplified to just reprinting the user input
So in other words the cscript process ...
9
votes
2
answers
16k
views
Scripting Git Commands in Windows
I have a few git commands I would like to automate in a restrictive windows environment. I find myself running these same commands over and over, executing in Git Bash.
$ git cd "R:/my/directory/...
8
votes
12
answers
7k
views
Getting my ip address
I have a computer on a small network, so my ip is 192.168.2.100.
I am trying to get my real ip. I download the no-ip client but that just seems like a lot of trouble for such a simple thing.
I ...
8
votes
3
answers
28k
views
Is it possible to change the automatic configuration script address in the LAN settings of Internet Explorer 8 with the help of a script?
I use 2 different automatic configuration script addresses in the LAN settings of Internet Explorer 8. During the course of my work, I need to switch between them very often. Every time I have to do ...
8
votes
2
answers
14k
views
WScript.Shell and blocking execution?
I'm using WScript to automate some tasks, by using WScript.Shell to call external programs.
However, right now it does not wait for the external program to finish, and instead moves on. This causes ...
8
votes
3
answers
81k
views
I need to write VBS WScript.Echo output to text or cvs
I am attempting to write a VBScript that will list all of the installed application on a system in a text file or csv. I was able to find an existing code to list all of the software (including name, ...
8
votes
3
answers
29k
views
How can I determine if a file is locked using VBS?
I am writing a VB Script to update some files on the network. Before beginning, I want to know if any of the files are locked. I'd like to do this before I actually do any updates.
I am aware that I ...
8
votes
1
answer
31k
views
CScript and VBS to Remove Line Breaks from Text File
I have a batch file running which spits out a text/html file. The batch file is causing some line breaks in the text file, which do not translate very well in opening the file in an email. I have ...