|
Is it possible to do this?
Here is my test function which does work locally. How can I get these values remotely, I haven't been able to find much on the net?
Thanks for reading.
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
MessageBox.Show(adapter.Name);
MessageBox.Show(adapter.OperationalStatus.ToString());
MessageBox.Show(adapter.Description);
MessageBox.Show(adapter.NetworkInterfaceType.ToString());
MessageBox.Show(adapter.Speed.ToString());
MessageBox.Show(adapter.GetIPProperties().UnicastAddresses[0].Address.ToString());
}
|
|
|
|
|
GetAllNetworkInterfaces() is specifically for the local computer, so unless you run it on the remote computer and relay the information back some way, then you can't use it.
You may be able to use WMI if it provides the information you need and the network security configuration allows it. See the WMI "Win32_NetworkAdapter" class...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
I did look at that class and I am very unfamiliar with WMI, I wasn't able to get much of anywhere with it ... here is what I tried, the only part I wasn't sure of is which values to search for after it queries the database.
public static string getNetworkCardInformation(string serverName)
{
string networkCardInformation = "";
try
{
ConnectionOptions options = new ConnectionOptions();
ManagementScope scope = new ManagementScope(GetStandardPath(serverName), options);
scope.Path = new ManagementPath(@"\\" + serverName + @"\root\cimv2");
scope.Options.Impersonation = ImpersonationLevel.Impersonate;
scope.Connect();
ObjectQuery query = new ObjectQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
using (ManagementObjectSearcher search = new ManagementObjectSearcher(scope, query))
{
foreach (ManagementObject service in search.Get())
{
networkCardInformation = service["IP address="].ToString();
}
}
}
catch (ManagementException ex)
{
networkCardInformation = "ERROR : " + ex.Message;
}
catch (COMException exc)
{
networkCardInformation = "ERROR : " + exc.Message;
}
catch (Exception e)
{
networkCardInformation = "ERROR : " + e.Message;
}
return(networkCardInformation);
|
|
|
|
|
Hi,
here is a code snippet I use to discover the content of some WMI class on the local machine; it tells what keys exist together with their value:
string clas="Win32...";
ManagementObjectSearcher searcher=new ManagementObjectSearcher("SELECT * FROM "+clas);
ManagementObjectCollection results=searcher.Get();
log("There are "+results.Count+" items in "+clas);
int count=0;
foreach (ManagementObject result in results) {
log("=============== "+clas+"["+count+"] ===============");
count++;
PropertyDataCollection pdc=result.Properties;
foreach (PropertyData pd in pdc) {
string name=pd.Name;
object obj=pd.Value;
if (obj!=null) {
string[] sa=obj as string[];
if (sa!=null) {
string ss=string.Join("\";\"", sa);
log(count.ToString()+": "+name+" = string[] = \""+ss+"\"");
} else {
log(count.ToString()+": "+name+" = \""+obj.ToString()+"\"");
}
}
}
}
You could adapt it to also run remotely and only report the key,value pairs you're interested in.
PS: I'm sure the keys don't end on an equal sign!
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
Thank you very much, I will try that tomorrow when I get back to work.
I just started using WMI today, so the equals sign thing, lol
|
|
|
|
|
You're welcome.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
|
Thank you Mark, that looks like something I can adapt right to what I already have!
I'll try it tomorrow and report back.
|
|
|
|
|
hello guys... I dont know where to put this question. Lets say I have made a notepad in C#.NET. Now how can I run that notepad on linux platform? thnx
|
|
|
|
|
You'd need a version of .NET that runs on Linux (obviously). Fortunately, there are Linux versions around, the most popular is called Mono.
|
|
|
|
|
|
Hi,
Have written a small Windows service which monitors a single folder waiting for simple text files to arrive in said folder. Once a file or files arrive, the service converts them to XML, deletes the file(s) from the 'in' folder, copies it to an 'out' folder where another process deals with them. It's a simple, clean service which runs fine 99% of the time.
However, the other 1% of the time, a file or files arrives in the 'in' folder and nothing happens. The service doesn't seem to have noticed that anything has arrived in the folder it's watching.
Does anyone know of any reason why the service would stall every so often. It's a very small problem but one that I'd like to iron out if I can....
Thanks in advance
Scott
|
|
|
|
|
Are you using the FileSystemWatcher to catch the fact that a file has been created? If you are, you should be aware that it's not 100% effective. It has some gaping deficiencies.
|
|
|
|
|
I am indeed using FileSystemWatcher to monitor the folder but I admit I was unaware of any deficiencies in it. Can you explain a little what they are please?
|
|
|
|
|
It will sometimes send a notification that a file was created before the file has finished being written. That is probably a problem more often with larger files. Like a person said below, the solution is to wait a few milliseconds if the file is not yet available. One way to do this would be to use a try/catch to check if you were able to gain a write lock on the file. If that fails, wait a few milliseconds and try again.
|
|
|
|
|
I'd just like to add that you should acquire a full lock, meaning you don't want to share the file for reading nor for writing (nor for deletion). That way, you'll be sure that no other handles to the file are open before acquiring the lock.
|
|
|
|
|
Hi.
Sometimes it happens that your thread which is responsible for creating XML files tries to read the arrived text file when it's not completely free (some service is still using it).
Try to wait for some milliseconds before attempting to open the text file like this:
Thread.Sleep(100);
I hope this will work.
|
|
|
|
|
In addition to the previous answers, I would like to suggest you on increasing the InternalBufferSize property of your file system watcher object to a bigger value.
It might help when a large number of files are being created at the same time. The lesser the value of the InternalBufferSize, the more are the chances of file changes / creations going unnoticed by the watcher.
Hope this helps.
ramzg
|
|
|
|
|
Hi all,
Thanks very much for the suggestions so far. Will implement those changes now, hopefully that will sort this last bug out.
Much obliged to you all,
Scott
|
|
|
|
|
Hi,
as others already explained, FSW has a limited buffer, so for a very active folder you might miss some events, however that seldom is the problem; the actual problem typically is FSW gets triggered by the beginning of some action (such as file creation), whereas your app typically is interested in the end of the action (file created and available).
My solution (applies only if the producer can be slightly changed) is by using a sentinel file: have the producer create and write the file of interest first, then emit a small file that signals the former has been created and written; and now make the FSW watch out for that sentinel file only; it being small causes start and end creation to coincide, so there is no need to wait or to retry. And you could store the data file's name inside the sentinel file, to remove all uncertainty.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
Sorry Luc for being lazy but would this still be an issue when streaming data in a separate thread?
"You get that on the big jobs."
|
|
|
|
|
Hi Rob, I have no idea what you are asking here.
FWIW: the FSW events get handled in a ThreadPool thread. They fire upon filesystem events such as create file, write to file, delete file, which all indicate the start of an action. There is no event for flushing or closing a file.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
modified on Friday, June 10, 2011 8:38 PM
|
|
|
|
|
OK, I was just thinking one of the main reasons the FSW InternalBuffer would overflow is because the code block within the subscribing method is taking time (ie reading file) and so other events are backing up in the buffer. And maybe a better way would be to thread the reading of the file into a separate thread to help avoid the InternalBuffer overflowing.
I guess it still isn't a solution to the problem anyway, just a way to help minimise it.
"You get that on the big jobs."
|
|
|
|
|
Oh, I see, yes when a consumer temporarily can not keep up with a producer, you would need more buffering, or split the consumption effort in a real-time task and a delayed task (a queue could be helpful here).
Under the same conditions, and assuming new files (OnCreate) are of interest, it might be wise not to use a FSW at all, and to scan the folder yourself (e.g.with Directory.GetFiles or the newer Directory.EnumerateFiles ) especially if the consumer is to also delete the files once processed.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.4
|
|
|
|
|
Good idea. I suppose whatever is writing the file could also write it to a different folder and then perform a move operation to move it to the monitored folder once the file is fully written.
|
|
|
|