Click here to Skip to main content
13,346,397 members (64,007 online)
Rate this:
Please Sign up or sign in to vote.
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
Posted 27-Feb-13 13:46pm
Dale 20121.8K
Updated 1-Mar-13 16:33pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
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.
Dale 2012 1-Mar-13 18:01pm
Hello again Mike I am still running into the same problem and have updated my code in my question to show my changes. The file is still not found when I try to run a file scan, outputting the desired string to the process filetool.exe.... I am sure the process is found but for some reason it still returns a message along with part of my string "Couldn't find C:\$Recycle.Bin\S-1-5-21-1749952126-3686413466-825947452-1000\$"

I figure that if the original string being sent was like this....

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

then why would my returned value not read something like this?

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

Unless the process name is not being sent to the process window somehow?....
Can that happen?.... Is there anyother way that I can run a exe more easily to output its information back to my program?..

thank you very much in advance!!
Mike Meinz 1-Mar-13 19:14pm
Can you try a different directory? I think the problem may be that Windows does not allow you to access files in the Recycle Bin.

In your code, what is the actual data in Label6.Text?
In your code, what is the actual data in Disasm?
What is the actual complete contents of output?
Can you provide a URL to the documentation for FileTool.exe?

Using the Process Class is the way to do what you want. We just have to figure out what's going on with it.
Dale 2012 1-Mar-13 21:15pm
Ok thank you for your patients with this I will tell you exactly what everything is that I hope to achieve. I forgot to change the word Disasm to filetool so in short I have a minimal command line dissembler for x86 and x64 win32 files that I hope to use with my antivirus to further my detection capabilities.

Label6.text displays the current file being scanned like so C:\folder\folder\somefile.exe
label6.text is always changing to the next file to be scanned until the scan has finished (recursive file scan)

Disasm or Disasm.exe is the executable file that is in my bin folder of my program that I am trying to use. Its funny that I can open the cmd window and type in the command manually everything works fine inside the cmd window?...

Output is the process returned from the dos window to my textbox1.text so that I do not need both the dos window and the program window... I hope that is quite possible also.

I will once again revise the code I have and update it in my question to exactly what I have in my program in hopes to solve this thing once and for all.

thank you again for your help.
Mike Meinz 1-Mar-13 21:39pm
1. Is the Recycle Bin file, the first file that is passed to the process? Or are some files processed and the Recycle Bin file is where it fails?
2. I don't understand purpose of DISASM. You never mentioned before. What does it do?
3. What does FileTool.exe do? Is it something you developed or available via Internet download. Can you give me URL to web site so I can check documentation?
4. Strongly recommend that you add code to skip over Recycle Bin files and not attempt to process them.
5. For label6.txt, Disasm and output variables, it would be good to see some actual data that is in those variables rather than just a description. Set a breakpoint on Textbox1.text = output and then use Visual Studio Immediate window to get actual values stored in each of these variables.
Mike Meinz 1-Mar-13 21:55pm
See post from "Dzomlija" at $Recycle.Bin. You cannot access files in the Recycle Bin.
Dale 2012 2-Mar-13 0:34am
Ok I will await your response when your able to... also I thought about the recycle bin thing earlier but like i said its for all files in any dir.... nothing found so far
Mike Meinz 2-Mar-13 7:16am
To really help you, I need more details about Disasm. Can I download it somewhere? Is there documentation? If Disasm is your code, please post the section of Disasm code that gets the command line parameter and uses it to access the file.

All your posts of error messages show Recycle Bin files. You must eliminate Recycle Bin files!

I would like to see the actual values from output and label6.text for a non-Recycle Bin file.

Also, I am pretty sure that you should change the setting of arguments to the following
Dim Arguments As String = Label6.Text.ToString
Mike Meinz 2-Mar-13 9:20am
After a Google Search, I downloaded a program called DISASM.EXE from Softpedia Free Disasm.
I was able to get this program working. I have put my code in the Revised Answer of Solution 1.
1. Moved WaitForExit to after ReadToEnd() - I found this in the Visual Studio Help file
2. Did not put DISASM.EXE in the command line arguments
3. I put another EXE that I renamed to XXX.EXE into the same directory to use as the program file to be processed for testing.
Dale 2012 4-Mar-13 14:18pm
OK SUCCESSS!!! I have figured it out to work will any from a any directory by simply adding the path to my recursive loop and presto its all good now thank you so much for your help!!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 2 Mar 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100