I want to set in the right-click menu of windows, a shortcut to my app.
The goal is to select a document (image, pdf etc.) -> right-click -> 'Send with my app' ( and optionnaly open a certain class with arguments, like the files path)
I've saw some many possibilities to do that ...
but I would like to know the good way to do that with a c# wpf app.
The goal is to send an installation program to many clients to allow them to use the app, and set the entry on the context menu
In order to show custom options in Windows context menu, you will need to update the registry. Here is how to do it
http://www.howtogeek.com/107965/how-to-add-any-application-shortcut-to-windows-explorers-context-menu/
Once done, in your wpf application, you can get the command line arguments passed using :
string[] args = Environment.GetCommandLineArgs();
from these args, you can extract any argument passed (file location etc)
Related
I'm currently writing an application where I need to modify the context menu of windows explorer so that I can call a method within the application to be used on all files/folders that are seen in windows explorer.
As there are already quite a few posts on stackoverflow (and also tutorials) on how to add the context menu for specific file types I know already that that is done usually by assigning the application to the right parts of the registry entry for those file types.
As I don't want to limit myself to only specific filetypes my question is: IS there any way
to assign this new context menu item to ALL filetypes (aside from going through each registry entry
beginning with . and assigning the application to them there)?
Yes, the * class:
Create the key:
HKEY_CLASSES_ROOT\*\shell\Open with MyThing
Create the sub key:
HKEY_CLASSES_ROOT\*\shell\Open with MyThing\command
Set the default value to your command line:
C:\foo\myThing.exe "%1"
(You can add fixed values here also: C:\foo\myThing.exe "%1" /ranfromshell)
To set an optional icon create the string value Icon in:
HKEY_CLASSES_ROOT\*\shell\Open with MyThing
You can put the path to an icon, dll or exe here - Windows will extract the appropriate icon & display it.
Example
For:
.Reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Open with MyThing]
"Icon"="C:\\foo\\myThing.exe"
[HKEY_CLASSES_ROOT\*\shell\Open with MyThing\command]
#="C:\\foo\\myThing.exe \"%1\""
I make context menu item for images(for example), it should open my console application, using target file as string argument. When I use it for many files it opens many application copies, and for each one it has one string argument, but I want to send array of string to one application.
As I researched, it is impossible on registry level, so my application should search for it's copies and get their string arguments. How to realize it in c# console application?
I have a C# win form application and I build a "setup" for it by visual studio 2010
my application needs some parameters like username , pass, ip and ...
i want to get these values from user before setup complete and save it to a file to use by my application. but how?
This answer presumes that you are using the Setup Project in Visual Studio. If you aren't edit your question and we can take another look.
To gather user input you need to introduce a new dialog to the installer.
The following steps will bring you to the part of the installer project that will allow you to add new dialogs:
In the Solution Explorer menu select the option "User Interface Editor"
In the newly opened screen right click on of the options (Install for example) and select "Add Dialog"
This displays a range of pre-built user dialogs. You will probably want one of the text box dialogs.
If you want something different you can also create a custom setup dialog. There is a nice code project post on doing this here.
Once you have this information you need to actually access it and use it during installation.
For this you need to add an installer class to your target project (the project you want to install).
In that installer class you can reference the text boxes you created using code like this:
public override void Install(System.Collections.IDictionary stateSaver)
{
string myPassedInValue=this.Context.Parameters["TEST"];
//Do what you want with that value - such as storing it as you wanted.
}
This answer is a little bit from 10000 feet - if I went into all the detail I'd end up writing a full article. If you have any sticking points, please ask. Also - have a look at this excellent article on the subject, it should get you most if not all of the way.
In VS solution explorer
Right click yoursetup >> View >> USerInterface
Right Click Start >> Add Dialog >> Select TextBox
Now made a Custom Class And add Install class file
Sample code
In Install.cs
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
string targetDirectory = Context.Parameters["Username"];
string servername = Context.Parameters["password"];
}
The problem is easy: I've a lot of desktop shortcuts which points to a lot of file, BUT I also have a lot of shortcuts which points to directories pointed by those shortcuts. I want to remove this redundance by simply adding another rightclick menu options for all shortcuts (.lnk files) that allows you to open explorer.exe to the directory containing the file pointed.
While I discovered how to retrive the target of a shortcut and it's working, I found a suggestion on how adding a menu item to rightclick context menu, but it's not working (I put a key under HKCR*\shellext\ContextMenuHandlers called Test and set the base value to "cmd.exe"
But it doesn't work, obviusly
any suggestion?
Update 1:
How to add an icon to that menu item?What size should the icon file have? 16x16 or 32x32?
thanks in advance
Go into HKCR\lnkfile
Create a new key called "shell", and below that create another key called whatever you want the display text to be for your context menu handler, I called mine "COMMAND".
Next, create yet another key below that called specifically "command" and make the (Default) value be "cmd.exe", which will be the path to your custom command. Remember to wrap it in quotes if you're going to be pointing to an exe that has spaces.
So for this example, the final key ends up being:
HKCR\lnkfile\shell\COMMAND\command\
Add the (Default) value mentioned above and your test will be working fine.
Additionally, you can use "%1" to specify the full path to the .lnk file being accessed by the context menu, again remember to wrap it in quotes since you never know if it'll be a file that has spaces in it's full path.
How to open files from explorer into different tabs. I can associate an open with menu with the file type, now when I already have the program working, how to open the new file into another tab, instead of new program.
How to find the already running process exactly, not with the name and send the filename to it.
Let me make myself clear: I want my app to be single instance, so that when user select 10 text files and press enter key, my application will open all the 10 text files into 10 tabs, instead of creating 10 processes. How to do that? How to communicate between various instances of the same process.
EDIT SOLVED: Implemented the functionality using WM_COPYDATA in C# and the SingleApplication class from codeproject.
I am not quite sure what you mean in this question. Are you trying to open Windows Explorer windows into one window with tabs? If that is the case, then I recommend you look into QT TabBar, which extends Windows Explorer to allow for such behavior.
Or perhaps you are trying to have a link open to a new tab in a web browser. If that is the case, this behavior is defined by the web browser itself. For Internet Explorer 7, you can set this behavior under Tools > Internet Options.
In the General tab, click the Settings button next to the "Tabs" section. You will want to set the "Open links from other programs in:" option to open a new tab.
Keep in mind that this behavior is defined by each user, and you can't ever make any guarantees that they will have the same browser settings as you do.
After reading your comments, I think I understand a bit better. It sounds like you want your application to only allow one instance at a time. Since you tagged this post C#, I will assume that is what you are writing your program in.
Codeproject.com has a great tutorial on how to make your program only allow a single instance.
Here is a snippet of code from their site:
static void Main()
{
if(SingleInstance.SingleApplication.Run() == false)
{
return;
}
//Write your program logic here
}
You would want to write code just before the return statement to have the existing instance open the file in a new tab.
If you are able to provide detailed information about what your program is doing, we might be able to help you with some of the specifics.