Solved

Run .bat commands from shell

Posted on 2003-10-31
6
2,168 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:greetrufus
Comment Utility
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
Comment Utility
Never mind.  Your solution worked perfectly.
Thank you very much!!
0
 
LVL 28

Expert Comment

by:vinnyd79
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now