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.
Related
Hello all i have a rather specific Question and please consider my apologies if this is not a standard stack-overflow question ,
i need to know is it possible to get all control names of another exe e.g.
i have a c# application and i want to get all control names of another standalone application running on my computer say b.exe so if b.exe have a textbox and a button in it i want to have names of textbox and button in my c# exe and also i want to have a listener for click events of b.exe
till now whatever i have researched is nothing special actually i dont want full code snaps i just want a guideline can i do it thorugh pinvoke? or winapi? please explain what is pinvoke and winapi and is it possible through application hooking ? once again i need a guideline a way to follow so please help me out regarding this, i know i can get active windows name through pinvoke or winapi but my requirements are little high
1 . Access to control names:
Unfortunately I do not .NET (C#) but under Visual C++ this would be impossible.
The reason is: The controls do not have names in the executable any longer but the names are simply converted to numbers.
Example "myTextControl" would be 1234 in the executable. The information about the (original) name of the control gets completely lost while compiling.
2 . Accessing controls in other executables:
I think under .NET (C#) it is not as easy as under native programming languages (directly accessing the Windows API) but it is possible to access controls of other executables as long as you know the number (e.g. 1234).
Therefore you'll have to find out the window handle of the dialog window containing the control and then you can send messages to the control. Unfortunately many messages containing pointers will require some very tricky hacks. Messages without pointer work well.
3 . Creating a listener for a control in other executables:
Creating a listener (e.g. a click listener) on a control in another EXE is possible however very tricky: This would require writing a native (this means: not .NET / C#) DLL file which is then combined with the Windows API function "SetWindowsHookEx".
I do not think that a .NET API (required for C#) already exists that will do this because there are only few use cases for this.
I have a third party .Net application with literally hundreds of dlls and XML files. I need to add a single service to the application, and in the process need to find out which dlls are loaded, and which methods are invoked when a single button in the UI is pressed. The application and most of the dlls are in .Net. Any ideas on how to go about doing this? Is there any free software that I can use?
Have a look on NDepend. Its very helpfull to discover dependencies (and much more).
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.
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.
I have a program that is using the C# WebBrowser control and it needs to detect which page is loaded to determine what to do next. The program works fine on most of the employee's computers at the office, but it does not work on some.
I have determined the problem is that the documentCompleted event is not firing on those computers it does not work on.
This program does use threads to process data, and the webbrowser.navigate call is made through a delegate. But I have also changed the code to not use delegates for the navigate action with no change in the result.
I also made a separate program that has just a basic WebBrowser and debug textfield, and the DocumentCompleted event does fire when using that program.
NOTE: The computers that it is not firing on are older PCs with single core/thread processors.
I am out of ideas on this one, any help would be appreciated.
As explained by CodeBlock, this seems to be related by the installation state of Microsoft.mshtml.dll
We've got customers where the Microsoft.mshtml.dll is not present in GAC (nor in computer), and then the WebBrowser component never fires any event.
By using Reflector in the WebBrowser class, the DocumentComplete event is raised by a subclass named WebBrowserEvent, which implement a private interface DWebBrowserEvents2.
This interface is a ComImport of {34A715A0-6587-11D0-924A-0020AFC7AC4D}, which, I suppose, is related to Microsoft.mshtml.dll.
So our solution was to install the Office 2003 Redistributable Primary Interop Assemblies, which install the DLL on Program Files then register it on the GAC.
Note : Don't pay attention to the .NET Framework 1.1 required or office required, it just copies some dlls.
Note 2 : The 2007 package seems to include the same dll.
#Pavel L:
The problem here is you used a web browser control from mshtml.dll but .NET framework does not include this file. The solution for this is simply copy mshtml.dll to your app dir or set 'Copy local' property of Microsoft.mshtml to True.
Sorry for my bad english :D
If it is a threading issue, make sure you are calling Application.DoEvents(). I've had problems with WebBrowser not working right when I failed to do that.
Well I'd like to share even more simple solution rather than installing a package.
As it was stated before the DocumentComplete event somehow depends on Microsoft.mshtml.dll file. You can find it on a machine with Visual Studio installed. So it needs to be copied and installed to the target machine. Here's the description of the process:
Place the Microsoft.mshtml.dll file into the "%ProgramFiles%\Microsoft.NET\Primary Interop Assemblies" folder.
Then drag and drop it into the "%SystemRoot%\Assembly" folder.
Register the library with RegAsm.exe utility (which is located in the appropriate subfolder of "%windir%\Microsoft.NET\Framework").
P.S. May be it may be done in a better way but this solution works and I hope it'll be useful for you.
In order for the documentCompleted-Event to fire,
the visible property of the web browser needs to be set to true.
It can also be on visible, if you have multiple screens.
If you have > 1 screen, switch off all but the main screen, this should resolve the problem.
Alternatively, move the window to the 2nd screen.
Make sure webbrowser.Visible=true; this works for me, I had similar problems previously.