Running Dos Commands from VB.net

cheers dude.

could i add another argument in there to bring in the ip address from a text box???

i was thinking something like,

Code:
Private Sub RUN_PROCESS(ByVal fileName As String, ByVal arguments As String, ByVal arguments2 As String)


with,

Code:
Me.RUN_PROCESS("cmd", "/c net use \\", TextBoxcleanIP.Text + " /user:mine spottydog")
 
You can pass in as many arguments as you want. But it would be better to build your argument list first and just pass it in a 1 argument.

TrUz
 
i have used the following code,

dos.dos2("cmd", "/c copy c:\", Test.Text + " c:\temp\nice2.txt")

(i also moved the sub's to a moudal page for ease of use ;))

but it seems to display (below) when it should say "1 file(s) copied"

blap.jpg


these files listed are on my c:\ but there is a lot more there than that, so it's not like it's doing "dir" instead.

Most other commands that i've tested seem to be working ok and display just how i'd like them to, but "copy" is the most important command i'm going to use.

any ideas as I'm stumped!:confused:

edit; i've used "dos.dos1("cmd", "/c copy c:\test.txt c:\temp\nice2.txt") and that works, must be something to do with bringing in the file name from the textbox.
 
Last edited:
Can you copy and paste your dos2 sub routine for me? Must be something not right if it works without the text box.

TrUz
 
here it is;

Code:
Imports System.io
Module dos
    Public Sub dos1(ByVal fileName As String, ByVal arguments As String)
        Dim p As New Process()

        With p
            .StartInfo.Arguments = arguments
            .StartInfo.CreateNoWindow = True
            .StartInfo.FileName = fileName
            .StartInfo.RedirectStandardOutput = True
            .StartInfo.UseShellExecute = False
            .Start()

            Dim reader As StreamReader = .StandardOutput

            While (Not reader.EndOfStream)
                Formstatus.statuslist.Items.Add(String.Format("{0}", reader.ReadLine))
                Formstatus.statuslist.HorizontalScrollbar = True
                Formstatus.Show()
            End While

            .WaitForExit()
        End With
    End Sub

cheers dude ;)
 
umm,

dos.dos2("cmd", "/c copy c:\" + Test.Text + " c:\temp\nice2.txt")

has to be put in like,

dos.dos2("cmd", "/c copy c:\" +Test.Text + " c:\temp\nice2.txt") - (vb just changes it)

but that just make is hang.
 
with the "+test.text +" it throws an double exception error.

seems odd that it works when the file is written in but when pulled though from the text box, it fails. I did think that it had something to do with the spaces in the line but I've checked that and the syntax of the dos command should be right.

god i love this programming lark!!!
 
TrUz,

you where right,

dos.dos2("cmd", "/c copy c:\" + Test.Text + " c:\temp\nice2.txt")

does work i had;

dos.dos2("cmd", "/c copy c:\", +Test.Text + " c:\temp\nice2.txt") - and that was never gonna work.

a fresh set of eyes an' all.

thanks again for your time.
 
Back
Top Bottom