Questions tagged [vbscript]

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic. VBScript is not the same thing as VBA or VB.NET. They are three different things, so use the correct tags.

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic.

VBScript is commonly used for automating administrative and other tasks in the Windows operating systems (via Windows Script Host --) and for server-side scripting in web applications. It can also used for client-side scripting in (not other browsers), but is generally used for this purpose only in intranet web applications, where the browser can be limited to IE. VBScript is also the language used to create custom Outlook forms ().

Although VBScript has much common syntax with VBA, do not tag questions as unless you are specifically asking about both. It is also completely different than VB.NET.

Some differences between VBScript and VBA:

  • Does not support enumerated constants; replace with the numeric value:

    'VBScript
    Outlook.CreateItem(0)
    
    'VBA allows this:
    Outlook.CreateItem(olMailItem)
    
  • All variables are of type Variant, and are declared without a type specification:

    'VBScript
    Dim olApp  
    Dim msg
    
    'VBA allows this:
    Dim olApp As Outlook.Application  
    Dim msg As Outlook.MailItem
    
  • Method calls don't support named arguments.

    'VBScript
    wb.SaveAs "output.csv", 6, , , , False
    
    'VBA allows this:
    wb.SaveAs FileName:="output.csv", FileFormat:=xlCSV, CreateBackup:=False
    

Executing VBScripts with WSH -- WScript/CScript

VBScript can be executed locally either in GUI mode, in which output is displayed as a window:

wscript.exe C:\Script\Location\script.vbs

or in console mode, in which input is read from and written to a console window.

cscript.exe C:\Script\Location\script.vbs

Running wscript.exe or cscript.exe without specifying the path will run the script in the machine's architecture -- 32-bit on 32-bit machines, and 64-bit on 64-bit machines. On 64-bit machines, it is possible to have the script run in the 32-bit emulation layer:

C:\windows\SysWOW64\wscript.exe  C:\Script\Location\script.vbs
C:\windows\SysWOW64\cscript.exe  C:\Script\Location\script.vbs

Note: Scheduled VBScript tasks must be run with cscript.exe because computer/domain policies limit activation of GUI applications when no user is logged on.

Debugging scripts

Visual Studio (Community Edition, or the Integrated Shell of pre-2013 versions) can be used to step through scripts and locate errors.

  • //X will trigger the debugger if there is a runtime error, or a code breakpoint
  • //D will trigger the debugger at the beginning of the script

No variable expansion
Like other languages in the Visual Basic family, VBScript does not expand variables inside string literals, so in code like

var1 = "fox"
var2 = "The quick brown var1 jumps over the lazy dog."

the value of var2 will remain The quick brown var1 jumps over the lazy dog. instead of becoming The quick brown fox jumps over the lazy dog. To get the value of a variable in a string, the variable must be concatenated with the rest of the string:

var1 = "fox"
var2 = "The quick brown " & var1 & " jumps over the lazy dog."

Frequently Asked Questions

Resources

Related Tags

18718 questions
3
votes
1 answer

How to traverse subfolders in a zip file and unzip files with specific extension?

Basically I'm trying to unzip some specific files in a zip file (there are lots of junk subfolders in it). The thing is only the last subfolder contains files I want. Other subfolders won't contain any files except another subfolder. Here is the…
nwpulele
  • 211
  • 3
  • 12
3
votes
1 answer

Variable in For Loop Retains Old Value

I have a program that reads hostnames from a txt file, it scans the network for the hostname and then it displays the hostname and its respective Windows Operating system (CAPTION). I am trying to get all Windows XP machines upgraded to Windows 7. …
TTS Tech
  • 31
  • 1
3
votes
1 answer

How to pass an array from VBScript to JavaScript?

I have a webpage where I am fetching the name of files in a Folder into an array using VBScript, then I am passing that array to JavaScript variable, so that I can display the names on the screen. VBScript Code: Function allFiles() Dim arr,…
Ejaz
  • 1,504
  • 3
  • 25
  • 51
3
votes
1 answer

Make VBScript check for a file with a certain word in it's file name and then find and delete that file

I was wondering if there is a way to make it so my vbs script can check for and delete any files with a certain word in it's name. This is what I have so far: x=MsgBox ("Searching for any infected files...",64,"Search") DIM filesys Set filesys =…
3
votes
3 answers

VBScript - copy files modified in last 24 hours

I'm trying to copy files from a directory where the last modified date is within 24hours of the current date. I'm using a wildcard in the filepath as it changes every day I'm using; option explicit dim fileSystem, folder, file dim path path =…
Martin North
  • 31
  • 1
  • 1
  • 2
3
votes
1 answer

VBScript Regular Expressions to check IP address validity with some adtional characters

How to create VB script Irregular expression syntax to check the VPparam (IP address validity) When the last octatat of the IP address is a range between ip's (x-y) and between each IP we can put the "," separator in order to add another IP example…
yael
  • 2,765
  • 10
  • 40
  • 48
3
votes
2 answers

What's the correct way to pass parameters from VBScript to COM interface implemented in C#?

I'm trying to expose a fairly simple C# class to COM which should be usable from VBScript (among others). Some objects need to be created via COM calls and will be used in furter calls later on. The definition of the exposed classes and interfaces…
nopopem
  • 81
  • 5
3
votes
1 answer

Kill explorer.exe with windows title

I'm new with programing and my question is now, how i can close some specific explorer.exe windows. My Problem is, i have a program that call some windows: Option Explicit Dim shell, expl1, expl2, expl3, Terminate Dim uprgExplorer set shell =…
Sebastian
  • 494
  • 5
  • 18
  • 34
3
votes
2 answers

How to get line error from subroutines that are read in or referenced via ReadAll via VBS?

Hello a client of mine has a lot of VBSripts (VBS) that do various things. At the top of each script they reference a library of subs and functions like this: Const ForReading = 1 Dim objFSO, objFile Set objFSO =…
mountainclimber11
  • 1,339
  • 1
  • 28
  • 51
3
votes
2 answers

Compiling classic ASP files

I've inherited a classic ASP application written in VBScript. I don't have experience with either. I am using Visual Studio 2013 as my development environment. Please can you let me know whether it is possible to pre-compile ASP files? I just want…
aw1975
  • 1,669
  • 3
  • 20
  • 35
3
votes
2 answers

VBScript - Increasing a variable's value

I have the following: firstDate = InputBox("Insert the first report's date desired to obtain", "Report Information - Start", "YYYY-MM-DD") So the user inserts the date, lets say: 2015-04-17 I am trying to find a way by which I can increase the…
F0l0w
  • 243
  • 5
  • 15
3
votes
2 answers

Using Excel as log reader. How to write to log file if Excel has it open?

I've come into a position where all the existing scheduled applications write their logs to .CSV files, so that people can open them in Excel. The problem comes when someone opens a log file and just leaves it open. The applications then can't…
royatl
  • 336
  • 1
  • 7
3
votes
3 answers

Enable/disable windows-update from a vbscript

I need to disable windows-update service from my installation. I already use vbscript to do some stuff so I would like to do it in vbscript. My knowledge of vbscript (or any other script language) is very limited so...can anybody help me out with…
Javier De Pedro
  • 2,219
  • 4
  • 32
  • 49
3
votes
2 answers

Reading all rows of a specific column in excel with VB Script

I have a spreadsheet that has all of our customer information. So we have Customer 1,2,3,4,5 and each customer has an EMAIL_ADDRESS column with one or more email addresses. I need to read all of those addresses and output them in some form or…
Alaxander
  • 31
  • 1
  • 1
  • 2
3
votes
2 answers

list of intrinsic constants

Where can I find a complete list of the intrinsic constants in VBScript (like vbCrLf and vbTab)?
JoelFan
  • 37,465
  • 35
  • 132
  • 205
1 2 3
99
100