Testing Properties and Methods.

 

When ScriptEZ.API based script file is running, an identification area is appended

to the system menu of the console windows as following:

 

 

'//////////////////////////////////////////////////////////////////////////////

' Author: SY

' Demo ScriptEZ.API based application which uses facilities from RAD API:

' . Echo() method usage which displays always messages into a console window

'   instead of WScript.Echo() with 2 behaviours for cscript.exe or wscript.exe

' . ScriptEZ.API Remoting Control Interface usage by NPTelnet.exe program

'   (Connect to ScriptEZ.API process with <processid (PID)> as connection name)

'

' Purpose: Reviewing and testing miscellaneous methods and properties

'//////////////////////////////////////////////////////////////////////////////

 

const SCRIPTEZ_API = "ScriptEZ.API" ' Component name

 

Dim ScriptEZMain

Dim onExit

 

' start the script

'/////////////////

'On Error Resume Next

Main()

 

' Main Subroutine

'////////////////

Sub Main()

 

  onExit       = 3

 

  ' instantiate component object with callback interface

  Set ScriptEZMain = WScript.CreateObject(SCRIPTEZ_API,"ScriptEZMain_")

  If Not IsObject(ScriptEZMain) Then Exit Sub

 

  hWndFlash = ScriptEZMain.CreateFlashWindow(0,"Script de démo sur l'usage des"+vbLF+"méthodes/propriétés du composant ScriptEZ.API")

  r = ScriptEZMain.SetWindowText(hWndFlash,WScript.ScriptName)

  'ScriptEZMain.SetCPUCoreAffinity "0"

 

  ' Connect to an Index Server (aka ISF Desktop Server) and query for all indexed files

  r = ScriptEZMain.IndexServerConnect("local","gestionnaire","ga")

  If r = 0 Then

      rows = ScriptEZMain.IndexServerRunQuery(" (#filename *) & @size>0",11)

      c = 0

      Do Until Len(rows) <= 0

        ValList = Split(rows,vbLF)

        c = c  + UBound(ValList,1)

        ScriptEZMain.Echo rows

        ScriptEZMAin.FreeBSTR rows

        rows = ScriptEZMain.IndexServerRunQuery("",11)

      Loop

  Else

      MsgBox ScriptEZMain.IndexServerGetErrorMessage

  End If 

  r = ScriptEZMain.IndexServerDisconnect

  MsgBox Cstr(r) + " | Index Server found " + CStr(c) + " file(s)"

 

  ' IP address and hostname request

  IP = ScriptEZMain.HostnameToIPAddress

  If Len(IP) > 0 Then

   IPArray = Split(IP,";")

   IPMask=ScriptEZMain.HostnameToIPAddress(IPArray(0))

   ScriptEZMain.Echo IPArray(0) + "/" + IPMask

   ScriptEZMain.FreeBSTR IP

   ScriptEZMain.FreeBSTR IPMask

  End If

 

  Host = ScriptEZMain.IPAddressToHostname(IPArray(0))

  If Len(Host) > 0 Then

   ScriptEZMain.Echo Host

   ScriptEZMain.FreeBSTR Host

  End If

 

  ' Testing different priority classes for this current process

  ScriptEZMain.SetCPUCoreAffinity "priority_high:0"

  MsgBox "High Priority"  

  ScriptEZMain.SetCPUCoreAffinity "priority_above_normal:0"

  MsgBox "Above Normal Priority"  

  ScriptEZMain.SetCPUCoreAffinity "priority_normal:0"

  MsgBox "Normal Priority"  

  ScriptEZMain.SetCPUCoreAffinity "priority_below_normal:0"

  MsgBox "Below Normal Priority"  

  ScriptEZMain.SetCPUCoreAffinity "priority_low:0"

  MsgBox "Low Priority"  

  

  ' Register App for receiving AppEvent(s) with onAppEvent(EventID)

  ScriptEZMain.AppRegister

  ScriptEZMain.SetConsoleTitle "Demo Common Dialogboxes & Http File Reading"

 

  ' Demo for Inputting data in a combobox

  Dim hStringTable

  hStringTable = ScriptEZMain.MallocStringTable(4)

  r = ScriptEZMain.AddStringTableItem(hStringTable,"Choix numéro 01")

  r = ScriptEZMain.AddStringTableItem(hStringTable,"Choix numéro 02")

  r = ScriptEZMain.AddStringTableItem(hStringTable,"Choix numéro 03")

  r = ScriptEZMain.AddStringTableItem(hStringTable,"Choix numéro 05")

  bsRet = ScriptEZMain.InputComboBox(0,"Multi list of values to choose in a combobox...: ",-hStringTable)

  if Len(bsRet) > 0 Then

    MsgBox bsRet

    ScriptEzMain.FreeBSTR bsRet

  End If

 

  ' Demo for Inputting data in a listbox (multi selecting items)

  r = ScriptEZMain.ReplaceStringTableItemAt(hStringTable,"Choix numéro 04",3)

  bsRet = ScriptEZMain.InputListBox(0,"Multi list of values to choose in a listbox...: ",hStringTable)

  if Len(bsRet) > 0 Then

    ValList = Split(bsRet,"|")

    MsgBox bsRet, , "Count(" + CStr(UBound(ValList,1)) + ")"

    For i=0 To UBound(ValList,1)-1

      MsgBox ValList(i)

    Next

    ScriptEzMain.FreeBSTR bsRet

  End If

  ScriptEZMain.FreeStringTable hStringTable

 

  bsRet = ScriptEZMain.GetOpenDlgDirectoryPath("Test Open Directory Dlg...") 

  if Len(bsRet) > 0 then

    MsgBox bsRet

    ScriptEZMain.FreeBSTR bsRet

  End if

 

  bsRet = ScriptEZMain.GetOpenDlgFileName("Tous (*.*)|*.*", "Test Open File Dlg", 95)

  if Len(bsRet) > 0 then

    MsgBox bsRet

    ScriptEZMain.FreeBSTR bsRet

  End if

 

  bsRet = ScriptEZMain.GetSaveDlgFileName("Tous (*.*)|*.*", "Test Save File Dlg", 95)

  if Len(bsRet) > 0 then

    MsgBox bsRet

    ScriptEZMain.FreeBSTR bsRet

  End if

 

  ' Demo http file reading....

  httpFileHandle = ScriptEZMain.OpenHttpFile("http://sites.google.com","site/sovannpub/home/Product_versions.xml")

  If httpFileHandle > 0 Then

      r = ScriptEZMain.HttpReadFile(httpFileHandle)

      If r = 1 Then

        bsRet = ScriptEZMain.HttpGetReadBufferAsBSTR(httpFileHandle)

        ScriptEZMain.Echo ". Read from http://sites.google.com/site/sovannpub/home/Product_versions.xml: " + _

                          CStr(ScriptEZMain.HttpGetReadBytes(httpFileHandle)) + " byte(s)" + vbLF

        ScriptEZMain.Echo bsRet

        ScriptEZMain.FreeBSTR bsRet

      End If

      ScriptEZMain.CloseHttpFile httpFileHandle

  End If

 

  hXMLObject = ScriptEZMain.CreateXMLObject("<MAINTOPIC Attribute1='007' Attribute2='77'><ELEMENT Value='-3'/></MAINTOPIC>")

  If hXMLObject > 0 Then

    val = ScriptEZMain.NamedItemValue(hXMLObject,"Attribute1")

    If Len(val) > 0 Then

      ScriptEZMain.Echo "MAINTOPIC.Attribute1='" + val + "'"

      ScriptEZMain.FreeBSTR val

    End If

 

    val = ScriptEZMain.NamedItemValueFromElement(hXMLObject,"ELEMENT", "Value")

    If Len(val) > 0 Then

      ScriptEZMain.Echo "ELEMENT.Value='" + val + "'"

      ScriptEZMain.FreeBSTR val

    End If

    ScriptEZMain.DestroyXMLObject hXMLObject

  End If

 

  ' Demo ftp file reading (download)....

  MsgBox "Ce script va à présent tenter de télécharger et ouvrir le fichier README.TXT depuis ftp.microsoft.com",vbInformation,"Demo Ftp"

  hFtpConnection = ScriptEZMain.OpenFtpConnection("ftp://ftp.microsoft.com","","")

  '--- or with the following format

  'hFtpConnection = ScriptEZMain.OpenFtpConnection("ftp://ftp.microsoft.com:21","","")

  If hFtpConnection > 0 Then

    r = ScriptEZMain.FtpDownloadFile(hFtpConnection,"/Softlib/README.TXT","c:\Readme.txt")

    ScriptEZMain.CloseFtpConnection hFtpConnection

    If r = 1 Then

      Set WshShell = WScript.CreateObject("WScript.Shell")

      WshShell.Run "Notepad.exe c:\Readme.txt",3,true

    End If

  End If

 

  ' crypting data

  test = "Ceci est un court texte en clair daté du " + CStr(Date) + " " + CStr(Time)

  crypted = ScriptEZMain.EncryptBSTR(test,"topsecret")

  Msgbox "Texte Original....: " + test + vbLF + vbLF +"Après cryptage..:"+ crypted

  uncrypted = ScriptEZMain.EncryptBSTR(crypted,"topsecret")

  Msgbox "Texte Original....: " + test + vbLF + vbLF + "Après décryptage:" + uncrypted

  ScriptEZMain.FreeBSTR crypted

  ScriptEZMain.FreeBSTR uncrypted

 

 

  r = ScriptEZMain.DestroyWindow(hWndFlash)

  ' block until socket break or exit event

  Do Until onExit = 3

      WScript.Sleep 1000

  Loop

 

  ' App unregister before ending

  ScriptEZMain.AppUnregister

  WScript.Sleep 4000

  Set ScriptEZMain = Nothing

 

End Sub

 

' Callbacks for App Events notification and fetching help text

'/////////////////////////////////////////////////////////////

Sub ScriptEZMain_onAppEvent(EventID)

 

 ScriptEZMain.Echo " -> EventID:" + CStr(EventID)

 Select Case EventID

   Case 3  onExit= 3

 End Select

 

End Sub

 

Function ScriptEZMain_AppEventHelp()

 

 ScriptEZMain_AppEventHelp = vbLF +_

  CStr("Filename: " + Chr(34) + CStr(WScript.ScriptFullName) + Chr(34) + vbLF +_

       "  **** Supported AppEvents ****" + vbLF +_

       "AppEventID = 3" + vbTab + "to exit" + vbLF _

       )

 

End Function