Skip to content

Instantly share code, notes, and snippets.

@jnnsrctr
Last active February 16, 2023 16:06
Show Gist options
  • Save jnnsrctr/5fa42f7b976225641382d11b45a6fd03 to your computer and use it in GitHub Desktop.
Save jnnsrctr/5fa42f7b976225641382d11b45a6fd03 to your computer and use it in GitHub Desktop.
Start Chrome, but only if the VPN is connected.
@echo off
netsh interface show interface name="Ethernet 2" ^
|find "Connect state" ^
|find "Connected">nul ^
&& start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" ^
|| "C:\Program Files (x86)\Common Files\Pulse Secure\JamUI\Pulse.exe" -show
close
@jnnsrctr
Copy link
Author

jnnsrctr commented Feb 16, 2023

  1. Run in CMD: ipconfig /all | grep -iE "ethernet|adapter|description|media state" and find the interface that represents your VPN. If media state is not logged for one of the interfaces, the interface is normally connected.
    My output (truncated):
    Ethernet adapter Ethernet 2:
    Description . . . . . . . . . . . : Juniper Networks Virtual Adapter
    For my example, the interface name is Ethernet 2
  2. Enter your interface name in the code.
  3. Change code to your requirements. In my example, Chrome is started if the VPN is connected, and Pulse Secure, if not connected.
  4. If you want to add it to the taskbar: Add Chrome normally to the taskbar
  5. Right click on the Chrome icon
  6. Right click on "Google Chrome"
  7. Choose "Properties"
  8. Change target to cmd.exe /C "path-to-your-batchfile". This way, the Chrome icon is easily preserved, and reversing is easy, too.

Be aware that -show is a program-specific command for Pulse Secure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment