Answered by:
How to run a .BAT file to open a cmd window

Question
-
I am having trouble trying to get a .BAT file to run in a windows form application, the result im trying to achieve is when the user clicks the button it runs the .bat file which is used to open a cmd window with various options used for ipconfig (renew, release flushdns) the .BAT works fine but i am new to vb and cant figure out how to get it to run in the form if anyone can help me out i would be very grateful here is the .BAT i am trying to execute :
@echo off
:options
cls
echo =====================
echo MENU OPTIONS:
echo =====================
echo 1 ipconfig
echo 2 ipconfig all
echo 3 release
echo 4 renew
echo 5 flushdns
echo 6 ping
echo =====================
echo 7 to Exit
echo =====================
set /p input="Please choose what you would like to do: "
if "%input%"=="1" goto:ipconfig
if "%input%"=="2" goto:ipconfigall
if "%input%"=="3" goto:release
if "%input%"=="4" goto:renew
if "%input%"=="5" goto:flushdns
if "%input%"=="6" goto:ping
if "%input%"=="7" goto:exit
echo Please choose what option you would like to execute.
pause
goto:options
:ipconfig
ipconfig.exe
pause
goto:options
Saturday, February 2, 2013 9:55 PM
Answers
-
Process.Start("Your.bat") will execute your bat file, the same as double-clicking on it in Explorer.
- Proposed as answer by Frank L. Smith Saturday, February 2, 2013 10:38 PM
- Marked as answer by Youen Zen Tuesday, February 12, 2013 9:33 AM
Saturday, February 2, 2013 10:20 PM -
This example is for writing a file into the My Documents folder, but it also applies to reading and executing a file that you have stored in that folder. The special folders enumeration is used to create the file path and name. This eliminates the need to know the actual folder name.
- Proposed as answer by Renee Culver Sunday, February 3, 2013 1:06 AM
- Marked as answer by Youen Zen Tuesday, February 12, 2013 9:33 AM
Sunday, February 3, 2013 1:02 AM
All replies
-
Process.Start("Your.bat") will execute your bat file, the same as double-clicking on it in Explorer.
- Proposed as answer by Frank L. Smith Saturday, February 2, 2013 10:38 PM
- Marked as answer by Youen Zen Tuesday, February 12, 2013 9:33 AM
Saturday, February 2, 2013 10:20 PM -
i keep getting the "Win32Exception was unhandled the system cannot find the file specified"Sunday, February 3, 2013 12:01 AM
-
"i keep getting the "Win32Exception was unhandled the system cannot find the file specified"
That means the your file name is incorrect. Find the file in Explorer. Copy the directory from the address bar and paste it into the statement and add a backslash. Then copy the filename with the extension and paste it at the cursor (after the backslash).
Sunday, February 3, 2013 12:12 AM -
Thank you very much i got it to work but i had one more question if i wanted to put this program on another computer how would i get it to run then if the bat file is directed to my documents of the computer i made it on?Sunday, February 3, 2013 12:28 AM
-
This example is for writing a file into the My Documents folder, but it also applies to reading and executing a file that you have stored in that folder. The special folders enumeration is used to create the file path and name. This eliminates the need to know the actual folder name.
- Proposed as answer by Renee Culver Sunday, February 3, 2013 1:06 AM
- Marked as answer by Youen Zen Tuesday, February 12, 2013 9:33 AM
Sunday, February 3, 2013 1:02 AM