You are on page 1of 2

VBScript Quick Reference VBScript Quick Reference

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


BIND TO THE LOCAL COMPUTER
Set objUser = GetObject("!A"://cn=#en m$er% ou=&in'nce% (c=)'bri#'m% (c=com")
RETRIEVE A USER ACCOUNT
Set objOU = GetObject("!A"://ou=)in'nce%(c=)'bri#'m%(c=com")
RETRIEVE AN OU
strComputer = *loc'l+ost,
COMPUTER VARIABLE (lc!l c"puter#
Set colSer-iceist = objW./Ser-ice012ec3uer$("Select 4 )rom Win567Ser-ice")
QUER$% RETRIEVE ALL SERVICES
Set col"rocessist = objW./Ser-ice012ec3uer$("Select 4 )rom Win567"rocess")
")
QUER$% RETRIEVE ALL PROCESSES
Set objW./Ser-ice = GetObject("8inm9mts:::" & strComputer & ":root:cim-6")
CONNECT TO &MI
strComputer = *0,
COMPUTER VARIABLE (lc!l c"puter#
On 1rror ;esume Ne2t
I'NORE RUNTIME ERRORS
Option 12plicit
(ORCE VARIABLE DECLARATION
/) 1rr0Number T+en
< 'n error occurre(
1n( /)
CHEC) (OR AN ERROR
1rr0Cle'r
(e2ecute t+is st'tement e'c+
time $ou c+ec# t+e 1rr object)
CLEAR THE ERROR CACHE
Wscript01c+o *!ispl'$ t+is te2t,
DISPLA$ TO STANDARD OUTPUT
.s9=o2(*"rompt,% -bO>C'ncel% *Title,)
DISPLA$ TO MESSA'E BO*
Ws+S+ell0"opup(*.ess'9e,% ?% *Title,% @)
?: number o) secon(s to (ispl'$ popup bo2
@: (ispl'$s t+e O> 'n( C'ncel buttons
DISPLA$ TO POPUP DIALO' BO*
A+e'(B
AtitleBCTA TestA/titleB
ACTA:A""/CAT/ON
A""/CAT/ONNA.1="CTA Test"
SC;O="$es" S/NG1/NSTANC1="$es"
W/N!OWSTAT1="m'2imiDe" B
A/+e'(B
A/+e'(B
HTASECTION
Ascript l'n9u'9e="E=Script*B
Sub 8in(o87Ono'(
F Script to run on st'rtup
1n( Sub
Sub TestSub
F Script co(e 9oes +ere
1n( Sub
A/scriptB
SCRIPT SECTION
Abo($B Ainput t$pe="button"
-'lue=";un Script"
n'me="run7button"
onClic#="TestSub"B
A/bo($B
HTML SECTION
Const &or;e'(in9 = @
Set obj&SO = Cre'teObject 7
("Scriptin90&ileS$stemObject")
Set objTe2t&ile = obj&SO0OpenTe2t&ile 7
("c::scripts:ser-ers0t2t"% &or;e'(in9)
OPEN TE*T (ILE (OR READIN'
Const &orWritin9 = 6
Set obj&SO = Cre'teObject 7
("Scriptin90&ileS$stemObject")
Set objTe2t&ile = obj&SO0OpenTe2t&ile 7
("c::scripts:ser-ers0t2t"% &orWritin9)
OPEN TE*T (ILE (OR &RITIN'
Set obj!iction'r$ = 7
Cre'teObject("Scriptin90!iction'r$")
CREATE DICTONAR$ OB+ECT
obj!iction'r$0A(( #e$% item
POPULATE DICTIONAR$ OB+ECT
VBScript Quick Reference
OUTLOO)
C::B cscript test0-bs
SEND OUTPUT TO COMMAND &INDO&
C::B 8script test0-bs
SEND OUTPUT TO MESSA'E BO*
C::B cscript //C:cscript
SET DE(AULT TO CSCRIPT
C::B cscript //C:8script
SET DE(AULT TO &SCRIPT
If T,en
/) 2 = G T+en
H
1lse/) 2 = ?
T+en
H
1lse
000
1n( /)
Select C!-e
Select C'se 2
C'se @
000
C'se 6
000
C'se 1lse
H
1n( Select
CONDITIONAL STATEMENTS
LOOPS
'rr/tems =
Arr'$("'"%"b"%"c")
!im 'rr(6)
'rr(I) = 6I
'rr(@) = 5I
;e!im "reser-e 'rr(5)
'rr(6) = GI
ARRA$S
(UNCTIONS AND SUBROUTINES
(r Lp-
&or 1'c+ 2 in 'rr
000
Ne2t
&or i = @ to @I
000
Ne2t
&,ile Lp-
W+ile 2 A ?
H
Wen(
D Lp-
!o Until 2 B ?
000
oop
!o W+ile 2 A ?
000
oop
!o
000
oop Until 2 B ?
!o
000
oop W+ile 2 A ?
(unctin
&unction Test&unc
H
Test&unc = @I
1n( &unction
Su.rutine
Sub TestSub
H
1n( Sub
VBScript Quick Reference
On 1rror ;esume Ne2t
Const A!S7SCO"17ON11E1 = @
Set objConnection = Cre'teObject("A!O!=0Connection")
Set objComm'n( = Cre'teObject("A!O!=0Comm'n(")
objConnection0"ro-i(er = "A!s!SOObject"
objConnection0Open "Acti-e !irector$ "ro-i(er"
Set objComm'n(0Acti-eConnection = objConnection
objComm'n(0"roperties(""'9e SiDe") = @III
objComm'n(0"roperties("Se'rc+scope") = A!S7SCO"17ON11E1
objComm'n(0Comm'n(Te2t = 7
"S11CT N'me &;O. F!A"://OU=)in'nce%(c=)'bri#'m%(c=comF*
Set obj;ecor(Set = objComm'n(012ecute
Set obj12cel = Cre'teObject("12cel0Applic'tion")
obj12cel0Eisible = True
Set objWor#boo# = obj12cel0Wor#boo#s0A((
Set objWor( = Cre'teObject("Wor(0Applic'tion")
objWor(0Eisible = True
Set obj!oc = objWor(0!ocuments0Open("c::scripts:test0(oc")
Set objAccess = Cre'teObject("Access0Applic'tion")
objAccess0OpenCurrent!'t'b'se "C::Scripts:Test0m(b"
Set objOutloo# = Cre'teObject("Outloo#0Applic'tion")
Set objN'mesp'ce = objOutloo#0GetN'mesp'ce(".A"/")
OUTLOO)
ACCESS
&ORD
E*CEL
e'rn more 'bout scriptin9
)rom t+e Microsoft Windows
2000 Scripting Guide%
'-'il'ble online ('n( $es%
(espite t+e title most o) t+e
concepts 'ppl$ to l'ter
-ersions o) Win(o8s too):
+ttp://8880microso)t0com
/tec+net/scriptcenter/9ui(e

You might also like