|
-
Oct 12th, 2000, 09:32 AM
#1
Thread Starter
Member
can anyone tell me how to run a .bat file using the shell command
the command i am using is
a% = shell("temp.bat",2)
the bat file looks like this
netstat-e > c:\temp.txt
thankyou all for your help
-
Oct 12th, 2000, 09:39 AM
#2
Frenzied Member
->
you almost had it:
instead of:
a% = shell("temp.bat",2)
use
a=shell("c:\temp.bat",2)
you can even pass parameters to your batch file
a=shell("c:\temp.bat parameters",2)
-
Oct 12th, 2000, 09:41 AM
#3
Frenzied Member
what appears to wrong then?
you possibly need to include some path information on your file name (depending on your current path)
also, you need a space before the -e switch
-
Oct 12th, 2000, 09:45 AM
#4
Thread Starter
Member
i have tried the new way but i get the message
' bad command or file name'
-
Oct 12th, 2000, 10:00 AM
#5
Frenzied Member
works ok for me!
Code:
Option Explicit
Private Sub Command1_Click()
Shell "c:\test.bat", vbHide
End Sub
and test.bat contains:
Code:
netstat -e > c:\temp.txt
-
Oct 12th, 2000, 10:07 AM
#6
Thread Starter
Member
sorry to be a pain but i still get an error when running the program.
1st i get file not found
2nd if i run the .bat file on its own i get bad command or file name
thanks for all your help
-
Oct 12th, 2000, 10:16 AM
#7
Frenzied Member
have you put a space before the -e switch in the batch file yet?
is the batch file on the root?
My last bit of code I called the file test.bat instead of temp.bat - have you changed that to suit?
-
Oct 12th, 2000, 10:19 AM
#8
Thread Starter
Member
many thanks sorted it.
you have been a great help
-
Oct 12th, 2000, 10:28 AM
#9
Addicted Member
You could do it like this and it should work perfectly with a command button and a textbox..
Code:
Private Sub Command1_Click()
'Command1 and Text1 being the command button and the text box respectivly..
Open "C:\temp.bat" For Output As #1
Print #1, "@echo off"
Print #1, "netstat -e" & "Text1.text"
Close #1
shell "C:\temp.bat", vbMinimizedNoFocus
End Sub
With that code, it creates the batch file when the button is pressed. So what ever IP you put into the textbox it prints netstat -e IP HERE and then closes the batch file, then runs it. Hope that helps..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|