There were 18 articles found in this category:
VBScript AppActivate Function
Use AppActivate to make the selected Window Active Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "calc" WScript.Sleep 100 WshShell.AppActivate "Calculator" This example runs the Windows Calculator and makes the Windows Calculator the active Window. The Application being made ...
VBScript Arrays
This example will create an array called arrShopping that contains the Elements of Bread, Milk, Apples, Carrots, Lemons and Tomatoes. This array has 6 elements numbered 0 through to 5. arrShopping = Array("Bread","Milk","Apples","Carrots","Lemons","Tomatoes") The same array could also be create ...
VBScript For Each Next Loop
A For each loop lets you perform an action on an object, then perform the same action on a different object, and keep doing this, until there are no more objects. Dim arrShopping Dim str arrShopping = Array("Bread","Milk","Apples","Carrots","Cereal") For Each str In arrShopping MsgBox str Next ...
VBScript For Next Loop
A For Next loop is used to loop over a collection of items a specified number of times. Dim myLoop For myLoop = 1 To 20 WScript.Echo myLoop Next In this example, we will loop 20 times, starting from the number 1. This script will echo out 1, then 2, then 3 and so on, until number 20 is reached. ...
VBScript Join Function
This example will join elements from an array called arrShopping to a string called str and it will separate each item with a comma (,). str = Join(arrShopping,",") For more information about VBScript, check out our VBScript Training Videos VBScript Training Videos
VBScript Literals
A literal is a value that you directly type into a script. If the value you assign to a literal is a number it doesn't go in quotes, however if it's a string value it needs quotes. Dim myFirstLiteral, mySecondLiteral myFirstLiteral = 20 mySecondLiteral = "John" For more information ...
VBScript MsgBox Function
Use Msgbox to display a popup message box. Msgbox test This statement will popup a message box showing the text "test". myBox = MsgBox ("Proceed?", 3) This function will show a message box with Yes, No and Cancel Buttons For more information about VBScript, check out our VBScript Tr ...
Working with VBScript Objects
When you need to use an object, it must first be instantiated. For example: Set objFSO = CreateObject("Scripting.FileSystemObject") This example uses the FileSystemObject to allow access to files, folders, drives and text files. Dim objFSO, objFolder, objFile, objNewFolder Set objFSO = CreateObj ...
VBScript PopUp Function
Use PopUp to display a popup message box. Dim WshShell, BtnCode Set WshShell = WScript.CreateObject("WScript.Shell") BtnCode = WshShell.Popup("Is your name Bob?", 5, "Answer This Question:", 4 + 32) Select Case BtnCode case 6 WScript.Echo "Hello Bob." case 7 WScript.Echo "Oh, I m ...
VBScript ReDim
Redim allows you to resize an array. In this example we are re-declaring or re-dimming the arrShopping array to contain 11 elements. ReDim arrShopping(10) When you redim an array, the contents of the array will be lost, so use the "Preserve" keyword to prevent the array from being emptied when i ...
VBScript Run Method
Use Run to launch an external application. This example runs the Windows Calculator. Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "calc" WScript.Sleep 100 WshShell.AppActivate "Calculator" WScript.Sleep 100 usgage: object.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) ...
VBScript SendKeys Function
Use SendKeys to send keystrokes to another application. This function mimics the behavior of a human sitting at the keyboard, entering keystrokes. Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "calc" WScript.Sleep 100 WshShell.AppActivate "Calculator" WScript.Sleep 100 WshShe ...
VBScript Split Function
This example will split elements from a string called str to an array called arrStr using the comma (,) as a separator. arrStr = Split(str,",") For more information about VBScript, check out our VBScript Training Videos VBScript Training Videos
VBScript Exec
Exec allows you to execute command line applications. It requires the WshShell Object. The advantage of using Exec over RUN, is that exec allows you more flexibility over handling the output generated by command line applications. This example simply runs the IPConfig command and displays the ou ...
VBScript Dim
Use Dim to declare a variable. You can dim more than one variable on a single line by separating each variable name with a comma. Dim Hostname Dim objFSO, objFolder For more information about VBScript, check out our VBScript Training Videos VBScript Training Videos
VBScript Const
Use Const to declare a Constant. A constant is similar to a variable except that the value assigned to a constant doesn't change over the lifetime of the script. A good example of where a constant would be useful would be for static values like the hostname of a computer, a registry key, or even ...
WMI Return Codes
WMI will return the following codes: Return Code Description 0 Success 1 Informational 2 Warning 3 Error
VBscript AppActivate
Use AppActivate to make the selected Window Active Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "calc" WScript.Sleep 100 WshShell.AppActivate "Calculator" This example runs the Windows Calculator and makes the Windows Calculator the active Window. The Application being made ...
|