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
Printable View
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
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)
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
i have tried the new way but i get the message
' bad command or file name'
works ok for me!
and test.bat contains:Code:Option Explicit
Private Sub Command1_Click()
Shell "c:\test.bat", vbHide
End Sub
Code:netstat -e > c:\temp.txt
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
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?
many thanks sorted it.
you have been a great help
You could do it like this and it should work perfectly with a command button and a textbox..
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..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