This page contains a list of user images about Vbs which are relevant to the point and besides images, you can also use the tabs in the bottom to browse Vbs news, videos, wiki information, tweets, documents and weblinks.
P!nk - Just Give Me A Reason ft. Nate RuessFrom the Grammy Nominated album The Truth About Love available now - http://smarturl.it/tal Music video by P!nk featuring Nate Ruess performing Just Give Me ...
James Arthur sings Shontelle's Impossible - The Final - The X Factor UK 2012Watch judges' comments at http://itv.com/XFactor (UK ONLY) Watch James Arthur sing Impossible by Shontelle Sweeeeet! As potential Winner's Singles go, this o...
THE LEGEND OF ZELDA RAP [MUSIC VIDEO]WATCH BLOOPERS & MORE: http://bit.ly/ZELDAxtras DOWNLOAD THE SONG: http://smo.sh/13NrBp8 DOWNLOAD UNCENSORED SONG: http://smo.sh/WMYpsf GET LEGEND OF SMOSH T...
MACKLEMORE & RYAN LEWIS - THRIFT SHOP FEAT. WANZ (OFFICIAL VIDEO)Thrift Shop on iTunes: http://itunes.apple.com/us/album/thrift-shop-feat.-wanz-single/id556955707 The Heist physical deluxe edition: http://www.macklemoremer...
PEWDIEPIE Song - Dj FortifyDue to so many request I decided to upload this epic track as well. Enjoy it bros!
Draw My Life - Ryan HigaSo i was pretty hesitant to make this video... but after all of your request, here is my Draw My Life video! Check out my 2nd Channel for more vlogs: http://...
Einstein vs Stephen Hawking -Epic Rap Battles of History #7Download this song: http://bit.ly/EpicRap7 New ERB merch: http://bit.ly/MNwYxq Tweet this Vid-ee-oh: http://clicktotweet.com/TpUg9 Hi. My name is Nice Peter,...
P!nk - Try (The Truth About Love - Live From Los Angeles)Music video by P!nk performing Try (The Truth About Love - Live From Los Angeles). (C) 2012 RCA Records, a division of Sony Music Entertainment.
Rihanna - Stay ft. Mikky EkkoDownload "Stay" from Unapologetic now: http://smarturl.it/UnapologeticDlx Music video by Rihanna performing Stay ft. Mikky Ekko. © 2013 The Island Def Jam Mu...
Rihanna - We RideMusic video by Rihanna performing We Ride. (C) 2006 The Island Def Jam Music Group.
David Guetta - Titanium ft. SiaFrom the album Nothing But The Beat Ultimate - Download on iTunes here: http://smarturl.it/NBTBiTunes?IQid=vevo Featuring Sia, Ne-Yo, Akon, Nicki Minaj, Flo ...
Why Selena Broke Up With JustinFor you nosy people, this is the reason why Selena Gomez broke up with Justin Bieber. Get the song on iTunes: http://bit.ly/T74XEZ Andy Lange produced the mu...
Epic Trick Shot Battle | Dude PerfectPlay the DUDE PERFECT GAME here! iPhone - http://bit.ly/DPGameiPhone Android - http://bit.ly/DPGameAndroid iPad - http://bit.ly/DPGameiPad Tweet! http://bit....
David Guetta - She Wolf (Falling To Pieces) ft. SiaFrom the album Nothing But The Beat Ultimate - Download on iTunes here: http://smarturl.it/NBTBiTunes?IQid=vevo Featuring Sia, Ne-Yo, Akon, Nicki Minaj, Flo ...
Most Annoying People On The InternetDon't be these people. Mapoti See Bloopers and Behind-The-Scenes Here!: http://youtu.be/dfpo7uXwJnM Huge thank you and shout out to Dtrix: http://www.youtube...
MACKLEMORE & RYAN LEWIS - CAN'T HOLD US FEAT. RAY DALTON (OFFICIAL MUSIC VIDEO)Macklemore & Ryan Lewis present the official music video for Can't Hold Us feat. Ray Dalton. Can't Hold Us on iTunes: https://itunes.apple.com/us/album/cant-...
FUNNY GAMING MONTAGEI'm just a guy from Sweden who likes to laugh and make other people laugh. Sharing gaming moments on YouTube with my bros! Why not join us? :D Become a bro t...
Draw My Life- Jenna MarblesThis video accidentally turned out kind of sad, ME SO SOWWY IT NOT POSED TO BE SAD WHO WANTS HUGS AND COOKIES? Also, FYI for anyone attempting this, it takes...
Rihanna - DiamondsPre-order new album Unapologetic, out worldwide Monday, November 19: http://smarturl.it/UnapologeticDlx Music video by Rihanna performing Diamonds. ©: The Is...
Rihanna - Pon de Replay (Internet Version)Music video by Rihanna performing Pon de Replay. YouTube view counts pre-VEVO: 4166822. (C) 2005 The Island Def Jam Music Group.
The Microsoft VBscript icon |
|
| Appeared in | 1996 |
|---|---|
| Developer | Microsoft |
| Stable release | 5.8 |
| Major implementations | Windows Script Host, Active Server Pages |
| Influenced by | Visual Basic |
| Influenced | Windows PowerShell |
| OS | Windows |
| Usual filename extensions | .vbs, .vbe, .wsf, .wsc (.hta, .htm, .html, .asp) |
VBScript (Visual Basic Scripting Edition) is an Active Scripting language developed by Microsoft that is modeled on Visual Basic. It is designed as a “lightweight” language with a fast interpreter for use in a wide variety of Microsoft environments. VBScript uses the Component Object Model to access elements of the environment within which it is running; for example, the FileSystemObject (FSO) is used to create, read, update and delete files.
VBScript has been installed by default in every desktop release of Microsoft Windows since Windows 98;[1] in Windows Server since Windows NT 4.0 Option Pack;[2] and optionally with Windows CE (depending on the device it is installed on).
A VBScript script must be executed within a host environment, of which there are several provided with Microsoft Windows, including: Windows Script Host (WSH), Internet Explorer (IE), and Internet Information Services (IIS).[3] Additionally, the VBScript hosting environment is embeddable in other programs, through technologies such as the Microsoft Script Control (msscript.ocx).
Contents |
History [edit]
VBScript began as part of the Microsoft Windows Script Technologies, launched in 1996. This technology (which also included JScript) was initially targeted at web developers. During a period of just over two years, VBScript advanced from version 1.0 to 2.0, and over that time it gained support from Windows system administrators seeking an automation tool more powerful than the batch language first developed in the early 1980s.[4]
On March 6, 1988 Alan Cooper showed Bill Gates his shell prototype that allowed widgets to be added dynamically. March 20, 1991, Microsoft adopted "Quick Basic". This allowed users to create Windows apps quickly and easily with a GUI. Finally, on August 1, 1996, Internet Explorer is made with features that include VBScript.[5]
In version 5.0, the functionality of VBScript was increased with new features such as: regular expressions; classes; the With statement;[6] the Eval, Execute, and ExecuteGlobal functions to evaluate and execute script commands built during the execution of another script; a function-pointer system via GetRef,[7] and Distributed COM (DCOM) support.
In version 5.5, SubMatches[8] were added to the regular expression class in VBScript, to finally allow script authors to capture the text within the expression's groups. That capability had already been available in JScript.
With the advent of the .NET framework, the scripting team took the decision to implement future support for VBScript within ASP.NET for web development,[9] and therefore no new versions of the VBScript engine would be developed and it moved over to being supported by Microsoft's Sustaining Engineering Team, who are responsible for bug fixes and security enhancements. For Windows system administrators, Microsoft suggests that they migrate to Windows PowerShell. However, the scripting engine will continue to be shipped with future releases of Microsoft Windows and IIS.
Uses [edit]
Although VBScript is a general-purpose scripting language, several particular areas of use are noteworthy. First, it is widely used among system administrators in the Microsoft environment.[10] This situation may change with the promotion and increased use of Windows PowerShell. Second, VBScript is the scripting language for Quick Test Professional, a test automation tool.[11] A third area to note is the adoption of VBScript as the internal scripting language for some embedded applications, such as industrial operator interfaces and human machine interfaces. The hierarchical DBMS InterSystems Caché (which has its roots in the language MUMPS) also supports an implementation of VBScript, Cache BASIC, for programming stored code.[12][citation needed]
This relatively widespread use of VBScript is not because of many special merits of VBScript - several useful features of the full Visual Basic, such as strong typing, extended error trapping and the ability to pass a variable number of parameters to a subroutine have been removed - but mainly because, apart from being easy to learn, royalties need not be paid to Microsoft by implementers as long as the VBScript trade mark is acknowledged. By contrast, when an organization licenses Visual Basic for Applications (VBA) from Microsoft - as companies such as Autodesk, StatSoft, Great Plains Accounting and Visio (subsequently acquired by Microsoft) have done - it is allowed to redistribute the full VBA code-writing and debugging environment with its product.
Environments [edit]
When employed for client-side web development in Microsoft Internet Explorer, VBScript is similar in function to JavaScript. It is used to write executable functions that are embedded in or included from HTML pages and interact with the Document Object Model (DOM) of the page, to perform tasks not possible in HTML alone. However, other web browsers such as Firefox and Opera do not have built-in support for VBScript. This means that where client-side scripting and cross-browser compatibility are required, developers usually choose JavaScript over VBScript.
VBScript is also used for server-side processing of web pages, most notably with Microsoft Active Server Pages (ASP). The ASP engine and type library, asp.dll, invokes vbscript.dll to run VBScript scripts. VBScript that is embedded in an ASP page is contained within <% and %> context switches. The following example of an ASP page with VBScript displays the current time in 24-hour format (Note that an '=' sign occurring after a context switch (<%) is short-hand for a call to Write() method of the Response object), but it is also used as the default script for error messages with the windows operating systems.
<% Option Explicit %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>VBScript Example</title> </head> <body> <div><% ' Grab current time from Now() function. Dim timeValue timeValue = Now() %> The time, in 24-hour format, is <%=Hour(timeValue)%>:<%=Minute(timeValue)%>:<%=Second(timeValue)%>. </div> </body> </html>
VBScript can also be used to create applications that run directly on a workstation running Microsoft Windows. The simplest example is a script that makes use of the Windows Script Host (WSH) environment. Such a script is usually in a stand-alone file with the file extension .vbs. The script can be invoked in two ways. Wscript.exe is used to display output and receive input through a GUI, such as dialog and input boxes. Cscript.exe is used in a command line environment.
VBScript can be included in two other types of scripting files: Windows Script Files, and HTML Applications.
A Windows Script File (WSF) is styled after XML. A WSF file can include multiple VBS files. As a result WSF files provide a means for code reuse: one can write a library of classes or functions in one or more .vbs files, and include those files in one or more WSF files to use and reuse that functionality in a modular way. The files have extension .wsf and can be executed using wscript.exe or cscript.exe, just like a .vbe file.
An HTML Application (HTA) is styled after HTML. The HTML in the file is used to generate the user interface, and a scripting language such as VBScript is used for the program logic. The files have extension .hta and can be executed using mshta.exe.
VBScript (and JScript) can also be used in a Windows Script Component - an ActiveX-enabled script class that can be invoked by other COM-enabled applications.[13] These files have extension .wsc.
Functionality [edit]
Language features [edit]
The language of VBScript is modelled on Visual Basic, and therefore can be reviewed using similar categories: procedures, control structures, constants, variables, user interaction, array handling, date/time functions, error handling, mathematical functions, objects, regular expressions, string manipulation, and so on.[14]
The following are some key points of introduction to the VBScript language.
A “procedure” is the main construct in VBScript for separating code into smaller modules. VBScript distinguishes between a function, which can return a result in an assignment statement, and a subroutine, which cannot. Parameters are positional, and can be passed by value or by reference.
Control structures include the usual iterative and conditional Do Loops, If-Then-Else statements, and Case statements, with some more complex variants, such as ElseIf and nested control structures.
As a memory aid in coding, and certainly for readability, there are a large number of constants, such as True and False for logical values, vbOKCancel and vbYesNo for MsgBox codes, vbBlack and vbYellow for color values, vbCR for the carriage return character, and many others.
Variables by default have “Variant” type, but it is possible (and sometimes necessary) to force a particular type (integer, date, etc.) using conversion functions (Cint, CDate, etc.)
User interaction is provided through the functions MsgBox and InputBox which provide a simple dialogue box format for messages and input. Both functions display prompting messages, with the former returning a standard response, and the latter returning one user-supplied text or numeric value. For more elaborate GUI interaction with controls, VBScript can be used in combination with HTML, for example, in an HTML Application. Event-driven forms are not supported as in Visual Basic or Visual Basic for Applications.
Names are not case sensitive therefore, for example, MsgBox and msgbox, or FileSystemObject and filesystemobject, are treated as the same name. However, as usual, it is considered a best practice of VBScript style to be consistent and to capitalize judiciously.
Additional Functionality [edit]
File system management, file modification, and streaming text operations are implemented with the Scripting Runtime Library scrrun.dll. This provides objects such as FileSystemObject, File, and TextStream, which expose the Windows File System to the programmer.
Binary file and memory I/O is provided by the "ADODB.Stream" class, which can also be used as a string builder (since a high amount of VBScript string concatenation is costly due to constant memory re-allocation), and can be used to convert an array of bytes to a string and vice versa. Database access is made possible through ActiveX Data Objects (ADO), and the IIS Metabase can be manipulated using the GetObject() function with sufficient permissions (useful for creating and destroying sites and virtual directories). XML files and schemas can be manipulated with the Microsoft XML Library Application Programming Interfaces (msxml6.dll, msxml3.dll), which also can be used to retrieve content from the World Wide Web via the XMLHTTP and ServerXMLHTTP objects (class strings "MSXML2.XMLHTTP.6.0" and "MSXML2.ServerXMLHTTP.6.0", respectively).
Functionality can also be added through ActiveX technologies. Security concerns have led to many ActiveX controls being blacklisted in the Internet Explorer process by Microsoft, which deploys the killbit via monthly Windows security updates to disable vulnerable Microsoft and third party code.[15][16]
Development Tools [edit]
Microsoft does not routinely make available an IDE (Integrated Development Environment) for VBScript, although the Microsoft Script Editor has been reported. However, there are VBScript debuggers available from third-party sources,[17][18] and there is syntax high-lighting either for VBScript or languages with similar syntax in many editors in the list of text editors. Apart from this, any text editor can be used to create a VBScript program; the important thing is to give the text file the necessary file extension i.e. .vbs.
During execution, when an error occurs, the script host reports an error message stating the error type (e.g. “syntax error”) together with the line number and position within the line where the error occurred.
Examples [edit]
Hello World [edit]
The “simplest” example:
MsgBox "Hello World"
Save it as a .vbs file. Then, execute using cscript.exe or wscript.exe.
A more elaborate example, showing the use of MsgBox as a function (returning a result), and the use of three parameters, including the use of constants in the second parameter.
dim x x = MsgBox("Hello World:Text",1+64+4096,"Hello World:Title") x = MsgBox("Hello World:Text",4161,"Hello World:Title") x = MsgBox("Hello World:Text", vbOKCancel+vbInformation+vbSystemModal, _ "Hello World:Title") x = MsgBox("Hello World:Text", vbYesNoCancel+vbInformation,"Hello World:Title") MsgBox "The result is " & x
The first three lines all produce the same result. For clarity, the numbers in the second parameter are written as an explicit summation (that is, with a "+"), rather than presented as a single number (in this example, 4161). However, the use of constants as in the third line is considered best practice. Different constants will produce different behaviours; for example, vbOKCancel specifies two buttons in the dialogue box, whereas vbYesNoCancel would specify three buttons (Yes, No, and Cancel).
Terminate a task [edit]
VBScript can access WMI (Windows management instrumentation), for instance, the Windows Task Manager. The code below, when executed, would terminate (“kill”) any process involving ’’notepad.exe’’.
'Terminate all processes involving the name <strProcessToKill Option Explicit Dim strComputer, strProcessToKill, objWMIService, colProcess, objProcess strComputer = "." strProcessToKill = "notepad.exe" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer _ & "\root\cimv2") Set colProcess = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = '" & strProcessToKill & "'") For Each objProcess in colProcess msgbox "... terminating " & objProcess.Name objProcess.Terminate() Next
The use of Option Explicit is not required, but is considered a best practice for VBScript.[19][20]
Creating ten files with unique names [edit]
This example demonstrates how to create a new file and add content to it. It also demonstrates String concatenation.
For i = 1 to 10 createFile( i ) Next Public sub createFile(a) Dim fso,myFile filePath = "C:\file_name" & a & ".txt" Set fso=CreateObject("Scripting.FileSystemObject") Set MyFile= fso.CreateTextFile( filePath) MyFile.WriteLine("This is a separate file") MyFile.close End Sub
SendKeys [edit]
The SendKeys method sends one or more keystrokes to the active window (as if typed on the keyboard). In this example the script sends the characters “Hello World!” three times, each time pausing for 2 seconds (2000 milliseconds). SendKeys may not work with all programs, as some of them check for a real key stroke and not a virtual one (e.g. license key input in software installations).
set shl = createobject("wscript.shell") shl.sendkeys "Hello World!" wscript.sleep 2000 shl.sendkeys "Hello World!" wscript.sleep 2000 shl.sendkeys "Hello World!" wscript.sleep 2000
The code should be saved as whatever.vbs, then executed using cscript.exe or wscript.exe in a command window. During execution, the characters “Hello World!” will be displayed after the command prompt.
Windows file operations [edit]
Example of using the supplied object FileSystemObject for some file operations (such as testing if a file exists), and also creating a text file (a TextStream object, one of whose methods is WriteLine). The name of the file is passed as a parameter by reference (which is the default, although this does not matter in this example).
myfilename = "C:\Wikipedia - VBScript - Example - Hello World.txt" MakeHelloWorldFile myfilename Sub MakeHelloWorldFile (FileName) 'Create a new file in C: drive or overwrite existing file Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.FileExists(FileName) Then Answer = MsgBox ("File " & FileName & " exists ... OK to overwrite?", vbOKCancel) 'If button selected is not OK, then quit now 'vbOK is a language constant If Answer <> vbOK Then Exit Sub Else 'Confirm OK to create Answer = MsgBox ("File " & FileName & " ... OK to create?", vbOKCancel) If Answer <> vbOK Then Exit Sub End If 'Create new file (or replace an existing file) Set FileObject = FSO.CreateTextFile (FileName) FileObject.WriteLine "Time ... " & Now() FileObject.WriteLine "Hello World" FileObject.Close() MsgBox "File " & FileName & " ... updated." End Sub
The subroutine MakeHelloWorldFile will create (or update, if it exists) a small text file in the root directory of the C:\ drive, upon selecting “OK” in the MsgBox dialogue box.
See also [edit]
- HTML Components
- Windows Script File
- JavaScript
- JScript
- JScript .NET
- PerlScript
- AppleScript
- FastTrack Scripting Host
References [edit]
- ^ WSH Version Information, on MSDN
- ^ VBScript Version Information, on MSDN
- ^ What is VBScript?, in MSDN Library
- ^ 86-DOS
- ^ VB History
- ^ Visual Basic Scripting Edition: With Statement, on MSDN
- ^ GetRef Function, on MSDN
- ^ Visual Basic Scripting Edition: SubMatches Collection, on MSDN
- ^ What About VBScript?, within the article Introducing JScript .NET by Andrew Clinick of Microsoft Corporation, in Scripting Clinic on MSDN (July 14, 2000)
- ^ Script Center, Microsoft web site targetting system administration scriptors
- ^ Quick Test Professional – Basics of VBScript
- ^ http://www.intersystems.com/cache/technology/components/script/index.html
- ^ Introducing Windows Script Components, on MSDN
- ^ VBScript - Features by Category
- ^ "How to stop an ActiveX control from running in Internet Explorer". Microsoft. 2007-08-24. Retrieved 2009-06-29.
- ^ "Microsoft Security Advisory (960715): Update Rollup for ActiveX Kill Bits". Microsoft. 2009-01-17. Retrieved 2009-06-29.
- ^ VBsEdit, an editor for VBScript with a built-in debugger
- ^ "SplineTech VBS Debugger, an independent standalone VBScript debugger and editor"
- ^ Remarks on Option Explicit Statement, MSDN Library
- ^ Why force yourself to declare all variables?, In VBScript For Dummies, John Walkenbach, IDG Books Worldwide, Inc., 1996
External links [edit]
- VBScript in the Microsoft Developer Network
- Windows Script 5.6 Documentation
- VBScript @ codewiki
- VBScript @ stealthbot
- ExeScript Editor VBS Editor, Compiler, Debuger
- [1] WMI Overview
|
||||||||||||||||||||||||||||||||||



Research