SlideShare a Scribd company logo
VBScript Quick Reference                                                               VBScript Quick Reference



                                                                                       IGNORE RUNTIME ERRORS                  FORCE VARIABLE DECLARATION
    DISPLAY TO STANDARD OUTPUT                              HTA SECTION

                                             <head>                                      On Error Resume Next                       Option Explicit
 Wscript.Echo “Display this text”               <title>HTA Test</title>
                                                <HTA:APPLICATION
                                                                                       CHECK FOR AN ERROR                     CLEAR THE ERROR CACHE
      DISPLAY TO MESSAGE BOX                    APPLICATIONNAME="HTA Test"
                                                SCROLL="yes" SINGLEINSTANCE="yes"        If Err.Number Then                         Err.Clear
                                                WINDOWSTATE="maximize" >
MsgBox(“Prompt”, vbOKCancel, “Title”)                                                       ‘ an error occurred                     (execute this statement each
                                             </head>
                                             </head>                                     End If                                     time you check the Err object)
    DISPLAY TO POPUP DIALOG BOX
                                                          SCRIPT SECTION
WshShell.Popup(“Message”, 5, “Title”, 1)     <script language="VBScript“>                                         COMPUTER VARIABLE (local computer)
5: number of seconds to display popup box       Sub window_OnLoad
1: displays the OK and Cancel buttons             ' Script to run on startup
                                                                                                                    strComputer = “.”
                                                End Sub
                                                Sub TestSub
                                                  ' Script code goes here                           CONNECT TO WMI
                                                End Sub
                                             </script>                                                 Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")

                                                           HTML SECTION
                                                                                                    QUERY: RETRIEVE ALL PROCESSES
                                              <body> <input type="button"
                                                value="Run Script"                                     Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
                                                name="run_button"                                      ")
                                                onClick="TestSub">
     OPEN TEXT FILE FOR READING               </body>                                               QUERY: RETRIEVE ALL SERVICES

Const ForReading = 1                                                                                   Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service")

