Skip to main content

Windows Scripting With VBScript

If it works in Windows operating system environment, the days you will often associated with programs written in Visual Basic

Perhaps the day you use a database application created with the language of Visual Basic / VB.NET, or using the web site programmers work ASP / ASP.NET or loyal user application macro written with VBA (Visual Basic for Application) and if your unlucky day , you are a victim of the virus made with VBScript



Of the various types mentioned Visual Basic, VBScript is a scripting language is readily available and used in the Windows environment. You do not need to install an IDE, compiler, or application specific tools.

About VBScript

Made an initial target of VBScript (and JScript) is for the purposes of web development with a focus on the use of Microsoft Internet Explorer browser, the script was executed from the client side (client side scripting). Until this very day you are still able to insert a VBScript in your website, egg for validation purposes or a particular process on the client side, although the use of JavaScript for the same purposes more popular. This is related to inter-browser compatibility is on average more support JavaScript

But for the use of server side (server side scripting), VBScript never experienced the boom in popularity of the engine Active Server Pages (ASP), followed by the ASP.NET-based. NET Framework

In the Windows desktop environment, VBScript can also be used to create applications that run on Windows Script Host (WSH) Environment, introduced since Windows 98 and because of a scripting language, VBScript does not need to go through the compilation process as when you create an application with VB 6 or VB. NET

You can write a VBScript to stand alone file with extension *. vbs. Maybe a little more similar to batch files (*. bat) that has popular (and still can be used to this day) at the time operating system (DOS) can still be brought in the form of diskettes for measuring only hundreds of kilobytes

But of course, VBScript function is much broader than the batch file. You can use VBScript for Windows and network administration, multimedia, databases, we often do not even hear the virus is made with VBScript. Return a language / tools can be a double-edged sword, used for good or bad thing is a choice.

Scripting language itself may not be able to do many things. Location of the advantages is being able to access objects provided by the host application, in this case the WSH, which consists of WSCRIPT.EXE and CSCRIPT.EXE.WSCRIPT.EXE files used in Windows GUI environment, while CSCRIPT.EXE the command-line environment. You can download the latest WSH on the Microsoft Download Center website, by typing the keyword "Windows Script Host" that produces the following URL http://www.microsoft.com/downloads/en/result.aspx?freetext=windows+script+host&displaylang = stype = en & s_basic.

First Script!

If you ever make a program with VB.NET or earlier versions of Visual Basic, to write a VBScript program will not be much different. But do not worry, if you do not have to know VB, provided a basis program, will not be difficult to understand the workings and VBScript syntax is simple, easy to understand, and modular

To write VBScript, you only need a text editor that produces plain text, such as Notepad. Type the following code and save it with any name with extension *. vbs, for example sample.vbs

dim obj
set obj = CreateObject ( "Wscript.Network")
dim sInfo
sInfo = "Hello World:" & vbCRLF & _
"User Name:" & obj. UserName & vbCRLF & _
"Computer Name:" & obj.ComputerName & vbCRLF

msgBox sInfo
set obj = Nothing

Execution of the program by double click the vbs file. The program above creates an object named obj Wscript.Network, to get the UserName and ComputerName of the system you use, and displays them in the form of Message Box. Simple enough?

Controlling Program Through VBScript

You can call other programs through VBScript. The following simple script will show a similar function when you access the Start menu - Run on Windows.

ask = "Programs that want to run"
title = "VBScript"
default = "Notepad.exe"
answer = InputBox (ask, title, default)
set wshshell = CreateObject ( "WScript.Shell")
wshshell.Run answer

Save the above program code with extension *. vbs and double-click execution. The output from the script will ask what program to run (default is Notepad.exe) you can replace it with another program such examples that will summon msconfig System Configuration Utility, which will call iexplore.exe Internet Explorer browser, and so on.


Not only GUI-based program, you can also run the command line-based program, like the dir command to view a list of files and directories. The following example demonstrates calling the dir command, save results to a text file, and displays them in a pop-up window



Note the use CreateObject ( "Scripting.File-SystemObject") who works for the management of files, such as writing and reading the contents of text files. Output from above program code looks like the following picture



We will go further with the control program more interesting. This time VBScript will call a specific method of the object of Microsoft Word. For example the following program code:

set word = CreateObject ( "Word.Application")
word.documents.Add
checkword = InputBox ( "Enter a word:")
set of suggestions = word.GetSpellingSuggestions (checkword)
if suggestions.Count = 0 then
msgBox "The writing is correct"
else
list = "Writing is suggested:" "" & checkword & "" ":" & vbCr
for each suggestion in suggestion
list = list & suggestion & vbCr
next
msgBox list
end if
word.Quit

