Click here to Skip to main content
15,920,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the desired code for my needs except for the argument that i wish to pass to the process that I am trying to run from my application.

the process is a command line tool that needs a specific string like so:

1. Filetool.exe "C:\myfile.exe"

I need to write something like this in to try and pass the correct argument to the process so that it will find the file I wish to perform the work on.

Dim Arguments as string = "Filetool.exe" & "" & fi.fullname

The problem to this string is it outputs to the cmd line or the process like this which is the incorrect usage:


How can I fix this so that the string will be passed exactly as it is shown in my first example (1.)
It would help If I knew how to add (") with a directory, filename and (") at the end. also how to add spaces when passing arguments

Thank you in advance..

This is what I have so far but still not working fully...

Public Sub Dissassemble()
            Dim process As New Process()
            Dim Disasm As String = "Disasm.exe" 'this string is for opening Disasm.exe 
            Dim Arguments As String = Disasm & " " & Label6.Text.ToString 'this string is to give the command to the exe window to use Disasm.exe and the filepath,filename and extension like so.. Disasm.exe C:\folder\folder\somefile.exe
            process.StartInfo.UseShellExecute = False
            process.StartInfo.RedirectStandardOutput = True
            process.StartInfo.RedirectStandardError = True
            process.StartInfo.CreateNoWindow = True
            process.StartInfo.FileName = Disasm 'As string
            process.StartInfo.Arguments = Arguments 'As string
            process.WaitForExit() ' Wait until Disasm.exe exits
            Dim output As String = process.StandardOutput.ReadToEnd() 'Returns Dos contents to Textbox1.text
            TextBox1.Text = output
            Label13.Text = Arguments 'Not really important just a test label to see the arguments string
        End Sub
Updated 1-Mar-13 15:33pm

1 solution

Below is a working example of how to start a program, pass command line arguments and retrieve the output in VB .NET

Revised Answer - Posted 2 March 2013 9:25am EST:
Dim process As New Process
    ' The program to be started by the Process Class:
    Dim Disasm As String = "C:\Users\Mike\Downloads\DISASM\disasm.exe"
    ' The string parameter to be passed to the program:
    Dim Arguments As String = "C:\Users\Mike\Downloads\DISASM\xxx.exe"
    process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    process.StartInfo.CreateNoWindow = True
    Process.StartInfo.UseShellExecute = False
    Process.StartInfo.RedirectStandardOutput = True
    Process.StartInfo.RedirectStandardError = True
    process.StartInfo.FileName = Disasm
    ' The FullPathName of the file to be processed is passed as the argument:
    process.StartInfo.Arguments = Arguments
    Dim output As String = process.StandardOutput.ReadToEnd()
    process.WaitForExit() ' Wait until the program has ended
Catch ex As Exception
    MsgBox(String.Concat(ex.Message, vbNewLine, vbNewLine, _
            "Unable to Start: " & Disasm), _
            MsgBoxStyle.Critical, _
            "Starting " & Disasm)
End Try

Tested with Visual Basic .NET 2012
Share this answer
Dale 2012 28-Feb-13 12:54pm    
Thank you very much for this I am sure in most cases this would be enough to get things working and for the most part it does return a value back to my textbox1 but its not returning the correct information.

I should get an output of the file that I am trying to use with the filetool but instead im getting this

Couldn't find C:\$Recycle.Bin\S-1-5-21-1749952126-3686413466-825947452-1000\$

I have placed a label on the form just to monitor the string output of what should be given to the process and it looks fine:

Filetool "C:\$Recycle.Bin\S-1-5-21-1749952126-3686413466-825947452-1000\$"

I have used the code you have stated above..... Is there another way to enumerate files to pass each ones fullname as a string to the cmd line?.... thats my goal here

I will re-post what i have now maybe you can correct me where i have went wrong

thank you!!
Dale 2012 28-Feb-13 13:01pm    
I also am aware that the files may not be found in the recycle.bin but its the same for all files in all directories..
Dale 2012 28-Feb-13 13:07pm    
The file tool that i am using i have placed in my bin folder of the project.... when i call the process from my program does it open from this directory?.... It might be a issue with it not finding the process maybe?. idk
Mike Meinz 28-Feb-13 14:49pm    
You might want to put the fullpath to FileTool.exe similar to what I demonstrated in my original answer in Solution 1.
Mike Meinz 28-Feb-13 14:47pm    
You don't need to put quotes around the filename or include the name of the program in the arguments parameter.

I think you probably need to use Process.WaitForExit Method so you don't proceed until the program is completed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900