|
||||||
Microsoft Window's Big Secret: ScriptingHow to Automate any Task on Windows by Using a Script
The same language that is used for Visual Basic is built into every Microsoft Windows PC. This article looks at how to start using that hidden language - Basic.
One of the little known secrets about Microsoft Windows is that it has its own built in scripting language - and it's Basic - the same simple yet powerful language that forms the backbone of that world famous program Microsoft Visual Basic. The key differences between Visual Basic programming and Windows scripting are that:
And it's those differences that makes Basic so powerful and versatile. Writing a Basic Script for WindowsIt's very easy to create a Basic script - a script that will be quite familiar to any Visual Basic programmer (or to any other programmer, for that matter) - it just requires the programmer to open up a text editor and then start scripting extremely powerful applications - for example one that will create a Microsoft Word document and then write to it: option explicit 'enforce the definition of variables dim word, doc, ip set word = createobject("word.application") word.documents.add set doc = word.activedocument doc.select ip=True while ip <> False ip = inputbox ("Please enter some text") if ip <> False then doc.range.insertafter ip & vbCr 'vbCr is a Basic constant representing a carriage return end if wend doc.saveas ("C:/test.doc") word.visible = True The code is very simple, but very effective:
One interesting point this reveals is that all of the activities are hidden in the background unless the code specifically sets the documents visible property. There is, of course, an alternative ending to this script; instead of: word.visible = True the developer could write: word.quit set word = nothing This would simply close the file (and reclaim any memory that may have been used). Running a Basic Script in WindowsThe script can be run in one of two ways:
If the script is run from the command line then some additional text is always displayed as a header, but this can be turned off by using the nologo key word: cscript //nologo count.vbs ConclusionWindows scripting:
It is also:
and if that's not enough - it's on every Windows PC in the world.
The copyright of the article Microsoft Window's Big Secret: Scripting in Windows Programming is owned by Mark Alexander Bain. Permission to republish Microsoft Window's Big Secret: Scripting in print or online must be granted by the author in writing.
|
||||||
|
|
||||||
|
|
||||||