IPAddr
Visual Basic vs VBScript Functions
Visual BasicVBScriptPurpose
Number Functions
Abs(Number) Absolute Value
Atn(angle) ArcTangent
Cos(angle) Cosine
Exp(Number) Expential
Fix(Number) Integer Value
Int(Number) Integer Value
Hex[$](number) Hexadecimal Value
IsNumeric(variant) test for Numeric
Log(number) Logarithm
Oct[$](number) Octal Value
Rnd[(number)] Random Number
Sgn(number) Sign (+/0/-)
Sin(angle) Sine
Sqr(number) SQuare Root
Tan(angle) Tangent
Val(stringexpression) Numeric Value
String Functions
Asc(StringExpression)  
Chr[$](charcode)  
InStr([start, ]strexpr1, strexpr2)CHARINDEX(strexpr2, strexpr1[, start_location])Find Position of strexpr2 in strexpr1
InStr(start, strexpr1, strexpr2[, compare])  
LCase[$](strexpr)  
Left[$](strexpr, n)Left(strexpr, n) 
LTrim[$](stringexpr)LTrim(stringexpr)Removes leading spaces from a string
Mid[$](stringexpr, start[, length])SubString(stringexpr, start, length) 
Right[$](strexpr, n)Right(strexpr, n) 
RTrim[$](stringexpr)RTrim(stringexpr)Removes trailing spaces from a string
Space[$](number)  
Spc(number)  
Str[$](number)  
StrComp(stringexpr1, stringexpr2[, compare])  
String[$](number, charcode)  
String[$](number, string)  
Trim[$](stringexpr)RTrim(LTrim(stringexpr))Removes leading and trailing spaces from a string
UCase[$](strexpr)  
Date Functions
CVDate(Expression)  
DateAdd(interval, number, date)  
DateDiff(interval, date1, date2)  
DatePart(interval, date)  
DateSerial(year, month, day)  
DateValue(stringexpression)  
Day(dateexpression)  
Hour(dateexpression)  
IsDate(variant)  
Minute(dateexpression)  
Month(dateexpression)  
Second(dateexpression)  
TimeSerial(hour, minute, second)  
TimeValue(stringexpression)  
Weekday(dateexpression)  
Year(dateexpression)  
Financial Functions
FV(rate, nper, pmt, pv, due)  
IPmt(rate, per, nper, pv, fv, due)  
IRR(valuearray(), guess)  
MIRR(valuearray(), financerate, reinvestrate)  
NPer(rate, pmt, pv, fv, due)  
NPV(rate, valuearray())  
Pmt(rate, nper, pv, fv, due)  
PPmt(rate, per, nper, pv, fv, due)  
PV(rate, nper, pmt, fv, due)  
Rate(nper, pmt, pv, fv, due, guess)  
SLN(cost, salvage, life)  
SYD(cost, salvage, life, period)  
Other Functions
Choose(Index, Expr1, Expr2...)  
Format[$](expression[, fmt])  
IIf(expr, truepart, falsepart)  
IsEmpty(variant)  
IsNull(variant)  
Partition(number, start, stop, interval)  
Switch(varexpr1, var1[, varexpr2, var2...[, varexpr7, var7]])  
VarType(variant)  


  [Environ.vbs]
  Dim WSHShell
  Set WSHShell = WScript.CreateObject("WScript.Shell")
  WScript.Echo "The current PATH is " & WSHShell.Environment.item("path")
  WScript.Echo "Creating a new environment variable called RealHome"
  ' this variable will exist only during execution time of this script (Win95)   
  WSHShell.Environment.item("RealHome") = "Hello world"
  WScript.Echo "Realhome is " & WSHShell.Environment.item("RealHome")
  Set WSHShell = Nothing    
  WScript.Quit(0)
  

 

  [reg.vbs] 
  Dim WSHShell
  Set WSHShell = WScript.CreateObject("WScript.Shell")
  ' write in the HKey_Current_User
  WSHShell.RegWrite "HKCU\RealHome\", "Welcome"
  WSHShell.RegWrite "HKCU\RealHome\How-to", "Java"
  WSHShell.RegWrite "HKCU\RealHome\How-to", "Javascript"
  WSHShell.RegWrite "HKCU\RealHome\How-to", "PB"
  WSHShell.RegWrite "HKCU\RealHome\How-to", "VBScript"
  WSCript.Echo "Value of HKCU\Realhome is " & WSHShell.RegRead("HKCU\RealHome\")
  Set WSHShell = Nothing
  WScript.Quit(0)

Property:  WshShell.Environment

WshShell.Environment([strType])

The Environment property returns the WshEnvironment object. The optional parameter strType can be either "System", "User", "Volatile", or "Process". If strType is omitted, this property retrieves the "System" environment variables in Microsoft Windows 2000 or the "Process" environment variables in Windows 95/98.

The following table lists some of the variables that are provided with the Windows operating system. None of these variables are available from the "Volatile" environment type.

NameDescriptionWindows 2000Windows 95/98
NameDescriptionSystemUserProcessProcess
NUMBER_OF_PROCESSORSNumber of processors running on the machine.X X 
PROCESSOR_ARCHITECTUREProcessor type of the user's workstation.X X 
PROCESSOR_IDENTIFIERProcessor ID of the user's workstation.X X 
PROCESSOR_LEVELProcessor level of the user's workstation.X X 
PROCESSOR_VERSIONProcessor version of the user's workstation.X X 
OSOperating system on the user's workstation.X X 
COMSPECExecutable file for the command prompt (typically cmd.exe).X XX
HOMEDRIVEPrimary local drive (typically the C drive).  X 
HOMEPATHDefault directory for users (Typically \users\default in Windows 2000).  X 
PATHPATH environment variable.XXXX
PATHEXTExtensions for executable files (typically .com, .exe, .bat, or .cmd).X X 
PROMPTCommand prompt (typically $P$G).  XX
SYSTEMDRIVELocal drive on which the system directory resides (typically c:\).  X 
SYSTEMROOTSystem directory (for example, c:\winnt). This is the same as WINDIR.  X 
WINDIRSystem directory (for example, c:\winnt). This is the same as SYSTEMROOT.X XX
TEMPDirectory for storing temporary files (for example, c:\temp). XXX
TMPDirectory for storing temporary files (for example, c:\temp). XXX
<% Dim WSHShell, objEnv Set WSHShell = CreateObject("WScript.Shell") For Each Name in WSHShell.Environment %> <%= Name %> <%= WSHShell.Environment.item(Name)%> <% Next %> <%Set WSHShell = Nothing %>

The following VBScript code retrieves the operating system on the current system and echoes the result to the user.


  Code:
  Set WshShell = WScript.CreateObject("WScript.Shell")
  Set objEnv = WshShell.Environment("System")
  WScript.Echo objEnv("OS") 

  Output:
  WINDOWS_NT



  <%
  Dim WSHShell, objEnv
  Set WSHShell = CreateObject("WScript.Shell")
  Response.Write "The current USERNAME is " & WSHShell.Environment.item("SYSTEMDRIVE") & "
" Set objEnv = WshShell.Environment("System") Response.Write "OS=" & objEnv("OS") & " USERNAME=" & objEnv("USERNAME") & "
" Set objEnv = WshShell.Environment("USER") Response.Write "OS=" & objEnv("OS") & " USERNAME=" & objEnv("USERNAME") & "
" Set WSHShell = Nothing %>


  
    <% For Each Name in Request.ServerVariables %>
    
    <% Next %>
  
<%= Name %> <%= Request.ServerVariables(Name)%>


  <%
  On Error Resume Next
  Response.Write "All Variables : " & Now() & "
" dim Header, Footer header = "" footer = "
" Response.Write("cookies" & header) for each item in Request.Cookies Response.Write(" " & item & " " & Request.Cookies(item) & "") next Response.Write(footer & "server vars" & header) for each item in request.servervariables Response.Write(" " & item & " -- " & Request.ServerVariables(item) & "") next Response.write(footer & "session contents" & header) for each item in session.contents Response.Write(" " & item & " " & session(item) & "") next Response.write(footer & "application contents" & header) for each item in application.contents Response.Write(" " & item & "") next %>
Script engine : <%= scriptengine() %> <%= scriptenginemajorversion() %>: <%=scriptengineminorversion() %> <%= scriptenginebuildversion() %>