WSTools

WSTools (32- & 64-bit component)
(c) 2020 WizardSoft - info@wizardsoft.nl
Download Buy@MyCommerce

WSTools is a collection of functions that extend VBScript/JScript/MS Office VBA/VB6/ASP and any other programming/scripting language that supports Automation/ActiveX components like PowerShell or C#. It can be useful for scripters, programmers, MS Excel and Access VBA developers, system- and network administrators and any IT-department in general. It does not rely on or use Microsoft .NET. WSTools is a compiled small, fast and native binary DLL.

It supports functions related to Windows settings, network/internet download/upload, secure string and file hashing, encryption/decryption, sorting data, asking user input , calling win32 API functions directly from VBScript/JScript, send e-mails by script, JSON processing and more. All fits in an uncompressed 400 KB DLL. Look at some examples to get an idea of what is possible.

The product is licensed per named developer and includes 1 year of updates/upgrades. Product versions released during the included 1 year maintenance period stay completely functional during and after this period. Please read license Agreement for full details on permitted usage.

There are 2 options for Object Registration & Creation:
A) System-wide registration:
Register the DLL with regsvr32 WSToolkit64.dll (administrator rights necessary)
Test with:

Dim WS
Set WS = CreateObject("WS.Tools")
WS.Noop

B) Registration free (no administrator rights necessary)

Dim CTX, WS
Set CTX = CreateObject("Microsoft.Windows.ActCtx")
CTX.Manifest = "WSTools64.sxs.manifest"
Set WS = CTX.CreateObject("WS.Tools")
WS.Noop

WSTools will display a license message popup once in a while if it is not licensed.

Constants

Const HASH_CRC32 = 0, HASH_MD5 = 1, HASH_SHA1 = 2, HASH_SHA256 = 3, HASH_SHA512 = 4
Const SORT_Ascending = 0, SORT_Decending = 1
Const SORT_Case = 0, SORT_IgnoreCase = 1
Const ENC_ASCII = 0, ENC_UTF8 = 1, ENC_UNICODE = 2, ENC_UTF8BOM = 3, ENC_DETECT = 4
Const HTTP_Get = 0, HTTP_Post = 1, HTTP_Put = 2, HTTP_Patch = 3, HTTP_Delete = 4

Function Overview

Default type: Long
.s: String
.a: Array
(PX = ): Optional Parameter

No exceptions are thrown. Functions return True, False or a number to indicated success or failure.

Note that Variant variables can contain binary data in their string value (BSTR) if needed.

Generic

UnlockComponent(Code.s)
    Unlock WSTools using your unique registration code.

About()
    Displays WSTools version and license information.

Noop()
    No-Operation: test function.    

System Settings

AudioVolume(Volume) 
    Sets global sound volume to a percentage between 0 and 100. Returns previous volume.

AudioMute(Mute)
    Mute or unmute the sound volume.

MonitorBrightness(Brightness)
    Sets brightness of all supported attached monitors to Brightness (normally a value between 0 and 100).
    Returns the last monitor's previous brightness. Side note: many screens (and users) are better off with settings as low as 10..30.

ExplorerRefresh()
    Refreshes Windows desktop/taskbar/explorer icons.   

ClipboardGet.s()
    Returns clipboard item as text.

ClipboardSet(Text.s)
    Sets clipboard item to Text.

Beep(Freq = 750, Duration = 300)
    Plays tone. 

KeySend(KeyCode)
    Sends KeyCode (virtual key code) to active program.

LocaleDecimal
    Returns user's decimal separator

LocaleThousands
    Returns user's thousands separator

UserIsAdmin()
    Returns True when current user is admin/elevated.

UserLanguages.a()
    Returns array with current user's language preferences (e.g., en-US).

Cmd.s(Cmd.s, Async = False)
    Runs Cmd (can be any native command like dir c:\) and returns output. Unicode compatible.
    When Async is True, it returns the path to a log file that is available when Cmd is finished.
    Output contains both stdout and stderr.

RunAsAdmin(Program.s, Parameters.s = )
    Displays UAC-dialog if necessary to run program Program elevated as administrator.  

GUI

DialogSelectFile.s(Title.s = Open File, DefaultFile.s = , Pattern.s = *.*)
    Shows select-file dialog and returns selected file path as string.

DialogSelectFolder.s(Title.s = Select Folder, DefaultFolder.s = )
    Shows select-folder dialog and returns selected folder as string.

DialogSaveFile.s(Title.s = Save File, DefaultFile.s = , Pattern.s = *.*)
    Shows save-file dialog and returns selected file path as string.