When executed, the program will ask you to enter words, then the program will check spelling and suggest the correct word, if the program found a spelling error.

What makes the world interesting programming is creativity, you will quickly feel bored if you do coding without ever thinking to develop what you already know

Similarly, once you learn VBScript ability to control other programs, the implementation of course not limited to the examples given. Developing example, you can create a simple program that when executed will open favorite sites you are, the program code is as follows:



When executed, the script will call the URL which we have defined in the default browser. This simple program can be very useful for those of you who regularly visit certain sites.

Objects Used

Throughout the program examples shown, you already know the various objects such as Scripting.FileSystemObject, WScript.Network, and many other objects that you use the CreateObject command. How to know the objects found on your computer system? A way to see it is to use the Registry Editor.

You can see these objects by running the Registry Editor by typing regedit in the StartMenu, not in HKEY_CLASSES_ROOT, here are stored all the information about file associations and ActiveX objects. For example, you can find WScript.Network, if you do not find it, then the object is not you can use in your computer system

With VBScript, you can search and display all these objects. Program code is as follows:





Note that this program requires regtool.tob object, if not installed, you can search and download on the internet, for example in the URL http://www.filewatcher.com/m/regtool.ocx.22528.0.0.html, this program will displays the number of available objects and displays them on the message box. If necessary, of course, you can make modifications by writing to text files. The output of this program can be seen in the following figure:



VBScript and Security Issues

The more powerful VBScript, such as the ability to access the registry, files, and various objects, can not help but also raises security issues within the Windows operating system itself, for example, if VBScript is used as a destructive exploits by people who are not well-intentioned, and certainly we do not can eliminate the script and malice with sage or call of protest

Knowledge available for anyone to learn, because it was however, able to produce the script through a security hole that proved a good effort (to be not good if used to harm people), will get better if followed by finding ways to prevent it, remember that one of the best protection is to understand the attack came.

Comments

Popular posts from this blog

Graphical User Interface in Java (Part 1 From 3)

Frankly, graphics-based applications are always more interesting than the application of command-line based. And the good news, building graphical applications in Java, it is not as difficult as imagined Java is a programming language first released by Sun Microsystems in 1995. Java philosophy of "Write Once, Run Everywhere" make Java become one of the popular programming languages today. According to the official website of Java, Java technology currently used in 4.5 billion devices (more than 800 million PCs, 1.5 billion gadgets, 2.2 billion smart cards) and still did not include use in printers, web-cam, games, car navigation systems, medical devices, etc Know Java If you've heard of Java, but not so deeply in the program, chances are you will be confused with terms such as Java 2 SDK, JDK, Java Applets, Java Script, Java Runtime Engine (JRE), Java SE 6, etc. All of the Java technology, but if you want to learn to develop Java applications on a PC, the Java SE (Standar

Redmi Officially Launches Redmi Watch

  Redmi officially released its initial smartwatch Redmi Watchin China. In terms of style, Redmi Watch looks similar to the Apple Watch. Redmi Watch has a square-shaped design with rounded corners. Redmi Watchcarries a 1.4 inch 2.5 D display with a resolution of 320 x 320 pixels. Its weight is quite light, just 35 grams.Redmi Watch brings water resistance technology with a depth of up to 50 meters. Redmi Watch brings a variety of sports activity discovery features, from running, cycling, swimming, and also much more. Redmi Watchhas numerous innovative features including a heart price detector and also a rest period tracker. All tracking tasks can be kept track of and also accessed through the Mi Fit application. Via this application additionally, users can establish the screen face on Redmi Watch. There are greater than 120 types of front views to select from for free. Redmi Watchcan get in touch with mobile using Bluetooth connection. This wise watch includes NFC assistance

New Autoit: Debug Mode!

The virus is always ranks 10 most popular of the virus, even in the big 3 a few months back. How new variants in action? Follow this following discription Virus-like folder icon with the standard Windows default this is the older players in the world of viruses. Variannya very much, and comes with a variety of sizes. Of the first characteristics that never change is the use of a folder icon with the aim to deceive users. Antivirus others have to recognize that Autoit virus with a lmaut, Sohaned, or YahLover, known as our own Autoit.EE What Is Autoit ? Alleged that the author himself called Nhatquanglan the most likely came from Thailand. But we are not sure whether the new variants also come from the same manufacturer. For those of you who have never know what it is to Autoit. Autoit or full Autoit Script, is also the name of the applications that use automation to create a script, exactly automation, hotkeys, and scripting, as written in the site. In short, the script will be in autoi