App Support.

We're here to help.

Controlling Viscosity with Scripting (Windows)

As of Viscosity Windows 1.4.5, Viscosity provides support to be able to control connections using scripting. Scripting enabled you to take actions depending on the state of one of several connections, get information about connections, and control connections external to Viscosity's GUI.

Batch scripting is controlled using the included binary ViscosityCC.exe, allowing for feedback to Command Line.

ViscosityCC Commands

ViscosityCC.exe can be found in your default installation directory, generally C:\Program Files\Viscosity\ViscosityCC.exe.

Connect A Connection By Name

ViscosityCC.exe connect "My Connection"

Disconnect A Connection By Name

ViscosityCC.exe disconnect "My Connection"

Display Name Of The First Connection

ViscosityCC.exe getname 1

Display State Of The First Connection

ViscosityCC.exe getstate 1

Display State Of Connection By Name

ViscosityCC.exe getstate "My Connection"

List All Connection Names and IDs

Returns a JSON parsable list. Viscosity 1.9+
ViscosityCC.exe listall
Powershell example:
'.\ViscosityCC.exe listall | ConvertFrom-Json'

Powershell (.ps1) Examples

Connect and Open A Webpage Once Connected

The following script can be run by saving it and running it with the below:

./script.ps1 "My Connection Name"

	[string] $ConnName
$count = 0;
$TestCon = "`"$ConnName`""
$ViscosityCC = "C:\Program Files\Viscosity\ViscosityCC.exe"
& $ViscosityCC connect $TestCon
$status = "Disconnected"
Do {
	Start-Sleep -Milliseconds 500
	$status = & $ViscosityCC getstate $TestCon
} Until ($status -eq "Connected")

Start-Process ""

Batch (.bat) Examples

Several example can be found below for Batch scripting.

Connect And Open Webpage Once Connected

:@echo off
REM Example Viscosity Batch script to connect the fourth connection, 
REM Wait until the connection has connected,
REM And then open a webpage

set ViscosityCCPath="C:\Program Files\Viscosity\ViscosityCC.exe"
set state=
set connname=
REM Get the 4th connections name
for /f "delims=" %%a in ('"%ViscosityCCPath% getname 4"') do @set connname=%%a
echo %connname%

REM Check the connection is not already started
for /f "delims=" %%a in ('"%ViscosityCCPath% getstate "%connname%""') do @set state=%%a
echo %state%
if NOT %state%==Disconnected goto :loop

REM Start the connection
%ViscosityCCPath% connect "%connname%"

REM Sleep 10 seconds to allow the connection to happen
PING -n 8 -w 60000 >NUL
set state=Connecting

PING -n 2 -w 60000 >NUL
for /f "delims=" %%a in ('"%ViscosityCCPath% getstate "%connname%""') do @set state=%%a
echo %state%
if NOT %state%==Connected goto :loop