100 likes | 393 Views
Windows Script 101. VBScript for Sysadmins. Dave Motovidlak Faculty of Arts & Sciences motovidlak@admin.rutgers.edu. What is VBScript?. VBScript = Visual Basic Scripting Edition Subset of VB language – “VB Lite” Less GUI oriented Easier for beginning programmers to use … ?
E N D
Windows Script 101 VBScript for Sysadmins Dave Motovidlak Faculty of Arts & Sciences motovidlak@admin.rutgers.edu
What is VBScript? • VBScript = Visual Basic Scripting Edition • Subset of VB language – “VB Lite” • Less GUI oriented Easier for beginning programmers to use … ? • Intermediate step between batch files and “real” programming… maybe? • VBS (and JScript) support built into OS
How do you make VBScripts? • Regular ol’ text. No compiling. • Notepad suffices, other IDE’s are available. Try jEdit (http://jedit.org) or PrimalScript (http://sapien.com) • Run with wscript.exe or cscript.exe. Debugger available too. • VBS also used in MS Office docs Visual Basic for Applications (use the Visual Basic Editor, under View Toolbars)
What can I do with VBScripts? • VBS = object-oriented. Depends on object model you are scripting. VBS is just the “glue.” • Some object models: Windows Script Host, Office, Internet Explorer, WMI, ADSI • Can read / write files, modify the registry, change pc name, collect system data, manage user accounts / services, send data over web, reboot, create Excel charts, start processes on remote computers, automate OS installs, create your own “dll’s,**” etc.…
What are objects? • Objects are just things with properties and methods. Described by “dot” syntax. • Set myIE=CreateObject(“InternetExplorer.Application”) • myIE.IsVulernable=True • myIE.SpawnVirus(“ILoveYou”) • Object model = all the objects + methods + properties “exposed” by a particular app or package 5ProgID
Syntax examples • Set objShl=CreateObject(“WScript.Shell”)objShl.Run “notepad.exe”,1,True • strOutfile=“C:\Temp\1.txt”Set objFso=CreateObject(“Scripting.FileSystemObject)Set objFil=objFso.OpenTextFile(strOutfile,2,True)objFil.WriteLine “Hello world”objFil.Close
Which objects / models are most important? • Depends on what you want to do… • Windows Script Host (Network, Environment variables, Special Folders) • Scripting.FileSystemObject • WScript.Shell • ADSI service / user mgt. • WMI tricky but very powerful system admin interfaces
How do I learn more? • Online documentation, especially downloadable “Windows Script” chm • Oleview from reskit • Cheat with Visual Basic Editor in Office set References with Object Browser (use “dot completion” feature) • Scriptomatic tools, esp. for WMI and ADSI • Browse the registry … e.g., HKEY_CLASSES_ROOT\WScript.Shell
A few script resources • UCS Toolkit: http://ucstoolkit.rutgers.edu/technical/scripts.html • MSDN:http://msdn.microsoft.com/scripting • Win32 Scripting:http://cwashington.netreach.net/ motovidlak@admin.rutgers.edu