Script Problem

Got a problem with Viscosity or need help? Ask here!

Aybee

Posts: 8
Joined: Sun Apr 12, 2020 7:21 am

Post by Aybee » Sun Apr 12, 2020 7:23 am
Hello


have a problem with a script (killswitch)

When the VPN connection is ended, Viscosity executes a .bat with the content:

netsh interface set interface Ethernet disabled

It also works.

When Viscosity reconnects it should have a .bat with the content

netsh interface set interface Ethernet enabled

To run. The problem is that Viscosity doesn't wait for the script and runs the .bat immediately afterwards

netsh interface set interface Ethernet disabled

We have already tried to insert a sleep / pause in the .bat but Viscosity irgonizes that, it is not waiting for the execution. It takes 4-5 seconds before the network card is activated again, Viscosity cannot establish a connection and then executes the .bat to terminate the connection

Is there a solution for?

Sorry for my Bad English....

Eric

User avatar
Posts: 969
Joined: Sun Jan 03, 2010 3:27 am

Post by Eric » Tue Apr 14, 2020 2:20 pm
Hi Aybee,

We responded to your email already, however I will put that reply here as well:


I'm afraid we can't find a problem with the pre-connect script. In our testing Viscosity is waiting for the script to exit. Can you confirm running the script on it's own outside Viscosity has the desired effect?

> To run. The problem is that Viscosity doesn't wait for the script and runs the .bat immediately afterwards
>
> netsh interface set interface Ethernet disabled
>
I assume you have just copy pasted the wrong thing here, but if this is what your pre-connect script is running and the adapter is already disabled, it will indeed exit immediately.

Please note also that Viscosity copies the script in with the rest of the configuration items when you save the connection. If you are editing the original script, these changes will not be made to the script Viscosity has unless you clear and re-select the script in Advanced when editing the connection and Save again.

If you're still having issues after double checking your script is correct, please send us a copy of your script and we can take a look.

Regards,
Eric
Eric Thorpe
Viscosity Developer

Web: http://www.sparklabs.com
Support: http://www.sparklabs.com/support
Twitter: http://twitter.com/sparklabs

Aybee

Posts: 8
Joined: Sun Apr 12, 2020 7:21 am

Post by Aybee » Tue Apr 14, 2020 4:23 pm
Have received the email, we are happy to continue here.

The script works outside.

The problem is that Viscosity does not wait until the script is completely finished when connecting but already tries to connect to the server which is not because the network card is deactivated and has to be activated by the script / bat

The network adapter takes 5-6 seconds until it is activated again by the script, but Viscosity notices when connecting that it is not possible and then jumps to the script / asked to deactivate it.

We tried this 4-5 times on 2 Windows Pc.

Eric

User avatar
Posts: 969
Joined: Sun Jan 03, 2010 3:27 am

Post by Eric » Tue Apr 14, 2020 4:26 pm
Hi Aybee,

If you would like to confirm Viscosity is waiting, please try setting the following script as your Before Connect script:
Code: Select all
ping 127.0.0.1 -n 6 > nul
echo ViscosityNoConnect
You should see the following in your log, note the 5 second delay between the .NET Framework version and the disconnect:
Code: Select all
Apr 14 4:25:10 PM: Running on Windows 10 1909 (18363) 64 bit
Apr 14 4:25:10 PM: Running on .NET Framework Version 4.8.03752.528040
Apr 14 4:25:15 PM: Before Connect script terminated connection attempt.
Apr 14 4:25:15 PM: State changed to Disconnected
Regards,
Eric
Eric Thorpe
Viscosity Developer

Web: http://www.sparklabs.com
Support: http://www.sparklabs.com/support
Twitter: http://twitter.com/sparklabs

Aybee

Posts: 8
Joined: Sun Apr 12, 2020 7:21 am

Post by Aybee » Tue Apr 14, 2020 4:36 pm
Crazy that it works for you.

Just tried it again. When I disconnect it disables the network adapters.

Then when I connect, he opens CMD and I see the command
Code: Select all
netsh interface set interface Ethernet enabled
Code: Select all
Wait 5 seconds too.Press a key to skip
Viscosity connects between the command
Code: Select all
netsh interface set interface Ethernet enabled
to connect what does not work because the network card is not yet activated and then jumps to the script
Code: Select all
netsh interface set interface Ethernet disable
Edit:
I'll try it later with your command, I had seen too late

Eric

User avatar
Posts: 969
Joined: Sun Jan 03, 2010 3:27 am

Post by Eric » Tue Apr 14, 2020 4:42 pm
Hi Aybee,

These commands require Admin rights to execute and Viscosity does not run elevated. This is most likely why they appear to not be waiting and then your adapter appears to be disabled again, when instead what is happening is both commands are failing to run.

You have a couple of options. You can run Viscosity elevated, however this may come with some risks.

Your other options are to run a script elevated when connecting which will enable your adapter and then connect your connection - https://sparklabs.com/support/kb/articl ... g-windows/

And then you can use the OpenVPN scripting system to disable the adapter on disconnect - https://sparklabs.com/support/kb/articl ... ect-occurs

Regards,
Eric
Eric Thorpe
Viscosity Developer

Web: http://www.sparklabs.com
Support: http://www.sparklabs.com/support
Twitter: http://twitter.com/sparklabs

Aybee

Posts: 8
Joined: Sun Apr 12, 2020 7:21 am

Post by Aybee » Tue Apr 14, 2020 4:58 pm
The script is listed with admin rights via task planning.

The deactivation works wonderfully only the activation does not work and also only because Viscosity doesn't wait for me to connect until the script is completely finished

I will try out your version after work

Aybee

Posts: 8
Joined: Sun Apr 12, 2020 7:21 am

Post by Aybee » Wed Apr 15, 2020 1:41 am
It doesn't work.

Viscosity is already trying to connect while the script for activating the network card is running.

It would be correct:
  • Viscosity Starts the script after clicking Connect
    The script is executed with a "Wait 5 seconds" in time the network card is activated
    Script ends
    Viscosity tries to connect to the VPN
---
But it works differently
  • Click Connect at Viscosity
    Script starts
    Viscosity tries to establish a connection to the VPN
    Viscosity gets no connection (because the network card is not yet active) and executes script to deactivate the network card
    Script for activating the network card closes

Eric

User avatar
Posts: 969
Joined: Sun Jan 03, 2010 3:27 am

Post by Eric » Wed Apr 15, 2020 11:44 am
Hi Aybee,

Did you try the example ping script I posted earlier? As I have mentioned, I'm afraid the issue here is most likely with your script or lack of elevation. If your script is using a task host to elevate itself and then exit immediately, Viscosity will also think that the script has finished and exited.

Regards,
Eric
Eric Thorpe
Viscosity Developer

Web: http://www.sparklabs.com
Support: http://www.sparklabs.com/support
Twitter: http://twitter.com/sparklabs

Aybee

Posts: 8
Joined: Sun Apr 12, 2020 7:21 am

Post by Aybee » Thu Apr 16, 2020 4:10 am
You are right, the problem is that the script is executed with the task planning, I have now tried it again, with the script directly and the command

ping 127.0.0.1 -n 6> nul

it works.

Is there a way to set how often Viscosity tries to connect? If the first connection does not work (DSL separation at night) try the viscosity 2-3 times?
11 posts Page 1 of 2