C# correct Syntax for Networkconnection with adminshare - c#

I have following, simple, problem because I don't have the luxury to actually debug properly right now. This question might even seem dumb to most but I am still unexperienced when it comes to coding.
I am supposed to write a simple console application that connects to a few different clients (and one server) and replaces some files on the C Drive with Adminrights(If I understood it right that's what the C$ is for?). But because something had gone wrong in the past there are actually a few occurences where the filepath differs from the standard, so I have to check with Dictionary.Exists(path) first, to not make it any longer, what is the correct Syntax to properly connect to said folder?
I was thinking about:
Directory.Exists(#"192.168.xxx.xxx\C$\Program Files\...")
I also tried to test it via localhost, but that didn't seem to work because either I am doing it wrong or it is just not intended to work with it?

Well, figured it out now thanks to a tip from Alex K.. Didn't know that this kind of format was called UNC and did some research about it (a bunch of different sites), could easily test it on my own computer like that:
bool test = Directory.Exists(#"\\192.168.10.102\C$\Program Files")
Also works with the domainname "localhost" instead of "192.168.10.102". Both resulted in true.

Related

Any way to get the DNS cache entries in C#?

I've been looking for answers and couldn't quite find anything that worked for me, hopefully there's someone who can help me out with this.
I need to get the number of entries in the DNS cache of the computer. Not really even interested in the particular entries, just the total count.
This answer (Is there a way to monitor the system's DNS cache on c#?) comes close but I can't manage to download the powershell module to try to get it to work, plus it would be best if I could get a solution that worked without requiring any extra tools to be installed.
Thanks in advance.
I have managed to do it by using the PowerShell Get-DnsClientCache function.
DnsClient functions are apparently loaded by default in the non-server Windows OSs as well, unlike the dnsserver module.
Anyone interested can see an example on how to execute PowerShell scripts in the link posted in the original question.

Deploying a C# application - user form (novice)

I'm virtually a complete novice, I've tried Googling for answers and become totally confused.
Using Visual Studio 2010, I have a C# application which is an email notifier for a friend. The external (Arduino) hardware works, the main code (from a website) works but I'm sending it to her on the other side of the world to use and she is very 'non-technical' - hence the need for a 'setup form'.
I have created a form where she can enter comm port (selected from a list), username and password (all to be used by the main code), but that form should run only when the application is first installed on the PC.
At the moment it runs in VS-2010 (though I need to iron out a couple of snags), validates and hides - but I don't know how to a) store the data and make it available to the main code, b) ensure that the form only runs at setup, or c) exactly what I need to do or include to create an installable application.
Could somebody either help or direct me to some tutorials that don't assume I understand all the terminology?
I just want to create something that she can instal from a memory stick. I know it can be done and it's proababy quite simple for those who understand - I'm trying to learn but I'm no longer young and it's a struggle.
Thanks
a) store the data and make it available to the main code,
write the data on a file!
you have millions of possibilities, for isntance reading and writing a plain text file can be done with few lines of code, but if you want to encrypt your file (it may be the case if you want to store the password) you can use System.Security.Cryptography as shown in this guide
b) ensure that the form only runs at setup,
once you have written the file, then it means that the program has run already at least once, so you don't need to ask the user again (just read the data from the file)
c) exactly what I need to do or include to create an installable application.
Visual Studio already comes with the Setup project for this task. See this good guide.
From your comment and link to the code project for the Arduino, I gather that this is your first venture into writing code in C#, or very close to it. And ideally you'd like to make this as easy for your friend as possible. The best advice I can give you is not to try to run before you learn to walk. If you try to create a custom setup project and use a configuration file, which is what you are talking about doing, you may hit so many barriers that you never get to a successful end of the project. That kind of experience is discouraging and I'd hate for you to lose the drive to ever want to try another software project.
Make this initial project easy on yourself. This is not good programming practice for most situations, but if you only have one user, hard-code her configruation information for this first version. In other words, put her username, password, com port, etc directly into the main program. This eliminates the need for both the configuration, and any custom setup form. If you still want to make the whole thing configurable and versatile, do that in your next version. Custom setup is not a beginner task. It will be a lot easier to take on with the encouragement of your friend's excitement and compliments over a first version that works.

Translate LINQ Statement to usual Data Service URL

I want to translate a simple LINQ statement to a url that I can use on my webserver to produce my output manually. So I want to get something like this
http://localhost:6627/WebSite15/NorthwindDataService.svc/Products?$orderby=ProductName
when executing a statement like:
Products.Orderby(x => x.ProductName);
Is this possible? I mean, a simple data service does that out of the box, but I don't want to use this thing because I have special requirements.
I had a very similar problem and I found this EntitySorter and it worked wonderfully... You can see a similar implementation of it here also (look at the higher voted answer, not the marked answer).
It would let you do this kind of thing:
IEntitySorter<Person> sorter = EntitySorter<Person>
.OrderBy("Address.City")
.ThenByDescending("Id");
EDIT: On a side note, I had a perfectly justified reason to use it (and in fact was using it in a mocked service layer so I wasn't concerned about performance), but it was remarkable how much EntitySorter has to "go around your a$$ to get to your elbow" to get soft searches working... I think it was Microsoft's attempt at saying "We didn't make this easy on purpose"... That said, I thought EntitySorter was a very elegant solution considering what it's doing :)
I've realized it with a ExpressionVisitor now. Works like a charm.

C# proper way for file associations

I've been looking for a proper way to get file associations working on WinXP and above. The association should be replaced if it already exists. The application I've developed always run in admin mode, so rights shouldn't be a problem.'
I've come across some old posts that had some sample code, but some of them didn't work well enough and some not at all. I'm using this post to make a final desicion on the method I will attempt to use and am looking for as much feedback as possible.
I think you need to make changes to the registry as shown here
http://msdn.microsoft.com/en-us/library/cc144154%28v=vs.85%29.aspx#registration

How to find if app has been installed before?

Is it possible for a .NET application to leave a trace so that it can be found if the application is re-installed?
Of course, a trace that is difficult to be removed.
Create a file
Create a registry key
Create a global variable
A combination of all above
...and then check for existence the next time install is attempted.
While it is better practice to remove applications in their entirety, I assume this is for 'trial' software (one time install) purposes or a similar reason.
Well, generally, if you un-install something, you'd hope it completely removes itself, and doesn't leave a trace of the fact that it was there. Otherwise, if it doesn't, it hasn't really un-installed.
This is language-agnostic anyway.
So the answer is: Yes, but don't do that.
What problem are you really trying to solve?
Many application leave behind traces (eg in registry) to detect previous installation. However tools like RevoUninstaller can be used to completely remove those traces. One easy way of doing so is to send the machine id to your server.
I've done some Googling to find better information (with no success) but I can remember mention of something referred to as the "Manufacturers Section" of a hard drive, an area which is outside that of normal storage to which it's possible to write information that won't be lost if the drive is re-formatted. The specific product I'm remembering was AutoCAD.
The fact that you are asking for something that is "difficult to be removed" leads me to believe that you are looking for something like this?
It's unlikely that the use of this sort of technology would make you very popular with your customers, particularly with the bad feeling directed towards DRM, rootkits and the like.

Categories