Set objFSO = CreateObject _
  ("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _                                                              COMPUTER VARIABLE (local computer)
  ("c:scriptsservers.txt", ForReading)                                                                strComputer = “localhost”
                                                   CREATE DICTONARY OBJECT             RETRIEVE AN OU
     OPEN TEXT FILE FOR WRITING
                                              Set objDictionary = _                      Set objOU = GetObject("LDAP://ou=finance,dc=fabrikam,dc=com")
Const ForWriting = 2                            CreateObject("Scripting.Dictionary")
                                                                                       RETRIEVE A USER ACCOUNT
Set objFSO = CreateObject _
  ("Scripting.FileSystemObject")                 POPULATE DICTIONARY OBJECT              Set objUser = GetObject("LDAP://cn=ken myer, ou=Finance, dc=fabrikam, dc=com")
Set objTextFile = objFSO.OpenTextFile _
  ("c:scriptsservers.txt", ForWriting)      objDictionary.Add key, item                BIND TO THE LOCAL COMPUTER

                                                                                            Set colAccounts = GetObject("WinNT://" & strComputer)
VBScript Quick Reference                                                                      VBScript Quick Reference


                                                                                                                                                                                LOOPS
                                                                                                                                                          For Loops                Do Loops

                                                                                                                                                          For Each x in arr        Do Until x > 5
            On Error Resume Next                                                                                 CONDITIONAL STATEMENTS                     ...                     ...
                                                                                                           If Then             Select Case                Next                     Loop
            Const ADS_SCOPE_ONELEVEL = 1

                                                                                                           If x = 4 Then       Select Case x              For i = 1 to 10          Do While x < 5
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")                                                     …                 Case 1                     ...                      ...
            objConnection.Provider = "ADsDSOObject"                                                        ElseIf x = 5            ...                    Next                     Loop
            objConnection.Open "Active Directory Provider"                                                 Then                  Case 2
            Set objCommand.ActiveConnection = objConnection                                                    …                   ...                                             Do
                                                                                                           Else                  Case Else                While Loops                ...
            objCommand.Properties("Page Size") = 1000                                                                                                                              Loop Until x > 5
            objCommand.Properties("Searchscope") = ADS_SCOPE_ONELEVEL
                                                                                                               ...                 …
                                                                                                           End If              End Select                 While x < 5
                                                                                                                                                           …                       Do
            objCommand.CommandText = _
              "SELECT Name FROM 'LDAP://OU=finance,dc=fabrikam,dc=com'“                                                                                   Wend                       ...
                                                                           Learn more about scripting                                                                              Loop While x < 5
            Set objRecordSet = objCommand.Execute
                                                                          from the Microsoft Windows
                                                                              2000 Scripting Guide,                   ARRAYS
                                                                            available online (and yes,
                                                                           despite the title most of the        arrItems =
                                                                             concepts apply to later            Array("a","b","c")                         FUNCTIONS AND SUBROUTINES
                                                                            versions of Windows too):                                          Function                     Subroutine
                                                                                                                Dim arr(2)
                                                                           http://www.microsoft.com             arr(0) = 20                    Function TestFunc            Sub TestSub
                                                                          /technet/scriptcenter/guide           arr(1) = 30                      …                            …
     EXCEL                                                                                                                                       TestFunc = 10              End Sub
                                                                                                                ReDim Preserve arr(3)          End Function
          Set objExcel = CreateObject("Excel.Application")                                                      arr(2) = 40
          objExcel.Visible = True
          Set objWorkbook = objExcel.Workbooks.Add

     WORD
          Set objWord = CreateObject("Word.Application")
          objWord.Visible = True
          Set objDoc = objWord.Documents.Open("c:scriptstest.doc")

                                                                                                                SEND OUTPUT TO COMMAND WINDOW                      SET DEFAULT TO CSCRIPT
     ACCESS

          Set objAccess = CreateObject("Access.Application")                                                          C:> cscript test.vbs                             C:> cscript //H:cscript
          objAccess.OpenCurrentDatabase "C:ScriptsTest.mdb"


           OUTLOOK                                                                                               SEND OUTPUT TO MESSAGE BOX                         SET DEFAULT TO WSCRIPT

              Set objOutlook = CreateObject("Outlook.Application")
              Set objNamespace = objOutlook.GetNamespace("MAPI")
                                                                                                                      C:> wscript test.vbs                             C:> cscript //H:wscript
OUTLOOK

More Related Content

What's hot

Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product DevelopmentTom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Vincenzo Barone
 
Testing Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptTesting Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScript
Mark
 
Surface flingerservice(서피스플링거서비스초기화)
Surface flingerservice(서피스플링거서비스초기화)Surface flingerservice(서피스플링거서비스초기화)
Surface flingerservice(서피스플링거서비스초기화)
fefe7270
 
Swift - One step forward from Obj-C
Swift -  One step forward from Obj-CSwift -  One step forward from Obj-C
Swift - One step forward from Obj-C
Nissan Tsafrir
 
My Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveCMy Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveC
JohnKennedy
 
Apache Cassandra in Bangalore - Cassandra Internals and Performance
Apache Cassandra in Bangalore - Cassandra Internals and PerformanceApache Cassandra in Bangalore - Cassandra Internals and Performance
Apache Cassandra in Bangalore - Cassandra Internals and Performance
aaronmorton
 
Testing JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiTesting JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and Chai
Mark
 
JavaScript Looping Statements
JavaScript Looping StatementsJavaScript Looping Statements
JavaScript Looping Statements
Janssen Harvey Insigne
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
JWORKS powered by Ordina
 
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Alfresco the clojure way -- Slides from the Alfresco DevCon2011Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Carlo Sciolla
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
Manav Gupta
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
Vikas Thange
 
OOPs difference faqs- 4
OOPs difference faqs- 4OOPs difference faqs- 4
OOPs difference faqs- 4
Umar Ali
 
Spring vs. Java EE QConSP 2012
Spring vs. Java EE QConSP 2012Spring vs. Java EE QConSP 2012
Spring vs. Java EE QConSP 2012
Guilherme Moreira
 
From dot net_to_rails
From dot net_to_railsFrom dot net_to_rails
From dot net_to_rails
pythonandchips
 
Metaprogramming in JavaScript
Metaprogramming in JavaScriptMetaprogramming in JavaScript
Metaprogramming in JavaScript
Mehdi Valikhani
 
NoSQL and JavaScript: a love story
NoSQL and JavaScript: a love storyNoSQL and JavaScript: a love story
NoSQL and JavaScript: a love story
Alexandre Morgaut
 
Dispatch in Clojure
Dispatch in ClojureDispatch in Clojure
Dispatch in Clojure
Carlo Sciolla
 
Objective c runtime
Objective c runtimeObjective c runtime
Objective c runtime
Inferis
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
Rafael Winterhalter
 

What's hot (20)

Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product DevelopmentTom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
 
Testing Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptTesting Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScript
 
Surface flingerservice(서피스플링거서비스초기화)
Surface flingerservice(서피스플링거서비스초기화)Surface flingerservice(서피스플링거서비스초기화)
Surface flingerservice(서피스플링거서비스초기화)
 
Swift - One step forward from Obj-C
Swift -  One step forward from Obj-CSwift -  One step forward from Obj-C
Swift - One step forward from Obj-C
 
My Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveCMy Favourite 10 Things about Xcode/ObjectiveC
My Favourite 10 Things about Xcode/ObjectiveC
 
Apache Cassandra in Bangalore - Cassandra Internals and Performance
Apache Cassandra in Bangalore - Cassandra Internals and PerformanceApache Cassandra in Bangalore - Cassandra Internals and Performance
Apache Cassandra in Bangalore - Cassandra Internals and Performance
 
Testing JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and ChaiTesting JavaScript/CoffeeScript with Mocha and Chai
Testing JavaScript/CoffeeScript with Mocha and Chai
 
JavaScript Looping Statements
JavaScript Looping StatementsJavaScript Looping Statements
JavaScript Looping Statements
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Alfresco the clojure way -- Slides from the Alfresco DevCon2011Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
OOPs difference faqs- 4
OOPs difference faqs- 4OOPs difference faqs- 4
OOPs difference faqs- 4
 
Spring vs. Java EE QConSP 2012
Spring vs. Java EE QConSP 2012Spring vs. Java EE QConSP 2012
Spring vs. Java EE QConSP 2012
 
From dot net_to_rails
From dot net_to_railsFrom dot net_to_rails
From dot net_to_rails
 
Metaprogramming in JavaScript
Metaprogramming in JavaScriptMetaprogramming in JavaScript
Metaprogramming in JavaScript
 
NoSQL and JavaScript: a love story
NoSQL and JavaScript: a love storyNoSQL and JavaScript: a love story
NoSQL and JavaScript: a love story
 
Dispatch in Clojure
Dispatch in ClojureDispatch in Clojure
Dispatch in Clojure
 
Objective c runtime
Objective c runtimeObjective c runtime
Objective c runtime
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 

Similar to Vbscript reference

vbscript-reference book
vbscript-reference bookvbscript-reference book
vbscript-reference book
Anand Dhana
 
Why Every Tester Should Learn Ruby
Why Every Tester Should Learn RubyWhy Every Tester Should Learn Ruby
Why Every Tester Should Learn Ruby
Raimonds Simanovskis
 
Javascript1
Javascript1Javascript1
Javascript1
anas Mohtaseb
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
Fwdays
 
Playing With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsPlaying With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.js
Mike Hagedorn
 
Workshop Consul .- Service Discovery & Failure Detection
Workshop Consul .- Service Discovery & Failure DetectionWorkshop Consul .- Service Discovery & Failure Detection
Workshop Consul .- Service Discovery & Failure Detection
Vincent Composieux
 
Beyond simple benchmarks—a practical guide to optimizing code
Beyond simple benchmarks—a practical guide to optimizing code Beyond simple benchmarks—a practical guide to optimizing code
Beyond simple benchmarks—a practical guide to optimizing code
Particular Software
 
A Discussion on Automatic Programming
A Discussion on Automatic ProgrammingA Discussion on Automatic Programming
A Discussion on Automatic Programming
techmonkey4u
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
Andrii Dembitskyi "Events in our applications Event bus and distributed systems"
Andrii Dembitskyi "Events in our applications Event bus and distributed systems"Andrii Dembitskyi "Events in our applications Event bus and distributed systems"
Andrii Dembitskyi "Events in our applications Event bus and distributed systems"
Fwdays
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's code
Andrey Karpov
 
Why Windows 8 drivers are buggy
Why Windows 8 drivers are buggyWhy Windows 8 drivers are buggy
Why Windows 8 drivers are buggy
Andrey Karpov
 
Javascript
JavascriptJavascript
Javascript
Gita Kriz
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
Abhishek Kesharwani
 
Better Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web ServicesBetter Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web Services
WSO2
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
Phúc Đỗ
 
QA Fest 2019. Антон Молдован. Load testing which you always wanted
QA Fest 2019. Антон Молдован. Load testing which you always wantedQA Fest 2019. Антон Молдован. Load testing which you always wanted
QA Fest 2019. Антон Молдован. Load testing which you always wanted
QAFest
 
Mspec talk
Mspec talkMspec talk
Mspec talk
Edward Wilde
 
Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113
SOAT
 
Qtp test
Qtp testQtp test
Qtp test
G.C Reddy
 

Similar to Vbscript reference (20)

vbscript-reference book
vbscript-reference bookvbscript-reference book
vbscript-reference book
 
Why Every Tester Should Learn Ruby
Why Every Tester Should Learn RubyWhy Every Tester Should Learn Ruby
Why Every Tester Should Learn Ruby
 
Javascript1
Javascript1Javascript1
Javascript1
 
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
"Applied Enterprise Metaprogramming in JavaScript", Vladyslav Dukhin
 
Playing With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsPlaying With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.js
 
Workshop Consul .- Service Discovery & Failure Detection
Workshop Consul .- Service Discovery & Failure DetectionWorkshop Consul .- Service Discovery & Failure Detection
Workshop Consul .- Service Discovery & Failure Detection
 
Beyond simple benchmarks—a practical guide to optimizing code
Beyond simple benchmarks—a practical guide to optimizing code Beyond simple benchmarks—a practical guide to optimizing code
Beyond simple benchmarks—a practical guide to optimizing code
 
A Discussion on Automatic Programming
A Discussion on Automatic ProgrammingA Discussion on Automatic Programming
A Discussion on Automatic Programming
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Andrii Dembitskyi "Events in our applications Event bus and distributed systems"
Andrii Dembitskyi "Events in our applications Event bus and distributed systems"Andrii Dembitskyi "Events in our applications Event bus and distributed systems"
Andrii Dembitskyi "Events in our applications Event bus and distributed systems"
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's code
 
Why Windows 8 drivers are buggy
Why Windows 8 drivers are buggyWhy Windows 8 drivers are buggy
Why Windows 8 drivers are buggy
 
Javascript
JavascriptJavascript
Javascript
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Better Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web ServicesBetter Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web Services
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
 
QA Fest 2019. Антон Молдован. Load testing which you always wanted
QA Fest 2019. Антон Молдован. Load testing which you always wantedQA Fest 2019. Антон Молдован. Load testing which you always wanted
QA Fest 2019. Антон Молдован. Load testing which you always wanted
 
Mspec talk
Mspec talkMspec talk
Mspec talk
 
Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113
 
Qtp test
Qtp testQtp test
Qtp test
 

Recently uploaded

Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Leena Ghag-Sakpal
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 

Recently uploaded (20)

Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 

Vbscript reference

  • 1. VBScript Quick Reference VBScript Quick Reference IGNORE RUNTIME ERRORS FORCE VARIABLE DECLARATION DISPLAY TO STANDARD OUTPUT HTA SECTION <head> On Error Resume Next Option Explicit Wscript.Echo “Display this text” <title>HTA Test</title> <HTA:APPLICATION CHECK FOR AN ERROR CLEAR THE ERROR CACHE DISPLAY TO MESSAGE BOX APPLICATIONNAME="HTA Test" SCROLL="yes" SINGLEINSTANCE="yes" If Err.Number Then Err.Clear WINDOWSTATE="maximize" > MsgBox(“Prompt”, vbOKCancel, “Title”) ‘ an error occurred (execute this statement each </head> </head> End If time you check the Err object) DISPLAY TO POPUP DIALOG BOX SCRIPT SECTION WshShell.Popup(“Message”, 5, “Title”, 1) <script language="VBScript“> COMPUTER VARIABLE (local computer) 5: number of seconds to display popup box Sub window_OnLoad 1: displays the OK and Cancel buttons ' Script to run on startup strComputer = “.” End Sub Sub TestSub ' Script code goes here CONNECT TO WMI End Sub </script> Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2") HTML SECTION QUERY: RETRIEVE ALL PROCESSES <body> <input type="button" value="Run Script" Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process") name="run_button" ") onClick="TestSub"> OPEN TEXT FILE FOR READING </body> QUERY: RETRIEVE ALL SERVICES Const ForReading = 1 Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service") Set objFSO = CreateObject _ ("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile _ COMPUTER VARIABLE (local computer) ("c:scriptsservers.txt", ForReading) strComputer = “localhost” CREATE DICTONARY OBJECT RETRIEVE AN OU OPEN TEXT FILE FOR WRITING Set objDictionary = _ Set objOU = GetObject("LDAP://ou=finance,dc=fabrikam,dc=com") Const ForWriting = 2 CreateObject("Scripting.Dictionary") RETRIEVE A USER ACCOUNT Set objFSO = CreateObject _ ("Scripting.FileSystemObject") POPULATE DICTIONARY OBJECT Set objUser = GetObject("LDAP://cn=ken myer, ou=Finance, dc=fabrikam, dc=com") Set objTextFile = objFSO.OpenTextFile _ ("c:scriptsservers.txt", ForWriting) objDictionary.Add key, item BIND TO THE LOCAL COMPUTER Set colAccounts = GetObject("WinNT://" & strComputer)
  • 2. VBScript Quick Reference VBScript Quick Reference LOOPS For Loops Do Loops For Each x in arr Do Until x > 5 On Error Resume Next CONDITIONAL STATEMENTS ... ... If Then Select Case Next Loop Const ADS_SCOPE_ONELEVEL = 1 If x = 4 Then Select Case x For i = 1 to 10 Do While x < 5 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") … Case 1 ... ... objConnection.Provider = "ADsDSOObject" ElseIf x = 5 ... Next Loop objConnection.Open "Active Directory Provider" Then Case 2 Set objCommand.ActiveConnection = objConnection … ... Do Else Case Else While Loops ... objCommand.Properties("Page Size") = 1000 Loop Until x > 5 objCommand.Properties("Searchscope") = ADS_SCOPE_ONELEVEL ... … End If End Select While x < 5 … Do objCommand.CommandText = _ "SELECT Name FROM 'LDAP://OU=finance,dc=fabrikam,dc=com'“ Wend ... Learn more about scripting Loop While x < 5 Set objRecordSet = objCommand.Execute from the Microsoft Windows 2000 Scripting Guide, ARRAYS available online (and yes, despite the title most of the arrItems = concepts apply to later Array("a","b","c") FUNCTIONS AND SUBROUTINES versions of Windows too): Function Subroutine Dim arr(2) http://www.microsoft.com arr(0) = 20 Function TestFunc Sub TestSub /technet/scriptcenter/guide arr(1) = 30 … … EXCEL TestFunc = 10 End Sub ReDim Preserve arr(3) End Function Set objExcel = CreateObject("Excel.Application") arr(2) = 40 objExcel.Visible = True Set objWorkbook = objExcel.Workbooks.Add WORD Set objWord = CreateObject("Word.Application") objWord.Visible = True Set objDoc = objWord.Documents.Open("c:scriptstest.doc") SEND OUTPUT TO COMMAND WINDOW SET DEFAULT TO CSCRIPT ACCESS Set objAccess = CreateObject("Access.Application") C:> cscript test.vbs C:> cscript //H:cscript objAccess.OpenCurrentDatabase "C:ScriptsTest.mdb" OUTLOOK SEND OUTPUT TO MESSAGE BOX SET DEFAULT TO WSCRIPT Set objOutlook = CreateObject("Outlook.Application") Set objNamespace = objOutlook.GetNamespace("MAPI") C:> wscript test.vbs C:> cscript //H:wscript OUTLOOK