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

Más contenido relacionado

La actualidad más candente (20)

Cpp
Cpp Cpp
Cpp
 
Debugging JavaScript with Chrome
Debugging JavaScript with ChromeDebugging JavaScript with Chrome
Debugging JavaScript with Chrome
 
MFC Brush
MFC BrushMFC Brush
MFC Brush
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
P2
P2P2
P2
 
Richard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleRichard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL Module
 
The Big Three
The Big ThreeThe Big Three
The Big Three
 
Chapter9
Chapter9Chapter9
Chapter9
 
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp Shadbox ERC223
 
Oops in c++
Oops in c++Oops in c++
Oops in c++
 
Kapacitor Alert Topic handlers
Kapacitor Alert Topic handlersKapacitor Alert Topic handlers
Kapacitor Alert Topic handlers
 
Rcpp11 genentech
Rcpp11 genentechRcpp11 genentech
Rcpp11 genentech
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Ruby haskell extension
Ruby haskell extensionRuby haskell extension
Ruby haskell extension
 
กลุ่ม6
กลุ่ม6กลุ่ม6
กลุ่ม6
 
ClojureScript - A functional Lisp for the browser
ClojureScript - A functional Lisp for the browserClojureScript - A functional Lisp for the browser
ClojureScript - A functional Lisp for the browser
 
Conversion of data types in java
Conversion of data types in javaConversion of data types in java
Conversion of data types in java
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 

Destacado (11)

Red sox game
Red sox gameRed sox game
Red sox game
 
Magazine Beach Clean Up
Magazine Beach Clean UpMagazine Beach Clean Up
Magazine Beach Clean Up
 
Proceso fabril
Proceso fabrilProceso fabril
Proceso fabril
 
752 presentation
752 presentation752 presentation
752 presentation
 
Acto creativo
Acto creativoActo creativo
Acto creativo
 
SAN PEDRO
SAN PEDROSAN PEDRO
SAN PEDRO
 
Sap fi configuration
Sap fi configurationSap fi configuration
Sap fi configuration
 
Segurança da informação golpes, ataques e riscos
Segurança da informação golpes, ataques e riscosSegurança da informação golpes, ataques e riscos
Segurança da informação golpes, ataques e riscos
 
John locke biography
John locke biographyJohn locke biography
John locke biography
 
The Evolution and Future of Hadoop Storage (Hadoop Conference Japan 2016キーノート...
The Evolution and Future of Hadoop Storage (Hadoop Conference Japan 2016キーノート...The Evolution and Future of Hadoop Storage (Hadoop Conference Japan 2016キーノート...
The Evolution and Future of Hadoop Storage (Hadoop Conference Japan 2016キーノート...
 
Literary theory & criticism.
Literary theory & criticism.Literary theory & criticism.
Literary theory & criticism.
 

Similar a vbscript-reference book

Vbscript reference
Vbscript referenceVbscript reference
Vbscript referenceRahul Ranjan
 
Analysis of the Ultimate Toolbox project
Analysis of the Ultimate Toolbox projectAnalysis of the Ultimate Toolbox project
Analysis of the Ultimate Toolbox projectPVS-Studio
 
Analysis of the Ultimate Toolbox project
Analysis of the Ultimate Toolbox projectAnalysis of the Ultimate Toolbox project
Analysis of the Ultimate Toolbox projectPVS-Studio
 
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 ServicesWSO2
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the mastersAra Pehlivanian
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
Checking Oracle VM VirtualBox. Part 1
Checking Oracle VM VirtualBox. Part 1Checking Oracle VM VirtualBox. Part 1
Checking Oracle VM VirtualBox. Part 1Andrey Karpov
 
NodeJS: the good parts? A skeptic’s view (jax jax2013)
NodeJS: the good parts? A skeptic’s view (jax jax2013)NodeJS: the good parts? A skeptic’s view (jax jax2013)
NodeJS: the good parts? A skeptic’s view (jax jax2013)Chris Richardson
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Ben Lesh
 
Aaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security TeamsAaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security Teamscentralohioissa
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical FileAshwin Francis
 
Hidden Gems in Swift
Hidden Gems in SwiftHidden Gems in Swift
Hidden Gems in SwiftNetguru
 

Similar a vbscript-reference book (20)

Vbscript reference
Vbscript referenceVbscript reference
Vbscript reference
 
Analysis of the Ultimate Toolbox project
Analysis of the Ultimate Toolbox projectAnalysis of the Ultimate Toolbox project
Analysis of the Ultimate Toolbox project
 
Analysis of the Ultimate Toolbox project
Analysis of the Ultimate Toolbox projectAnalysis of the Ultimate Toolbox project
Analysis of the Ultimate Toolbox project
 
Qtp test
Qtp testQtp test
Qtp test
 
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
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the masters
 
Oop1
Oop1Oop1
Oop1
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Day 1
Day 1Day 1
Day 1
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
Checking Oracle VM VirtualBox. Part 1
Checking Oracle VM VirtualBox. Part 1Checking Oracle VM VirtualBox. Part 1
Checking Oracle VM VirtualBox. Part 1
 
Multi qubit entanglement
Multi qubit entanglementMulti qubit entanglement
Multi qubit entanglement
 
NodeJS: the good parts? A skeptic’s view (jax jax2013)
NodeJS: the good parts? A skeptic’s view (jax jax2013)NodeJS: the good parts? A skeptic’s view (jax jax2013)
NodeJS: the good parts? A skeptic’s view (jax jax2013)
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
 
Aaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security TeamsAaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security Teams
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
Hidden Gems in Swift
Hidden Gems in SwiftHidden Gems in Swift
Hidden Gems in Swift
 

Más de Anand Dhana

Más de Anand Dhana (6)

bluetooth-security
bluetooth-securitybluetooth-security
bluetooth-security
 
descriptive programming
descriptive programmingdescriptive programming
descriptive programming
 
bluetooth
bluetooth bluetooth
bluetooth
 
vbscripting
vbscriptingvbscripting
vbscripting
 
vb script
vb scriptvb script
vb script
 
loadrunner
loadrunnerloadrunner
loadrunner
 

Último

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 

Último (20)

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 

vbscript-reference book

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