Wednesday, February 9, 2011

Debug vbscript & Jscript from Command prompt


How to debug Windows Script Host (WSH) scripts, which can be written in any ActiveX script language (as long as the proper language engine is installed), but which, by default, are written in VBScript and JScript.
There are certain flags in the registry and, depending on the debugger used, certain required procedures to enable debugging.
To debug WSH scripts in Microsoft Visual InterDev, the Microsoft Script Debugger, or any other debugger, use the following command-line syntax to start the script:

               wscript.exe //d

This code informs the user when a runtime error has occurred and gives the user a choice to debug the application. Also, the //x flag can be used, as follows, to throw an immediate exception, which starts the debugger immediately after the script starts running:
               wscript.exe //d //x 

After a debug condition exists, the following registry key determines which debugger will be used:

HKEY_CLASSES_ROOT\CLSID\{834128A2-51F4-11D0-8F20-00805F2CD064}\LocalServer32

The script debugger should be Msscrdbg.exe, and the Visual InterDev debugger should be Mdm.exe.

If Visual InterDev is the default debugger, make sure that just-in-time (JIT) functionality is enabled. To do this, follow these steps:
  1. Start Visual InterDev.
  2. On the Tools menu, click Options.
  3. Click Debugger, and then ensure that the Just-In-Time options are selected for both the General and Script categories.
Additionally, if you are trying to debug a .wsf file, make sure that the following registry key is set to 1:

HKEY_CURRENT_USER\Software\Microsoft\Windows Script\Settings\JITDebug

Friday, February 4, 2011

Creating dictionary using Vbscript


Dim vKey
Dim sItem, sMsg
Dim oDict

'--- Creating a dictionary object
Set oDict = CreateObject("Scripting.Dictionary")

'--- Adding items to dictionary
oDict.Add "One", "Engine"
oDict.Add "Two", "Wheel"
oDict.Add "Three", "Tire"
oDict.Add "Four", "Spanner"

'--- Looping the Collection
For Each vKey In oDict
sItem = oDict.Item(vKey)
'sMsg = sMsg & sItem & vbCrLf
Next

'WScript.Echo (oDict.Count)
'oDict.Item("one") = "temp"
'WScript.Echo sMsg

'wscript.Echo (odict.item(one))
oDict.Key("One") = "nine"
'oDict.Item("nine") = "nine"
oDict.Add "Ten", "ten"

For Each vKey In oDict
sItem = oDict.Item(vKey)
sMsg = sMsg & sItem & " - " &vKey & vbCrLf
Next

WScript.Echo sMsg

WScript.Echo "===============Again============="

WScript.Echo (oDict.Exists ("One"))
WScript.Echo (oDict.Exists ("nine"))
WScript.Echo (oDict.Exists ("Ten"))

'WScript.Echo (odict.item(One))1
'WScript.Echo (odict.item(nine))
'WScript.Echo (odict.item(Ten))

For Each vKey In oDict
sItem = oDict.Item(vKey)
WScript.Echo (sItem & " - " & vKey)
Next

If oDict.Exists("One") Then
WScript.Echo "heello"
End If


If oDict.Exists("nine") Then
WScript.Echo "heello"
End If

Dim temp()
Dim count, counter
count = oDict.Count
WScript.Echo (count)

WScript.Echo
ReDim temp(count)
counter = 0
For Each key In oDict
temp(counter) = key
' WScript.Echo key & " - " & counter
' WScript.Echo temp(counter)
counter = counter+1
Next


'WScript.Echo ("oDict.Keys")

Vbscript Function Related to Date

dtm1="18-Feb-10"
dtm2="19-Aug-10"

'To Get difference between two date
WScript.Echo "Difference between " & dtm1 & " and " & dtm2

'To Get month difference
intMonthsDifferent=DateDiff("m", dtm1, dtm2)
WScript.Echo "In month: " & intMonthsDifferent

'To Get date difference
intDateDifferent=DateDiff("d", dtm1, dtm2)
WScript.Echo "In date: " & intDateDifferent

If intMonthsDifferent > 0 Then
WScript.Echo "postive"
Else
WScript.Echo "negative"
End If

'Difference In date with difference format Another example

dtm1="18/02/1999"
dtm2="18/03/1998"

