So with remote work ever increasing, I’m trying to write a script to encourage our users to ensure they’re on the VPN without forcing them on it. Hard requirement is that it’s windowless minus the popup, so the solution is to wrap the PS script in VBS via mshta. Another set of requirements are the conditions which will trigger the script.
Process logic:
If hours are between 8AM and 4PM, M-F (days handled via schtasks, hours in script)
and, if user is logged on
and, if machine is not locked
Execute ping check, messagebox, and launch VPN client
Really prefer the script be fileless to follow KISS principle the best I can
It seems that in VB, the (Window.Close) command executes before PS finishes, and it kills the whole thing. It works if I remove the code to determine lock status, but as soon as I add it, the script dies
mshta vbscript:(CreateObject("WScript.Shell").Run("powershell -NoLogo -WindowStyle Hidden -NoProfile -command ""$locked=(quser 2>$null) -and (get-process logonui -ea 0);if(((get-date) -gt (get-date 06:00:00)) -and ((get-date) -lt (get-date 16:00:00)) -and ($locked -eq $false)){if(!(test-connection domainControllerFQDN -count 2 -Quiet)){Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('No Network connectivity detected. Please connect to the VPN','Network Connectivity Check');ii C:Program*CiscoCisco*vpnui.exe}}""",0))(Window.Close)
How can I put a pause in between the PS execution wrapped in WScript.Shell, and the Window.Close command? I’m assuming a pause would even be the fix to my ailment.
Edit:
Works, but throws windows:
mshta vbscript:(CreateObject("WScript.Shell").Run("powershell -command ""$locked=(quser 2>$null) -and (get-process logonui -ea 0);if(((get-date) -gt (get-date 06:00:00)) -and ((get-date) -lt (get-date 16:00:00)) -and ($locked -eq $false)){if(!(test-connection domainControllerFQDN -count 2 -Quiet)){Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('No network connectivity detected. Please connect to the VPN','Network Connectivity Check');ii C:*Cisco*vpnui.exe}}""",0))
Doesn’t work…PS doesn’t execute…nothing happens
mshta vbscript:(CreateObject("WScript.Shell").Run("powershell -command ""$locked=(quser 2>$null) -and (get-process logonui -ea 0);if(((get-date) -gt (get-date 06:00:00)) -and ((get-date) -lt (get-date 16:00:00)) -and ($locked -eq $false)){if(!(test-connection domainControllerFQDN -count 2 -Quiet)){Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('No network connectivity detected. Please connect to the VPN','Network Connectivity Check');ii C:*Cisco*vpnui.exe}}""",0,true))
13