dannyres Posted November 5, 2003 Posted November 5, 2003 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 Quote
hog Posted November 5, 2003 Posted November 5, 2003 Try using the String.Split method on the text that the user enters to get at the bits you want Quote My website
Leaders dynamic_sysop Posted November 5, 2003 Leaders Posted November 5, 2003 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) Quote
dannyres Posted November 5, 2003 Author Posted November 5, 2003 dynamic_sysop but the problem is i dont know what arguments the people might enter into the textbox. hog how would i go about that?? Dan Quote
Raven76 Posted November 5, 2003 Posted November 5, 2003 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. Quote
Administrators PlausiblyDamp Posted November 5, 2003 Administrators Posted November 5, 2003 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
dannyres Posted November 5, 2003 Author Posted November 5, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.