WScript.Echo "Difference between " & dtm1 & " and " & dtm2
intMonthsDifferent=DateDiff("m", dtm1, dtm2)
WScript.Echo "In month: " & intMonthsDifferent
intDateDifferent=DateDiff("d", dtm1, dtm2)
WScript.Echo "In date: " & intDateDifferent

If intMonthsDifferent > 0 Then
WScript.Echo "postive"
Else
WScript.Echo "negative"
End If

WScript.Echo "-----------------------------------------------"
WScript.Echo "Function To Get different value of current Date"
WScript.Echo "-----------------------------------------------"

WScript.Echo "Current Date:- " &(Date ())
WScript.Echo "Current Time:- " &(Time ())
WScript.Echo "Current Time:- " & TimeValue (Time)
WScript.Echo "Current Time and date:- " & Now ()
WScript.Echo "Hours:- " & Hour (Time)
WScript.Echo "Month:- " & Month (Date)
WScript.Echo "Second:- " & Second (time)
WScript.Echo "Total Seconds:- " & Timer ()
WScript.Echo "Time with User's Argument:- " & TimeSerial (13,56,8)
WScript.Echo Weekday (Date)
WScript.Echo "Day's name as per index:- " & WeekdayName(Weekday(1))
WScript.Echo "Day's name as per index:- " & WeekdayName(Weekday(2))
WScript.Echo "Day's name as per index:- " & WeekdayName(Weekday(3))
WScript.Echo "Day's name as per index:- " & WeekdayName(Weekday(8))
WScript.Echo "Month's name as per index:- " & MonthName (1)
WScript.Echo "Month's name as per index:- " & MonthName (12)

Data Type Validation in Vbscript

Dim temp
WScript.Echo (VarType (temp))
WScript.Echo (TypeName (temp))
WScript.Echo

temp = 3
WScript.Echo (VarType (temp))
WScript.Echo (TypeName (temp))
WScript.Echo

temp = 3111111
WScript.Echo (VarType (temp))
WScript.Echo (TypeName (temp))
WScript.Echo

temp = "afsda"
WScript.Echo (VarType (temp))
WScript.Echo (TypeName (temp))
WScript.Echo

ReDim temp(6)
WScript.Echo (TypeName (temp))
WScript.Echo

temp(0) = 1
temp(1) = 1
WScript.Echo (VarType (temp))

WScript.Echo (vbSunday)
WScript.Echo (TypeName (temp))

Playing with array

WScript.echo "-------------------------------------------------------"
WScript.echo "Playing with array"
wscript.echo "-------------------------------------------------------"

Dim arrArray
Dim i
Dim sTmp
arrArray = Array(81,117,105,99,107,84,101,115,116,45,80,114,111)

'--- Checking if variable is an array.
If IsArray(arrArray) Then
For i = LBound(arrArray) To UBound(arrArray)
WScript.Echo (arrArray(i))
arrArray(i) = Chr(arrArray(i))
WScript.Echo (arrArray(i))
Next
End If

If IsArray(arrArray) Then
sTmp = Join(arrArray, vbNullString)
MsgBox sTmp
MsgBox vbNullString
MsgBox vbNull
End If

Erase arrArray
MsgBox vbArray
MsgBox vbByte

WScript.echo "-------------------------------------------------------"
WScript.echo "Split to make array n filtering"
wscript.echo "-------------------------------------------------------"


a=Split("Sunday Monday Tuesday WEDNES DAY T h urs dayF r iday Satu r day"," ",-1,1)
a=Split("Sunday Monday Tuesday WEDNES DAY T h urs dayF r iday Satu r day")
for each x in a
WScript.Echo(x)
Next

WScript.Echo
WScript.Echo "Filter Function"
WScript.Echo


WScript.Echo
WScript.Echo "True Function"
WScript.Echo

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True,1)
for each x in b
WScript.Echo (x)
Next

WScript.Echo
WScript.Echo "True Function"
WScript.Echo

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True,0)
for each x in b
WScript.Echo (x)
next

WScript.Echo "True Function"

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True)
for each x in b
WScript.Echo (x)
next



WScript.Echo
WScript.Echo "False"
WScript.Echo


a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",False,1)
for each x in b
WScript.Echo (x)
next

WScript.Echo
WScript.Echo "False"
WScript.Echo


a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",False,0)
for each x in b
WScript.Echo (x)
next

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons