Shell Icon Overlay (C#) - c#

I need a method to create Icon Overlay's for Folders and Files in Windows XP/Vista, using C# or C++? Any examples?
Thanks,
-Sean!

Do not do this! Please, please don't.
You will break a lot of applications. Shell extensions must not use the .net framework (or any other similar framework), ever.
Here's an explanation why you must not do this.
Write your extension in C/C++, but not C#.
Update:
Even though as of .NET4 it's possible to have multiple framework versions in one process, it is still not recommended and not supported by Microsoft!
See this post about why:
[...] These problems led us to officially recommend against—and not support—the development of in-process shell extensions using managed code.

Tigris' TortoiseSVN product heavily uses icon overlays provided by library shared by several Tortoise products, the overlays themselves are written in C++ rather than C#.
The documentation for the TortoiseOverlays project explains how they use it and the problems they have encountered (username: guest, empty password), and the GPL'ed sourcecode is in the Subversion repository (same username/password as above).
Snippit from documentation:
TortoiseOverlays registers itself with the explorer to handle the nine
states mentioned above, i.e. it registers nine overlay handlers. The
explorer process initializes the TortoiseOverlays handler, calling its
IShellIconOverlayIdentifier::GetOverlayInfo(). TortoiseOverlays looks
for the registered overlay handlers under
HKLM\Software\TortoiseOverlays\Statusname and calls their
GetOverlayInfo() method so they can initialize too (Note that any
change to the icon name, index, ... your handler does are overwritten
later and won't be used - it's TortoiseOverlays that handles the icons
now). After the initialization, TortoiseOverlays relays every call to
its IShellIconOverlayIdentifier::IsMemberOf() method to the other
handlers. The first handler that returns S_OK determines whether the
icon is shown or not.

Related

interact with external application in c#

I was playing around with Microsoft Spy++ and noticed that not only does it find the open processes, but can find the individual components running in each process. For example there is this application that allows you to open a window in which there is a textbox for an IP address and textbox for a port. Spy++ can detect these components. Knowing that Spy++ can detect them, is there anyway possible to find them in a separate c# application and go on to MODIFY their contents and otherwise interact with the program? (such as firing a click event on a button)
This is feasible. Try use PInvoke (InterOp) or AutomationElement, or AutomationPeer (for WPF applications) to automate all you wish to do.
Also you might wish to try Inspect and UISpy application as well.
Automation elements/peer is a non-intrusive mechanism to control UI using accessibility framework. One of the weaknesses in windows is its lack of defence against code injection. Put simply:
As a privileged user,
- You can Open and Modify a running Process image
- Make it load your OWN DLL
- Make it run your OWN thread (that potentially listens to commands from your process) and
- allows you to read any bits of memory you want.
Look at detours (http://research.microsoft.com/en-us/projects/detours/) for how to do it with Managed Processes.. Unfortunately, Microsoft removed the inject at runtime features.
Also look at http://msdn.microsoft.com/en-us/magazine/cc163617.aspx for doing things in the managed world (Apps like Snoop utilise that)

Extending Task Manager Windows 8

I would like to know if there is any way to extend the task manager in a language like C# preferably but i'm also ok with C++, or anything else that works.
I would like to add some new features like, search, kill all processes with the same name, and what ever else comes to mind, but i have no idea were to start.
Note: I don't want to replace it or rewrite it from scratch, just add some new features.
I also found this link Is it possible to add functionality to Vista/7 taskmgr.exe? but it's for VIsta/7 i'm just hoping something change in 8, considering that it was completely redesigned.
Thank you
If i am correct, what you want to know is if there is a way to extend TaskManager via a plugin based approach( like Office/Ie/Outlook plugins).
The answer is no.
I however have a different approach which may help you do what you want but would be a lot more work.
What i suggest is Com interop based injection and override.
using Spy++ you can see what are the window classes/properties of the TaskManager window. Then you would need to write a program which works minimized(system tray?!) and watches for some identifying window/class name to pop up in the messages system. Windows messages can be intercepted and hooked. http://www.codeproject.com/Articles/33459/Spying-Window-Messages-from-the-Inside may be of some help.
Once you get your window handle. you will probably need to find the tabs control group. and inject a new tab element. Post which you can put anything which you deem into the tab element.
This is speculative, and involves the assumption that all the new changes you want to add would end up in a new tab.
I hope this helps you in some way.
PS: The answer is not totally speculative though. For some internal use at my workplace, I had made a prototype which would do something similar to outlook and override some default functionality which wasn't exposed by the Add in framework per se. Beware that this would require lots of testing and was somewhat unreliable/unstable

Prevent C# Dll from being loaded for certain apps

Greetings all,
I have a shell toolbar extension written in C#. It's only meant to be used in Windows Explorer, so I want to prevent the DLL from being loaded in Internet Explorer. Windows provides tons of ways to load extensions in IE only, but seemingly no way to do Explorer only. I know there are various checks I could perform in different places after the DLL is loaded, but the ideal would be to prevent the DLL from loading at all.
Now, if it were written C++, I would call GetModuleFileName in DllMain, check if the executable was iexplore.exe, and return false on attach if so. But there is no DllMain in C#; Microsoft doesn't trust us to play nice with loader lock. Is there any other way I can selectively prevent a C# DLL from loading?
Don't do Shell Extension Handlers in .NET
http://blogs.msdn.com/b/junfeng/archive/2005/11/18/494572.aspx
Section 3: Registering our AppBar
http://www.codeproject.com/KB/shell/csdoesshell3.aspx?print=true
I had to send this one in a separate post as a new user is not allowed to send more than one link in 1 post.

Any high level library or framework to hook all events in one's app in C#?

I know there's hook in Win32 but I don't need to hook the whole system and it's low level.
What I want is something easy like Wordpress framework but for Winform which allows me to hook all events in my own application for example detecting all textbox leave or all forms closing.
Does this exist ? Is it possible technically or only Microsoft can do so in .NET Version X.X ?
Have a look at ManagedSpy. It's an application very similar to Spy++, but for managed applications. It appeared in an MSDN Magazine issue several years ago.
When you run ManagedSpy, you can attach it to a running .Net process. It will reflect on the assemblies and find all kinds of events (there's some filtering ability to only see certain events), then it attaches to them and outputs the sequence of them firing.
There is also source code for ManagedSpy, so you can see how they did things and use those ideas to build what you need.
There is no easy way to do this as I am aware. There are external tools that can help (such as Spy++) but I believe they operate at the Windows message level rather than the .NET event level.
If you really need to do this level of monitoring in your application, you'll need to sign up event handlers on each object you wish to monitor. You could consider writing code that walks the control tree for each Form and signs up their events, so you could run it at startup after the forms are created.

Integrating into Windows Explorer context menu

I want to write a small tool, that does the following:
When you right click on a file with a certain file-extension the Windows Explorer context menu shows an additional entry.
When you click this entry a certain EXE is launched with this file as one of its parameters.
I would like to use C#/.NET 2.0 for this. If it's not possible I could also do it with C++/Win32.
My questions are:
Is it possible with C# .NET 2.0?
What are the necessary functions for integrating into the Windows Explorer context menu?
How can I make this permanent? (I don't want to relaunch this tool after every boot)
What do I have to take special care of? (different OS, security permissions, etc.)
You will need to access the registry and add a key under root\\File\\shell or root\Folder\\shell, depending on which items you want the menu item visible on.
Try this article at CodeProject, it's quite useful.
Edit: There's another article here which may be of help.
It is, incidentally, not supported to use .NET for shell extensions, due to the current inability to host multiple runtime versions in the same process (.NET 4 will lift this restriction).
Consider the case where you have two shell extensions; one for .NET 3.5, one for .NET 1. Which runtime will get loaded into your process? Well, it's more or less random--it depends which shell extension gets loaded first. Sometimes it might be the 2.0 runtime, sometimes it might be the 1.1 runtime.
This is also an issue if a .NET program creates common file dialogs; your shell extension may or may not load, and may or may not run with the correct runtime version.
As such, if you go down the Shell extension route you should use native C++/COM/Win32.

Categories