Jump to content

Poor scripting spawns cmd Windows


Go to solution Solved by Luke94,

Recommended Posts

First of all I'm pretty sure I've done this the worst way possible.  I need to launch "vpncli.exe connect 192.168.1.1" in a command prompt titled VPN.  Then I need to controlsend keystrokes to get through the sign in process.  The following code works, but it spawns an extra unneeded cmd window.   How do I accomplish this without spawning the additional cmd window?

$command = ('start cmd /k cmd & title VPN & "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe" connect 192.168.1.1')
    Run(@ComSpec & " /c " & $command, "", @SW_HIDE)
    Sleep(500)
    ControlSend("VPN", "", "", "1")
    ControlSend("VPN", "", "", "{enter}")
    ControlSend("VPN", "", "", "UserID")
    ControlSend("VPN", "", "", "{enter}")
    ControlSend("VPN", "", "", "Password")
    ControlSend("VPN", "", "", "{enter}")
    ControlSend("VPN", "", "", "y")
    ControlSend("VPN", "", "", "{enter}")

 

Link to comment
Share on other sites

The START command "Starts a separate window to run a specified program or command.".

This should do the trick?

$command = '"C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe" connect 192.168.1.1'

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...