Search this site:
Enterprise Search Blog
« NIE Newsletter

Windows Scripting K2: VSearch Properties

Last Updated Apr 2009

By: Mark Bennett, Volume 2 - Issue 1 - June 2004

An old support adage is When you're sure everything is right, and it still doesn't work, something you are sure of is wrong.

Sometimes you'll find that a new program you are writing using the VSearch object in K2 is just not working the way you expect. Either it's not finding your Java classes, or the server isn't responding, and you'd really like to know what parameters K2 is using when it initiates the VSearch object.

Verity provides a handy API call: dumpSystemProperties. It shows you all of the properties currently active in the VSearch object, and may have just the information you are looking for to solve your problem.

Listing 1 shows a handy Windows Script Host utility that will list the output of dumpSystemProperties.



' 	Command line VSearch utlity using windows scripting 
' Usage: cscript proplist.vbs
' Display all VSearch system properties

' Provided by New Idea Engineering Inc (http://www.ideaeng.com)
' Copyright 2004 New Idea Engineering, Inc.
'
' Code and functions may be copied and used for your personal use
' or for your use in your company as long as the original copyright
' is included.
'
' For more information contact info@ideaeng.com

Dim rowCnt
Dim vsObj
Dim buffer
Dim offset
Dim sLen
Dim comma
Dim parm
Dim pairCnt
Dim parmArray(50,2)
'
' define tab character for output formatting
'
Dim tab
tab = chr(9)

' create output file handle
set conOut = WScript.StdOut

' create the VSearch object and get system properties
set vsObj = CreateObject("Verity.VSearch")
buffer = vsObj.dumpSystemProperties()

'
' the dumpSystemProperties returns a string containing
' name/value pairs for the items important to K2. Pairs
' are of the format
' name=value
' and are seperated by commas.
'

' begin parsing of the system property string
sLen = len(buffer)
rowCnt = 1
offset = 1

'
' process each name/value pair as encountered
'
while (offset < sLen)
comma = instr(offset,buffer,",")
if comma > 0 then
parm = mid(buffer,offset,comma-offset)
offset = comma + 1
else
parm = mid(buffer,offset)
offset = sLen + 1
end if
parm = fixup(parm)
'
' parm now contains the name=value pair
' parse the elements into an array

parmArray(rowCnt,1) = getName(parm)
parmArray(rowCnt,2) = getValue(parm)

'
' and continue looping
'
rowCnt = rowCnt + 1
wend

'
' all name=value pairs have been split into parmArray
' begin output
'
pairCnt = rowCnt - 1

for rowCnt=1 to pairCnt
conOut.writeline(parmArray(rowCnt,1) + tab + parmArray(rowCnt,2))
next

' ================ end of program ==================

'
' function definitions
'
function fixup(buf)
' trim leading and trailing {} and spaces
buf = trimCh(buf,"{")
buf = trimCh(buf,"}")
buf = trim(buf)
fixup = buf
end function

function trim(buf)
' remove leading and trailing spaces from buf
buf = ltrim(buf)
buf = rtrim(buf)
trim = buf
end function

function trimCh(buf,ch)
' trim character ch from string buf if in leading or trailing positions
if(instr(buf,ch)=1) then ' leading position
buf = mid(buf,2)
end if
if(instr(buf,ch)=len(buf)) then 'trailing position
buf = left(buf,len(buf)-1)
end if
trimCh = buf
end function

function getName(buf)
' extract the left portion of the name/value pair in the
' form
' name=value
'
getName = left(buf,instr(buf,"=")-1)
end function


function getValue(buf)
' extract the right portion of the name/value pair in the
' form
' name=value
'
getValue = right(buf,(len(buf) - instr(buf,"=")))
end function

' end

Listing 1

Running the Program

cscript //NOLOGO proplist.vbs

Partial Sample Output

os.name.applet		true
java.vendor.url http://www.microsoft.com/
user.name administrator
user.region US
ile.separator.applet true
file.separator \
os.name Windows NT
os.version 5.0
awt.toolkit com.ms.awt.WToolkit
file.encoding Cp1252
java.version 1.1.4
java.class.path C:\WINNT\java\classes\;D:\Dev\wsh\;
...

Once you've seen all the parameters VSearch is using, you can at least replicate the environment as you test your application.

Viewing the data file in Excel

Because the program uses a tab character to seperate the name - value pairs, you can redirect the output to a file, and then import that into Excel.

  • Run the program and redirect output to a file
    cscript //NOLOGO proplist.vbs > csvfile.txt
  • Start Excel
  • Open the file (csvfile.txt in this example
  • Configure Excel to import using the tab character as the field delimiter
  • Re-Size the column

Note that if you give the file a csv extention, Excel will open the file but not treat the tab characters as column delimiters. Caveat emptor.

Done!

Caveats?

The script needs to be run on a system where Verity K2 is installed in order to have access to the VSearch object.

The properties retruned by dumpSystemProperties may change inthe future, or the call itself may be deprecated. Also, since unauthorized use of this script could expose configuration parameters you would rather keep private, use care to secure execution permission of the script to users and administrators you trust.

As mentioned, Excel will attempt to load the data file without any processing if you don't start Excel and open the data file. If you do not use the 'File|Open' menu, Excel will load the file without any tab delimiter processing. The same appears true if you name the data file with a csv file extension: keep to non-Excel-related file names and Excel will prompt you for the import.