|
You can get the calling assembly using Assembly.GetCallingAssembly , but not the calling type. Since this is an object-oriented development platform, a more appropriate implementation would accept the caller as a parameter to the method, typically declared as an abstract class or an interface. The caller would have to implement that interface or extend that abstract base class and override whatever members are appropriate to call, so that your method or class can call those methods without knowing about a specific implementation of those methods.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello!
I want to check if a program is installed. For instance I want to see if the Visual C++ Toolkit 2003 is installed on my computer. How can I do this in C#?
Thank you for helping me!
|
|
|
|
|
|
Even after enumerating and possibly finsing the correct registry key, you should check for the exsistence of the dll or exe. Windows applications are infamous for not removing all registry entries after an un-install or even people will delete directories without using the un-install. Top and bottom is even if it has a registry key, don't assume that it's there.
Just expanding on what Heath mentioned.
Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
|
|
|
|
|
True to a point (although he didn't ask about files - merely products), but Windows Installer - unless you explicitly change the execution sequence from the default or change the Component table attributes or transitive condition to keep the component installed during uninstall - will remove all files it placed there originally. Windows Installer really is a powerful package distribution system, something I've been working with since it's 1.0 beta days and am currently beta testing for 3.0. If you're interested, you should take a look at the Windows Installer SDK on MSDN.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
[original posting]I want to check if a program is installed. For instance I want to see if the Visual C++ Toolkit 2003 is installed on my computer. How can I do this in C#?
The point I'm refering to is that just because something has a registry entry, doesn't mean it exists, only that it was installed at some point in time. I know from experience not to take anything for granted if it has a registry entry.
Heath Stewart wrote:
(although he didn't ask about files - merely products),
He wants to see if a specific product is installed. I merely wanted to point out that an un-install may have failed or been un-installed incorrectly (like deleting directory - infamous in users ) and still have left registry entries that may be included in the enum.
Regards,
Eric C. Tomlinson
P.S. Haven't used Windows Installer yet, all the clients I work for have subjected me to Installshield Maybe someday I'll be able to use it on something that I write (and actually finish)
Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
|
|
|
|
|
I know that non-Windows Installer products are notorious for this, but Window Installer packages are actually transacted - you won't see this behavior (except, perhaps, from poorly-written custom actions where the developer doesn't take rollbacks into account or simply can't).
It's Windows Installer I'm defending, not installs. Regarding installs in general, I wholy agree with you...except for one problem: proprietary installs are just that - proprietary. There may be no way to determine where to even look for a product if the install information (or, rather, the uninstall information) doesn't tell you. This is another reason why Windows Installer kicks butt: it's a relational database and tracks everything from files, registry entries, and feature and component installation states.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
First I want to thank you all for your great help.
All I wanted to do is to check if the Visual C++ Toolkit 2003 is installed on a system. I give my programs only to users who uses the Uninstall packages. So there won't be problems with deleting program directories or something.
But there is only interesting thing:
When I open my Control Panel and double click "Software" (in German) or "Add Or Remove Programs" (something like that in English). However, I got a list with all currently installed programs. How is this?
|
|
|
|
|
Add/Remove Programs uses the IAppPublisher shell interface, a COM interface not available in .NET, though you can declare it in managed code. COM servers containing implementations of IAppPublisher are in the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\AppManagement\Publishers registry key. Unfortunately, COM interop with .NET requires that you import the typelibs - if available - from each of these before you can create an instance of them.
So, I recommend reading about the IAppPublisher interface in the MSDN Online Library[^] and creating a mixed-mode Managed C++ assembly. This way, you can work with native COM and expose the functionality you need to managed code. Writing an MC++ assembly this way allows you to reference it in your other managed projects, like a C# project.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
does anyone know where to find (if possible) how to implement a web service running on a Pocket PC and make an application that uses it on the same Pocket PC (in C#)?
thanks
|
|
|
|
|
I think you might run into the issue of not having a web server running on your pocket PC. Probably impossible to get IIS on the pocket PC.
Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
|
|
|
|
|
well, you're right! It seems that the only way to deal with it is to handle SOAP requests manually.. (damn'!)
I'll use replication instead!
thanx!
|
|
|
|
|
Hi all,
I'm just getting into writing unit tests - can see the benefits of them for sure.
I get the impression that there is quite a bit of skill and know-how in writing decent tests that are worth their salt. The tests are only as good as the coder writing them, eh?
It would be great to see some examples beyond the example of the bank account that is given with nunit.
I wondered if anyone here knows of any good examples of some unit tests on a more involved real world application? Or if anyone has any thought or advice on this matter it would be great to hear too.
Sorry it's a bit of a vague question - But very much looking forward to your replies.
Best wishes
Steven
|
|
|
|
|
Not really got any examples I could share but some ideas to help you out:
* Test with good input
* Test with bad input
* Test with input at the edge of valid ranges. e.g. If your method can accept an integer in the range 1 to 100 test that 0 and 101 fail properly (throwing the correct exception, or returning the appropriate success indicator), and test that 1 and 100 work.
* Test different combinations of data. e.g. if it doesn't matter which order two parameters are given, then check that by testing with these parameters in a different order.
* Look at the possible code paths inside your method and try and construct tests that will take the code through each of the possible paths.
Probably other people will reply also with other ideas, but these are some that immediately spring to mind.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
Thanks Colin, That's great.
Makes sense and I'll give it a go.
Cheers
Steven
|
|
|
|
|
|
I want read data from Serial Device COM1. Is there an example, how to do it?
Ariadne
|
|
|
|
|
|
Hi ,
im trying to parse xhtml code in a xmldocument object.
the thing is that if i try to parse the code from eg www.xhtml.org it takes 15 seconds to parse the doc (using .LoadXML(xmlstring))
BUT
if i set the documents .XMLResolver = null
it works much much faster (maybe 1-2 seconds for the same doc)
however , if the document contains tokens like & the parsing fails and crashes if the xmlresolver is null.
what can i do about this?
could it be that the xmlresolver actually downloads the "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" that is specified in the xhtml code before it parses the code?
could i somehow make local copies of those files in that case and use those somethow?
//Roger
|
|
|
|
|
You should read the documentation for the XmlResolver property and class, which would answer your questions. Yes, for fully-trusted code (by default, code executed on and from your machine) the XmlDocument.XmlResolver is an XmlUrlResolver and will resolve DTDs. So, either extend XmlResolver or XmlUrlResolver and override ResolveUri so that it doesn't fetch external resources. Do override (unless you extend XmlUrlResolver , which already does this) GetEntity so that entities are resolved. Instantiate your implementation and set that as the XmlDocument.XmlResolver .
Here's a problem, though - if that entity is defined in the DTD (since XHTML doesn't define entities like ) then you can't resolve it.
You could, however, attempt to resolve common entities (can be found on the W3C web site) as well as decimal and hexidecimal entities for character encoding, like &#XX; and &#xXX;. If the content author tries to include content using an entity, though, you'll have a problem (perhaps in this case you could fetch the DTD) before returning from your method - it may work).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the info.
i solved it by embedding the standard dtd/ent files into my lib and made my xmlresolver use the embedded resources if they exist otherwise it will use the external resources.
//Roger
|
|
|
|
|
Good idea! I hadn't thought of doing that off the top of my head.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How to write a application that the user can only use 3 times.
I'm waiting for you.
Thank you.
|
|
|
|
|
Maybe you shoud make a config file and also store some counter values in registry. On load your program should increment value in registry and if it's > 3 then your application should delete your file.
xedom developers team
|
|
|
|
|
Alex Getman (leTaon) wrote:
then your application should delete your file
Bad practice to delete from a user's PC without notification or prior notification that after # uses the app will delete itself.
Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
|
|
|
|