sttz / expresso

expresso is a command line interface to control the ExpressVPN app
MIT License
63 stars 11 forks source link

Cannot properly make use of 'status' in a cmd script #17

Open unalignedcoder opened 2 years ago

unalignedcoder commented 2 years ago

Expresso status works very well, but cannot really be used in a script.

Rather than returning a full sentence, it would be great if it could return a simple boolean value of 0 or 1.

Suppose the user needs first of all to find out whether the VPN is connected.

In a simple batch script in cmd language, it is a pain to break apart the sentences "VPN connected to server" or "VPN not connected", to figure out their actual value.

I understand the full sentence actually comes from ExpressVPN, not by Expresso.

Still, is there any way to get status to return a machine-readable value?

golaat commented 1 year ago

You can very easily use expresso in a PowerShell Script. I have created a PowerShell script which attempts a reconnection to ExpressVPN every single time Windows fires a Network Disconnected event.

Check-VPNConnection.ps1:

$output = & expresso.exe status
Write-host $output
if ($output -ieq "VPN not connected") { expresso connect 'UK - Wembley' }

I then configure a Windows Task as follows:

image image image

Arguments: -NonInteractive -File "C:\Tools\scripts\check-vpnconnection.ps1"