Results 1 to 9 of 9

Thread: shell and .bat help please!

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    37
    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

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    ->

    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)



  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    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
    Mark
    -------------------

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    37
    i have tried the new way but i get the message
    ' bad command or file name'

  5. #5
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    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
    Mark
    -------------------

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    37
    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

  7. #7
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    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?

    Mark
    -------------------

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    37
    many thanks sorted it.
    you have been a great help

  9. #9
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158
    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..
    Stephen Bazemore
    Email:[email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width