Trying to run cmd prompts to connect/disconnect NordVPN

I’m still very new to AHK but I’ve been reading around the documentation but can’t figure out how to get this thing to work. Here’s what I’m trying to do:

- CD into specific directory

- then send “Nordvpn -c” to connect vpn

- ideally do this without the CMD prompt window actually opening

All I’ve been able to get it to do is launch the CMD Prompt window, have not been able to get it to actually type anything once the window is open.

CD into specific directory

No need to do this. Provide the path you want. There is no “navigation” with the run function.

then send “Nordvpn -c” to connect vpn

Are you sure it’s not nordvpn.exe? Usually you run an executable. You might have extensions turned off so you might not be aware the exe extension is there (see windows folder options to turn on extensions)

Run("c:\some\path\nordvpn.exe -c")

ideally do this without the CMD prompt window actually opening

This is the Run syntax:

Run(Target [, WorkingDir, Options, &OutputVarPID])  

Target is the file you want to run.
Working dir is the path it exists in (meaning you can use the full path with target or have the target be the file and and put the path in WorkingDir.)

Run("c:\some\path\nordvpn.exe -c")

is the same as:

Run("nordvpn.exe -c", "c:\some\path\")

And there are only 3 options. Min, Max, and Hide. Use the one you want.
Note that min will minimize it while hide will actually make the entire window hidden. You might need another hotkey to unhide it.

Run("nordvpn.exe -c", "c:\some\path\", "Min")

So I ended up doing this

run, cmd.exe

sleep 1000

send, cd “C:\Program Files\NordVPN\” {enter}

sleep 1000

send, nordvpn --connect {enter}

But now I cant seem to figure out how to get it to hide the window. I’m wanting to have it run this but not have the cmd window open.

Other than directly typing in a terminal, I always use long options to easily know what each command line does:

Run "nordvpn --connect", A_ProgramFiles, "Hide"
Run "nordvpn --disconnect", A_ProgramFiles, "Hide"

I don’t think it’s an exe, I was trying to follow these commands

https://support.nordvpn.com/Connectivity/Windows/1350897482/Connect-to-NordVPN-app-on-Windows-using-the-Command-Prompt.htm

Tried throwing this in AHK but no luck

You can try it with and without. No harm in experimenting.
Worst case scenario, one way doesn’t work.
¯\_(ツ)_/¯

But the whole “cd” thing is if you’re navigating to it via command prompt.
I didn’t realize you wanted to launch it via cmd.
There’s actually an easy way to do that and you still use Run():

Run(A_ComSpec " /c C:\Program Files\NordVPN\nordvpn -c")

A_ComSpec is the same as typing C:\Windows\system32\cmd.exe.
The /c means “close when done”.

Well, you need the actual path as starting directory…

Run "nordvpn --connect", A_ProgramFiles "\NordVPN", "Hide"
Run "nordvpn --disconnect", A_ProgramFiles "\NordVPN", "Hide"

For some unknown reason, my brain kept that to himself.

Or use the full path:

Run A_ProgramFiles "\NordVPN\nordvpn --connect",, "Hide"
Run A_ProgramFiles "\NordVPN\nordvpn --disconnect",, "Hide"

Just make sure that is an actual executable file (given that it doesn’t have extension).

Oh man this worked thanks!

One last question, is this not the correct way to do a hotkey for it?

^!+C::Run A_ProgramFiles “\NordVPN\nordvpn --connect”, “Hide”

No, the c must be lowercase:

^!+c::Run A_ProgramFiles "\NordVPN\nordvpn --connect",, "Hide"

Check the text in the green box:

https://www.autohotkey.com/docs/v2/lib/Send.htm#Parameters

hmm still nothing. Do I need to compile the script or save them in a certain place for hotkeys to work?