Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, im making a program that when a user enters a path in a textbox and presses enter it will start that process. So far it works fine except it doesnt accept arguments.

 

Because the Process.Start method only accepts a path and arguments as seperate strings i need to work out how to seperate them.

 

So for example if the user enters "C:\Program Files\myapp\test.exe /r /t" then i want to be able to get "C:\Program Files\myapp\test.exe" and "/r /t" as seperate strings... Does anyone have any idea of how to implement this?

 

 

 

Dan

  • Leaders
Posted

try using Substring, eg:

       Dim path As String = "C:\Program Files\myapp\test.exe /r /t"
       Dim exe As String = path.Substring(0, path.Length - 6)
       Dim args As String = path.Substring(path.Length - 6, 6)
       Console.WriteLine("the exe's path is: " & exe)
       Console.WriteLine("the argument to pass is: " & args)

Posted

I think he needs it to be more dynamic than that. For example they might only type 1 argument and not both.

 

You could use InStr to find the location of the "." then add 3 to the location to include the file extention. Everything else would be the aruguments.

 

However, If a very diverse set of commands is going to be used in the textbox I could see where some problems may arrise (such as file names with more than one dot). You might be better off with 2 textboxes. The first for the path to the executable (You could even use an openfiledialog to let the user browse to the file and populate the textbox). The second to any optional arguments that the user would like to add.

  • Administrators
Posted

relying on a '.' followed by 3 characters may not be safe if they could also type non-executables .js .pl etc. for the executable.

The two textboes suggestion is probably the easiest although you may want to mimic earlier versions of windows and if the path can contain spaces require the users to enclose it in quotes

i.e.

 

"C:\Program Files\myapp\test.exe" /r /t"

 

that way you can look for the first and second double quotes and everything between them is the executable. Everything else is arguments to the executable.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

ok well the two textbox thing isnt really an option in this case...

 

As for the quotes im thinking thats what im going to have todo, Unless there is some other way.

 

Also another option but not very good would to somehow bring up the run dialog, use sendmessage to enter the text and hit enter..

 

 

Dan

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...