Click here to Skip to main content
15,887,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, i want to know how my app has started, for example, if it started by a command as "program.exe /p" and indicate in the code what should do the app in diverse cases (for example when it started by /open command, /edit,...).

I need a solution
Thanks in advance
Regards
Posted
Updated 2-May-11 4:16am
v5
Comments
Nagy Vilmos 2-May-11 4:22am    
What have you tried?

Are you looking for command line arguments[^]? It seems so to me from your comment to Dave.
 
Share this answer
 
There's no way to tell how your app was launched. There is no pointer to anything that says how are under what circumstances your app was launched.
 
Share this answer
 
Comments
Ángel Manuel García Carmona 2-May-11 10:25am    
Hi. If i set in the registry -for example-, to the extension shell, a verb (f.e: play) and another key with a command (f.e: "app.exe /play), but indicate what should do the app in that case. This is what i want to do.
Dave Kreskowiak 2-May-11 10:34am    
That made absolutely no sense at all. It doesn't matter how the app was launched. Unless you put specific command line arguments in the registry, like you described, that your app is looking for, it has no way of knowing how it was launched. You'd have to include some switch, that you define, into the command line of the verb that launches your app.
Ángel Manuel García Carmona 2-May-11 10:35am    
I really am explaining that i want assign to those arguments/verbs (play,, open,...) some code.
Dave Kreskowiak 2-May-11 11:06am    
That still doesn't make much sense, but I think you're saying that you want to tell the app what to do when launched based on command line arguments. Your code just has to look for the command line arguments and act appropriately. http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs.aspx
Ángel Manuel García Carmona 2-May-11 13:29pm    
Hello, i have assigned an extension to my app and a shell verb, but web i click in a verb (shortcut menu), i see an error that tells "{File} is not a Win32 valid app".

Also, in the link that you has given me, isn't explained how to tell the app what to do when launched based on command line arguments.

Regards
You're kidding me, right? All you do is call the appropriate method in your code if you find an instance of the switch in the command line arguments. How hard is it to check for the existance of a string in a collection of them?
public void Main()
{
	List<string> argsCollection = new List<string>();

	argsCollection.AddRange(Environment.GetCommandLineArgs());

	if (argsCollection.Contains("/T")) {
		HandleTSwitch();
	}
}

private void HandleTSwitch()
{
}
</string></string>
 
Share this answer
 
Comments
Ángel Manuel García Carmona 3-May-11 16:28pm    
Hi Dave, thanks to your example, i could understand better how can i do what i want to do (i wasn't kidding you). "%1" reffers to the file and its path, but i want when i open a file by the argument, the app display that (f.e in a image control) but the problem is that i can't find a property to assign the opened file and its path. %1 reffers to file path (for example: C:\plazaaltaba.jpeg"; if i open this file, the command will be "C:\application -argument %1)
Dave Kreskowiak 3-May-11 18:12pm    
You're still not making very much sense, so I'll take another guess at what you want. If you want to show the path to the file in the title bar of your form, you just have to set the Text property of the form to the path you got from the arguments.

If you're still trying to get the filepath from the command line arguments, then look at the eample I just posted. The argsCollection will contain the full path supplied on the command line. You just don't have to check for an argument switch. You just get the string from the collection, see if the file exists, and do whatever you want with that path.
Ángel Manuel García Carmona 4-May-11 9:29am    
Hi! I know how to do this. I've written a foreach and some methods to get the file path string.
Thanks for your help.

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