0 votes

Running .BAT from .NET

What I want is the following ,I have the following .BAT

color 30
cls
@echo off
echo.
echo.
echo DIGITE LA IP DE LA IMPRESORA QUE DESEA CONFIGURAR Y PRESIONE "ENTER":
set /P IP=
echo DIGITE EL NOMBRE DE LA IMPRESORA Y PRESIONE "ENTER", EJEMPLO:IBMDE11BLM1

 set /P NOMBRE=

cscript %windir%\SysWOW64\Printing_Admin_Scripts\es-ES\prnport.vbs -a -r %IP% -h %IP% -o  raw -n 9100 -me
pause
rundll32 printui.dll,PrintUIEntry /if /b "%NOMBRE%" /f "C:\Windows\System32\DriverStore\FileRepository\lmud1p40.inf_amd64_9a2338ab5b59d9ef\lmud1p40.inf" /r %IP% /m "Lexmark Universal v2 XL" /u
rundll32 printui.dll,PrintUIEntry /y /n "%NOMBRE%"
rundll32 printui.dll PrintUIEntry /e /n "%NOMBRE%"
echo SE INSTALO CORRECTAMENTE "ENTER" 
pause
exit

What I want is in .NET by calling a button to invoke it and pass the ip and name parameters through the TextBox1.text and TextBox2.text.

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    'Shell("C:\Users\carvajal\Desktop\Autoinstalar Impresora V 0.3.bat").
    vbNormalFocus).
End Sub 

Because I can invoke the .BAT by shell but as I pass those parameters, someone can give me a clue, I have seen that it is by means of a %1 and %2 I do not see example of it to achieve it, or if it is possible from the same .net to create my own .BAT and execute the orders.

1voto

Jose A. Fernandez Points 1157

You have to use Process.Start and then read the output stream with standardoutput

You can help yourself with this article that I wrote in 2007 (although it is in ASP.NET 2.0 and VB).

Something like this

      Dim p As Diagnostics.Process = System.Diagnostics.Process.Start(startInfo)

      'Leemos la salida (objeto StreamReader)
      Dim sr As System.IO.StreamReader = p.StandardOutput
      Dim cadenaSalida As String = sr.ReadToEnd()
      sr.Close()

and you have in the OutputString what you need

I hope it will be of help or guidance.

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X