Solved

Run .bat commands from shell

Posted on 2003-10-31
6
2,178 Views
Last Modified: 2008-02-01
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
Comment
Question by:greetrufus
  • 4
  • 2
6 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9661940
Private Sub Command1_Click()
Shell Environ("Comspec") & " /c C:\plink\plink.exe userid@192.168.1.100", vbHide
End Sub
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9661942
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
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 500 total points
ID: 9661948
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
Technology Partners: 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!

 

Author Comment

by:greetrufus
ID: 9661956
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
 

Author Comment

by:greetrufus
ID: 9661968
Never mind.  Your solution worked perfectly.
Thank you very much!!
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9661972
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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question