Having trouble with a disconnect script

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

Zelg

Posts: 6
Joined: Tue Aug 13, 2013 4:15 am

Post by Zelg » Tue Aug 13, 2013 4:30 am
Hello. I just recently started using Viscosity and I'm having trouble getting it to run the disconnect script I have copied from the support page to shut down a program when my vpn connection disconnects. I'm not very technical when it comes to networking and scripting and I cannot figure out why I'm having this issue. I run viscosity as administrator. When I manually use the vbs script myself it closes the program just fine. I have a connect script that is just a msg box that says hello when I sign on and that works just fine. I've also tried using that same msg box script as the disconnect one and it works just as well. I just cant seem to get Viscosity to close a program when I disconnect (testing with manual disconnect. not sure if that makes a difference if its manual or unexpected).

Anyways, like I said i'm not very technical when it comes to this so if someone could help me out a bit I'd greatly appreciate it.

I'm on windows 7 and running Viscosity version 1.0.0 (1024) that was provided to me by my vpn provider.

Eric

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

Post by Eric » Tue Aug 13, 2013 2:15 pm
Hi Zelg,

Could you please post up a copy of your script and we will have a look to see if there's anything in Viscosity or the script going wrong.

Regards,

Eric
Eric Thorpe
Viscosity Developer

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

Zelg

Posts: 6
Joined: Tue Aug 13, 2013 4:15 am

Post by Zelg » Tue Aug 13, 2013 2:25 pm
Hi Eric, here is the script.

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
strProcessKill = "'utorrent.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
WSCript.Echo "Just killed process " & strProcessKill _
& " on " & strComputer
WScript.Quit
' End of WMI Example of a Kill Process

Eric

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

Post by Eric » Tue Aug 13, 2013 2:47 pm
Hi Zelg,

The script is working fine in our test environment on the version of Viscosity you are using. Are you explicitly running Viscosity with Right click -> Run as Adminitrator? Also try running Viscosity without Admin rights as uTorrent may be shielded from other user accounts when it is run.

Also make sure that the Disconnect script appears correctly in the Advanced section of the configuration that you are using. Make sure the script is saved as "kill.vbs" or similar as well, not as a text file.

Regards,

Eric
Eric Thorpe
Viscosity Developer

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

Zelg

Posts: 6
Joined: Tue Aug 13, 2013 4:15 am

Post by Zelg » Tue Aug 13, 2013 3:20 pm
Eric,

I have tried running Viscosity via right click -> Run as Administrator as well as checking the Run as Administrator box within the properties. I have also tried running Viscosity without doing those steps and they return the same results. In the security tab of properties its listed as me having full control. Is there another Admin rights section I may be missing?

Also the script appears correctly in the advanced section and the script is saved as a .vbs and not a text file. My Msgbox "Hello" script works as I connect but the kill script will only work if run manually by myself.

Zelg

Eric

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

Post by Eric » Tue Aug 13, 2013 3:38 pm
Hi Zelg,

I'm afraid I'm a bit stumped. As your Hello script is working and we can get it working here, it must be a permissions problem. Running Viscosity with Run As Administrator give the application full rights, there is nothing else you need to do to run with Admin rights (providing you are then clicking Yes to the UAC prompt or entering an Admin account if prompted for one).

As a test, try changing the strProcessKill to "'notepad.exe'", clear and reselect the script in Viscosity, then open up notepad, connect and disconnect. When you select the script, it is copied in with the Viscosity profile, did you edit the script at all after selecting it? As these changes would not have been replicated.

Regards,

Eric
Eric Thorpe
Viscosity Developer

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

Zelg

Posts: 6
Joined: Tue Aug 13, 2013 4:15 am

Post by Zelg » Tue Aug 13, 2013 4:12 pm
Eric,

I'm stumped as well. I tried as you said and changed the strProcessKill to "notepad.exe", cleared and reselected, closed and opened viscosity and it still doesnt work through Viscosity. I appear to have full control of the program and I certainly click Yes to the UAC prompt. I'm also the only user and my user account is the administrator so I'm not sure what else I can do. The only time I've edited the script is to switch between "notepad.exe" and "utorrent.exe" to see if it would at least close notepad and each time I did I made sure to save the script, clear the selection and reselect it within viscosity after restarting the program.

Zelg

Eric

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

Post by Eric » Tue Aug 13, 2013 4:59 pm
Hi Zelg,

One last thing to try, move the vbs script to your C drive, then open notepad. Type/paste in the following
Code: Select all
@echo off
start C:\yourscript.vbs
Save this as "script.bat" then use it as your Disconnect script.

Regards,

Eric
Eric Thorpe
Viscosity Developer

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

Zelg

Posts: 6
Joined: Tue Aug 13, 2013 4:15 am

Post by Zelg » Tue Aug 13, 2013 5:38 pm
Eric

That worked! Kind of. For whatever reason I was unable to save the vbs at C:\. It gave me error: 0x80070522 saying I didnt have the correct privileges. Not sure how that is but for now, whatever. I saved the .vbs kill script and the .bat to run it on the desktop and was able to successfully kill the program on disconnect.

I appreciate all of your help and as its pretty late here I can finally go to bed.

Thanks.

Zelg.

ggg777

Posts: 2
Joined: Wed Sep 04, 2013 8:09 am

Post by ggg777 » Wed Sep 04, 2013 8:22 am
Going through various sites I've come up with this script to disablewireless connection when VPN disconnects, and kill the program of choice... then reactivate the wireless connection.
Sometimes, Viscosity automatically then tries to re-connect afterwards, and sometimes it doesn't.

@echo off
netsh interface set interface "Wireless Network Connection" DISABLE
taskkill /f /IM "utorrent.exe"
timeout 30
netsh interface set interface "Wireless Network Connection" ENABLE
netsh interface set interface "Wireless Network Connection" CONNECT

I was also told to add this "remap-usr1 SIGTERM" to the OpenVPN commands.. which I did.

I assume I can then add script for "Connected" with a command to re-launch the program once the VPN connection is re-established.

So really all I am needing is to understand why Viscosity isn't trying to re-connect VPN every time, just sometimes.. seems random. The other thing to optimize would be a better way to script to check if process has been killed (instead of timeout 30) to be more specific.

Any suggestions?
12 posts Page 1 of 2