Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2199
  • Last Modified:

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?
0
greetrufus
Asked:
greetrufus
  • 4
  • 2
1 Solution
 
vinnyd79Commented:
Private Sub Command1_Click()
Shell Environ("Comspec") & " /c C:\plink\plink.exe userid@192.168.1.100", vbHide
End Sub
0
 
vinnyd79Commented:
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
0
 
vinnyd79Commented:
You could also try changing to the Directory before shelling.This example also uses vbNormalFocus in case you don't want to Hide the process as in the above examples.

Private Sub Command1_Click()
ChDrive "C:\"
ChDir "C:\plink"
Shell "plink.exe userid@192.168.1.100", vbNormalFocus
End Sub
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
greetrufusAuthor Commented:
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
0
 
greetrufusAuthor Commented:
Never mind.  Your solution worked perfectly.
Thank you very much!!
0
 
vinnyd79Commented:
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now