DialogInput.a(#/*/!/@/@@/Field1.s, ...) // text, #=numeric, *=password, !=checkbox, @=date, @@=datetime
    Shows dialog box with a dynamic number of input fields/controls.
    Result is an VB Array sized to the number of fields containing each entered value.

Helpers

ArraySort(Array.a, SortColumn = 0, Order = SORT_Ascending, Case = SORT_IgnoreCase)
    Const SORT_Ascending = 0, SORT_Decending = 1
    Const SORT_Case = 0, SORT_IgnoreCase = 1
    Sorts Array by SortColumn with Order and Case sensitivity.  Uses the QuickSort algorithm.

StringAdd(String.s)
    Add string String to String Builder which makes VERY fast string concatenation possible.

StringValue.s(Delimiter.s = )
    Returns concatenated string from previously added strings (StringAdd). Automatically frees memory.

StringClear()
    Frees memory of String Builder when result is not needed.

BitShiftL(Value, Bits)
    Result = Value << Bits

BitShiftR(Value, Bits)
    Result = Value >> Bits

TextTrim.s(Text.s, Chars.s)
    Trims all characters in Chars from Text.
    WScript.Echo TextTrim("aabbccxyzabczyxcab", "abc") outputs xyzabczyx

TextField.s(Text.s, Index, Delimiter.s)
    Returns field ('column') Index from Text delimited by Delimiter.

TextCompare(Left.s, Right.s)
    Returns textual comparison of Left and Right.
    Ignores case and non-space characters.
    Hello equals héllô
    Result 0: Left < right, 1: equal, 2: left > right

TextNormalize.s(Text.s)
    Returns 'normalized' form of Text with all their accents and diacritical marks replaced with the basic alternative.
    One practical reason for this would be building/using a search index.
    Héllô -> hello
    Bären -> baeren (for German)

DictionaryFromFile(FilePath.s, Dic, Separator = TAB, Enc = ENC_DETECT)
    Adds entries from FilePath to Dic (key <tab> value <crlf>).

DictionaryToFile(FilePath.s, Dic, Keys.a = NULL, Separator = TAB, Enc = #ENC_DETECT, Append = False)
    Saves key and values to FilePath. 
    Optionally support a Keys array which specifies keys and order to export to file.

JsonParse(Text.s)
    Parses Text and returns a JSON object (JavaScript object)
    You can access the array with a For Each loop, json.[index] or json.Item(index).

JsonStringify(Json)
    Returns Json object converted into textual representation (string).

Encoding

Base64Enc.s(Input.s)
    Encodes string Input to MIME base64. Input is converted to UTF-8 (same as PHP base64_encode behavior).

Base64EncBin(Input.s)
    Encodes binary data Input into base64 format.

Base64Dec.s(Input.s)
    Decodes base64 encoded string Input.

Base64DecBin(Input.s)
    Decodes base64 encoded binary data Input.

UrlEnc.s(Input.s)
    Encodes Input to URL-friendly string.

UrlDec.s(Url.s)    
    Decodes Url to string.

Utf8Enc.s(Input.s)
    Encodes string Input to raw UTF-8 data.

Utf8Dec.s(Input.s)
    Decodes raw UTF-8 data Input to string.

UnicodeToAscii(Input.s)
    Returns Input as ASCII bytes UTF-8 string representation.

AsciiToUnicode(Input.s)
    Returns ASCII bytes UTF-8 string representation as unicode. 

Console Settings

CmdClear()
    Clears console screen (CLS).

CmdColor(bg = 0, fg = 7)
    Set console background and foreground color to bg and fg.

CmdKey.s()
    Returns last pressed key (asynchronous).

CmdLocate(x, y)
    Move console cursor to location x, y

CmdPrint(Text.s)
    Prints Text to console.

CmdPrintN(Text.s)
    Prints Text followed by new line to console.

CmdTitle(Title.s)
    Change console title as shown in window title bar.

CmdRemoveCloseWindow()
    Removes the close button and menu item from existing console/terminal.

Encryption

Encrypt.s(Input.s, Password.s, Bits = 128)
    Decodes string Input using the AES algorithm with SHA1 key derived from Password. AES-128-CBC. Optionally the key size (Bits) can be set to 128, 192 or 256. Note: 128 bits is perfectly safe and the fastest.
    A cryptographic-safe random initialization vector is inserted into the first 16 bytes of the result.
    Compatible with binary data and PHP openssl_encrypt.    

Decrypt.s(Input.s, Password.s, Bits = 128)
    Encodes string input using the AES algorithm with SHA1 key derived from Password. AES-128-CBC. Optionally the key size (Bits) can be set to 128, 192 or 256.. Note: 128 bits is perfectly safe and the fastest.
    Compatible with binary data and PHP openssl_decrypt.

Hash.s(String.s, Hash)
    Const HASH_CRC32 = 0, HASH_MD5 = 1, HASH_SHA1 = 2, HASH_SHA256 = 3, HASH_SHA512 = 4
    Returns hash Hash of String as UTF-8.

HashHmac.s(String.s, Key.s, Hash)
    Const HASH_CRC32 = 0, HASH_MD5 = 1, HASH_SHA1 = 2, HASH_SHA256 = 3, HASH_SHA512 = 4
    Generates HMAC hash of String (as UTF-8) using Key and algorithm Hash.

FileHash.s(FilePath.s, Hash)
    Const HASH_CRC32 = 0, HASH_MD5 = 1, HASH_SHA1 = 2, HASH_SHA256 = 3, HASH_SHA512 = 4
    Generates Hash from file FilePath.  

BinHash.s(Input.s, Hash)
    Const HASH_CRC32 = 0, HASH_MD5 = 1, HASH_SHA1 = 2, HASH_SHA256 = 3, HASH_SHA512 = 4
    Generates Hash from binary Input (as contained in BSTR string).

WIN32 API Access

DllFunction(Dll.s, Function.s, P1, P2, ...)
    Calls WIN32 API Function from library Dll with parameters P1, ... 
    Input (ByVal) and output (ByRef) values are supported for integer, long and string variables. Returns function result.

DllResourceString.s(Dll.s, ID)
    Returns Dll resource string with ID from library Dll.

Files/Folders

FileTouch(FilePath.s)
    Updates the file's modified date to the current date/time.
    An empty file is created if it does not exist yet.

FileCopy(Source.s, Destination.s)
    Copy file Source to Destination. Returns True for success or False for failure.

FileMove(OriginalPath.s, NewPath.s)
    Moves or renames OriginalPath to NewPath. 
    If NewPath only specifies file name, path from OriginalPath is used.

FileDelete(FilePath.s)
    Delete file FilePath. Returns True for success or False for failure.

FileRead.s(FilePath.s, Enc = ENC_UTF8)
    Const ENC_ASCII = 0, ENC_UTF8 = 1, ENC_UNICODE = 2, ENC_UTF8BOM = 3, ENC_DETECT = 4
    Returns string with contents of file FilePath read using text encoding Enc.

FileReadBin.s(FilePath.s)
    Returns binary string (data) with contents of file FilePath.

FileWrite(FilePath.s, Input.s, Enc = ENC_UTF8, Append = False)
    Const ENC_ASCII = 0, ENC_UTF8 = 1, ENC_UNICODE = 2, ENC_UTF8BOM = 3, ENC_DETECT = 4
    Write string Input to file FilePath using text encoding Enc.

FileWriteBin(FilePath.s, Input.s, Append = False)
    Writes binary string (data) to file FilePath.

FileArchive(Archive.s, Files|.s)
    Archives Files (|-delimited when entering multiple file paths) to file Archive (custom format).
    Useful for script support files.

FileUnarchive(Archive.s, Destination.s)
    Extracts all files from file Archive (custom format) to folder Destination.

FolderCopy(Source.s, Destination.s, Pattern.s = *.*)
    Copy folder Source to Destination optionally specifying pattern which source files must match.

FolderCreate(FolderPath.s)
    Create folder FolderPath. Creates root folders if necessary.

FolderMove(OriginalPath.s, NewPath.s)
    Moves or renames OriginalPath to NewPath. 
    If NewPath only specifies file name, path from OriginalPath is used.

FolderDelete(FolderPath.s)
    Delete complete folder FolderPath sub folders.

FolderEmpty(FolderPath.s)
    Deletes files and folders in folder FolderPath.

KnownFolderPath.s(Guid.s)
    Returns complete folder path for specified 'known folder'.
    See https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid for possible values.
    Const FOLDERID_Documents = "{FDD39AD0-238F-46AF-ADB4-6C85480369C7}", ...

Network

HttpData.a(Type, Url.s, Dat.s = , Headers.s = )
    Const HTTP_Get = 0, HTTP_Post = 1, HTTP_Put = 2, HTTP_Patch = 3, HTTP_Delete = 4
    HTTP Request of Type to Url. Optionally specifying Dat to send.
    Headers can be passed as |-delimited string Headers ("UserAgent = Mozilla/5.0")

HttpDownload(Url.s, FilePath.s, Async = False)
    Download file from Url to FilePath.
    If FilePath is a folder, the file name is derived from Url.
    If using Async, make sure client/script keeps running until download is finished.

MailSend(Recipients|.s, Subject.s, Body.s, Attachments|.s =, Async = False )
    Send mail to Recipients (|-delimited). Attachments (|-delmited) can contain file paths. 
    If using Async, make sure client/script keeps running. First call MailSetup.

MailSetup(SmtpServer.s, Login.s, Password.s, From.s, Port = 465, Ssl = True)
    Mail configuration to use for MailSend.
    Some mail providers need additional configuration like generating an application-specific password or adjusting security.

JavaScript
These functions make it possible to mix JavaScript/JScript with VBScript or MS Office VBA. You can even pass VBA objects to JavaScript functions. Please read Microsoft's JScript documentation to learn how to handle automation objects.

JsCode(Script.s)
    Starts up-to-date JavaScript runtime (MS Chakra 11.0) initialized with Script. 
    Use this to add predefined functions that you can call later with JsFunction.

JsFunction(Function.s, P1, P2, ...)
    Calls JavaScript Function with variable amount of arguments and returns result.

JsEval(Eval.s)
    Interpretes Eval as JavaScript and returns result.
    Example: Set json = WS.JsEval("JSON.parse('[ ""Test 1"", 2, 3 ]')")