Programmatically Configuring Cisco VPNUI Shortcut to Auto-Connect Specific Host via CLI Parameters


4 views

Unlike most modern VPN clients, Cisco VPNUI.exe lacks a connection history feature, forcing users to manually re-enter host details for each session. This becomes particularly cumbersome for sysadmins and developers who frequently switch between multiple VPN endpoints.

While undocumented, VPNUI.exe actually supports these parameters:


"C:\Program Files (x86)\Cisco\Cisco VPN Client\vpnui.exe" -h vpn.example.com -u username -p password

Key parameters:

  • -h: VPN server hostname/IP
  • -u: Authentication username
  • -p: Password (not recommended for security)
  • -c: Connection profile name

For production environments, consider these approaches:

@echo off
SET VPN_PATH="C:\Program Files (x86)\Cisco\Cisco VPN Client\vpnui.exe"
START %VPN_PATH% -h vpn1.example.com -c "Production_VPN"

For better security than plaintext passwords:

  1. Use Windows Credential Manager to store credentials
  2. Create an encrypted PowerShell script:
$securePass = ConvertTo-SecureString "YourPassword" -AsPlainText -Force
Start-Process "vpnui.exe" -ArgumentList "-h vpn.example.com -u admin -p $securePass"

For developers needing programmatic control:

// C# wrapper example
ProcessStartInfo psi = new ProcessStartInfo
{
    FileName = @"C:\Program Files\Cisco\VPNUI.exe",
    Arguments = $"-h {hostname} -u {username}",
    WindowStyle = ProcessWindowStyle.Minimized
};
Process.Start(psi);

The Cisco VPNUI client (vpnui.exe) indeed lacks two critical features most network engineers expect: command-line parameter support and connection history. This becomes particularly frustrating when you need to quickly connect to specific VPN endpoints during troubleshooting or daily operations.

After examining the client's behavior, I discovered it stores connection profiles in the Windows registry under:

HKEY_CURRENT_USER\Software\Cisco Systems\VPN Client\Profiles

Each profile appears as a separate .pcf file containing the connection parameters, including the target host.

While vpnui.exe doesn't accept direct command-line arguments, we can automate the process using these methods:

Method 1: Registry-Based Profile Switching

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Cisco Systems\VPN Client\Profiles\WorkVPN]
"Host"="vpn.company.com"
"AuthType=1"
"Username"="your_username"

Method 2: Batch Script Automation

Create a batch file (connect_vpn.bat):

@echo off
:: Set the target VPN profile
set VPN_PROFILE=Production

:: Launch VPNUI and auto-connect
start "" "C:\Program Files (x86)\Cisco Systems\VPN Client\vpnui.exe"
timeout /t 3 >nul

:: Send keys to navigate UI (requires NirCmd or similar)
nircmd.exe sendkeypress ralt+down
nircmd.exe sendkeypress down
nircmd.exe sendkeypress down
nircmd.exe sendkeypress enter

The vpncli.exe (command-line version) offers more control:

:: Connect to specific profile
vpncli.exe connect "ProductionVPN" user "admin" pwd "securepass"

:: Pre-configured connection
vpncli.exe -s < config.txt

Where config.txt contains:

connect "ProductionVPN"
username "admin"
password "securepass"

For more robust automation, use this PowerShell script:

$vpnPath = "C:\Program Files (x86)\Cisco Systems\VPN Client\vpncli.exe"
$profileName = "NY-Office"
$creds = Get-Credential

Start-Process $vpnPath -ArgumentList "connect "$profileName" user "$($creds.UserName)" pwd "$($creds.GetNetworkCredential().Password)"" -NoNewWindow -Wait

Create separate shortcuts for different environments by combining these techniques:

:: Developer VPN shortcut
vpncli.exe connect "Dev-Env" user "devuser" pwd "d3vP@ss"

:: Production VPN shortcut
vpncli.exe connect "Prod-Env" user "produser" pwd "Pr0d!2023"