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
2 answers

How to get an HTA to restart itself?

I have an HTML Application that I am using to build a kiosk environment. At the end of every session (when the user clicks "Logout" or after a timeout) I want the HTA to close itself and restart*. I was wondering how I would go about achieving this…
Iain Fraser
  • 6,578
  • 8
  • 43
  • 68
3
votes
2 answers

How to edit the html from ASP in a better way?

Hello I have an ASP script that I need to edit. Actually I need to restyle the email that it sends, so I need to edit the HTML from it. The problem is the html (from the asp file) has on every row HTML = HTML & =" in it (plus some other changes).…
Mike
  • 81
  • 1
  • 5
3
votes
0 answers

StdIn.Writeline Fails in ASP sending strings to PowerShell

I am updating a Classic ASP webpage. It seems that if you try to use StdIn.Writeline to send command to PowerShell it fails. It behaves like the command interpreter only accepts commands as part of creating the session. Does anyone have any working…
Cynomus
  • 39
  • 4
3
votes
2 answers

Do I need "cmd /c"?

I've seen two different ways of calling icacls from VBScript: oShell.Exec("icacls ... or oShell.Exec("%COMSPEC% /c Echo Y| icacls ... What's the difference?
kgh
  • 157
  • 1
  • 12
3
votes
1 answer

PayPal Sandbox Blocks WinHTTP.WinHTTPRequest.5.1

paypalfunctions.asp and expresscheckout.asp files I'm hoping to find help, and if not help then a developer for hire who is proficient in Classic ASP and PayPal and can help me resolve this. We have a Windows 2008 R2 Server running Classic ASP. We…
Steve
  • 75
  • 1
  • 9
3
votes
3 answers

Press Enter Key in qtp

How to perform the Pressing of Enter Action in QTP. I'm selecting a cell and able to set a value ,now I want to press enter key and get the list from that Java Edit box. Which are the different ways I can achieve this?
Sam
  • 543
  • 3
  • 10
  • 27
3
votes
1 answer

Convert VBA to VBScript

I'm copying data form one workbook to another workbook and then run a macro from the copied workbook. The below VBA code works fine. VBA Code Sub test() Dim x As Workbook Dim y As Workbook Set x =…
Sivaprakash
  • 455
  • 1
  • 8
  • 22
3
votes
2 answers

VBScript object required

Option Explicit Dim output, ProxyEnable, ProxyServer, wshShell, doc Sub Window_onLoad loadProxySettings() End Sub Set wshShell = CreateObject("WScript.Shell") ProxyEnable =…
Steve
  • 143
  • 1
  • 1
  • 6
3
votes
1 answer

VBScript / ADODB Syntax Issue with adArray?

I'm hoping somebody could provide me with some fresh eyes on my vb script. The main purpose of this script is to execute a stored procedure using some parameters. The error I get is 'Expected end of statement' I haven't done much VB scripting but…
Ash W
  • 55
  • 1
  • 8
3
votes
2 answers

Auto Increment version of setup project

I need to increment version of an installer on every successful build. I have added a VBscript file and called it from a pre-build event. But am not able to get the actual result. my script is as under: set a = wscript.arguments if a.count = 0 then…
user22197
  • 31
  • 4
3
votes
3 answers

Multiple strings in multidimensional array vbscript

I am trying to add multiple strings into a multidimensional array in VBScript. I hope I can explain it in a short way: Every string contains some data separated by commas. Now I would like to add all these data into an array, one dimension for every…
C.Schwan
  • 33
  • 1
  • 4
3
votes
4 answers

How to check default host for VBScript is WScript or CScript?

I would like to know what is default host for VBScript on particular machine, whether that is set to WScript or CScript ? For example, if I use cscript //h:cscript //s then is there any way I can check host for VBScript is set to cscript? I found…
Magg
  • 103
  • 2
  • 7
3
votes
1 answer

ServerXMLHTTP appending to content-type

I am making a server-side HTTP request with a JSON body in VBScript like this: Set oXMLHttp = Server.CreateObject("MSXML2.ServerXMLHTTP") oXMLHttp.open cMethod, cAPIURL, False, cUser, cPassword oXMLHttp.setRequestHeader "Content-Type",…
3
votes
3 answers

ISO week number in VBScript or VBA

How can I get the ISO week number of some date in VBScript or VBA?
Michel de Ruiter
  • 7,131
  • 5
  • 49
  • 74
3
votes
2 answers

Create custom Windows 10 notification boxes

in Windows 10 there are those gray notification boxes in the lower right corner. They come when you plug in a USB, when Updates were installed or when a virus was found by windows defender. My question: How can i create these things? (with a custom…
infinitecode
  • 33
  • 1
  • 1
  • 7