Link to home
Start Free TrialLog in
Avatar of greetrufus
greetrufus

asked on

Run .bat commands from shell

I have created a button (plinkButton) in a form.
I am using the shell command to call a batch file called plink.bat
Here is the command I am currently using:

 Shell("C:\Program Files\plink.bat", vbNormalFocus)

The batch file consisits of the following commands:

@cls
@echo off
echo Connecting...
@"C:\plink\plink.exe" userid@192.168.1.100

I would like to illiminate the .bat file all together and be able to run the above in my project without calling out to an external batch file.
How do I do that?
Avatar of vinnyd79
vinnyd79

Private Sub Command1_Click()
Shell Environ("Comspec") & " /c C:\plink\plink.exe userid@192.168.1.100", vbHide
End Sub
You could also try shell without calling the command interpretor:

Private Sub Command1_Click()
Shell "C:\plink\plink.exe userid@192.168.1.100", vbHide
End Sub
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of greetrufus

ASKER

Sorry, I should have included that fact that I will be adding switches in the batch.
Here is a better example of the batch file I am calling (note, I am using VS 7.0 if that matters):

@cls
@echo off
echo Connecting...
@"C:\plink\plink.exe" -v -C -P 26 -L 5900:192.168.1.101 userid@192.168.1.100
Never mind.  Your solution worked perfectly.
Thank you very much!!
This should work:

Private Sub Command1_Click()
Shell Environ("Comspec") & " /c C:\plink\plink.exe -v -C -P 26 -L 5900:192.168.1.101 userid@192.168.1.100", vbNormalFocus
End Sub