|
|
Hey Guys, Gals.
The following function I am quite stuck on... and hope you are able to help or provide some form of direction.
Basically I have been able to gather "logical drive details" about connected storage, however, with regards to the Serial Number, all I can acquire is the Volume Number, which is not unique to the physical hard drive itself.
I realise that in order to acquire the manufactures serial number I need to utilise the Win32_PhysicalMedia Class, (link below), however I haven't got the foggiest with whats going wrong
Does anyone have any ideas, code example that actually works?
I am using Vista or XP Professional, Visual Studio 2008.
This is what I have so far....
ManagementObjectSearcher Serial = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")
foreach (ManagementObject Serials in Serial.Get()
{ combo_box.Items.Add(Serials["SerialNumber"].ToString()); }
Furthermore, the error I get is: NullReferenceException was unhandled, object reference not set to an instance of an object? Use the "new keywords" to create an object instance?
Cheers
Ian.
http://msdn2.microsoft.com/en-us/library/aa394346.aspx">http://www.eggheadcafe.com/forumtree.aspx?topicid=2
|
|
|
|
|
Hi,
you're on the right track, however not all objects returned by your WMI have a SerialNumber,
so Serials["SerialNumber"] would be null for them. You need a null-test; adding a few log
statements to your code would have told you what was going on.
BTW: you will probably also need new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDiskToPartition");
in search of the drive number that corresponds to a particular drive letter.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hello everybody,
I am searching for a long time for a possibility to read some windows settings and display it in my C#-program.
I want to have the following options:
start-> run -> "dcomcnfg" -> components -> computer -> My Computer
now right click on "my computer" -> "Properties"
Now register "Com Security" and "edit Limits" Now I want to display all users and their rights. Only read, not write new rights (at the moment). My programm and myself are working with full admin rights, so there should be no problem with rights or something like that.
I do not know how I can get the user and their rights in my program. In the registry, there is value with a very long string. if I change the rights, the string will be changed too. But I do not know if the string represents the full users including their rights. And how I read (decode) it?
Is this the right way?
Can you help me?
Thanks for your answers!!!!
|
|
|
|
|
Hi,
I'm building a small command line app to test connections to remote system, just like with telnet. I need it to test both TCP and UDP connections.
TCP works fine but i don't know how to test UDP connections since they are stateless.
For testing TCP I'm using
<br />
System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)<br />
Then i use the Socket.Connect(hostName, portNumber) method to establish connection. If that succeeds and no exception is thrown, i count it as success.
If i try the same with UDP
<br />
System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)<br />
Using Socket.Connect(hostName, portNumber) method against a closed port doesn't throw an exception or any other sign of failure.
Can any one suggest a way to test UDP connections?
Thanks,
darthBug
Join the dark side of the code
|
|
|
|
|
Hi!
I don't think that you can test UDP "connections" that way simply because UDP is a connectionless protocol. Fire and forget - if the packet reaches the destination: fine, if not: bad luck.
You'd have to have a counterpart on the other side actually receiving the UDP packet and sending back a reply.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Thanks,
I was afraid that it would be the case. I guess i'll have to engineer something...
darthBug
Join the dark side of the code
|
|
|
|
|
Hi everyone,
I am writing a server-client chat application where I have a ServerObject that is subclassed from MarshalByRefObject and is created as a Singleton. This ServerObject is acquired by the client by the GetActivator() method. Now, I wanted to add an event handler that will be raised when someone joins or leaves the chat room. So, I have done something like this-
<br />
public delegate void OnUsersJoinEventHandler(object sender, EventArgs e);<br />
public delegate void OnUsersLeaveEventHandler(object sender, EventArgs e);<br />
<br />
public class ChatServerObject : MarshalByRefObject<br />
{<br />
public event OnUsersJoinEventHandler UsersJoin;<br />
public event OnUsersLeaveEventHandler UsersLeave;<br />
<br />
protected virtual void OnUsersJoin(EventArgs e)<br />
{<br />
...<br />
}<br />
<br />
protected virtual void OnUsersLeave(EventArgs e)<br />
{<br />
...<br />
}<br />
}<br />
<br />
public class ChatClient<br />
{<br />
public ChatClient()<br />
{<br />
object server_obj = Activator.GetObject(typeof(ChatServerObject), "tcp://...");<br />
m_chat_server_object = (ChatServerObject)server_obj;<br />
<br />
m_chat_server_object.UsersLeave += new ChatServerObject(this.UsersLeft);....Line(1)<br />
}<br />
}<br />
So, you get the idea. Now, when the code compiles okay but when the runtime executes the line (1) above it throws an exception. The exception says the following-
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll. Getting the InnerException wasn't much insightful either. I can send you the full string of the InnerException if you think it might be useful. I tried to create another class that was subclassed from MarshalByRefObject but wasn't Registered as WKO; and that works fine. So, perhaps it has something to do with the fact that my server object is a WKO. Any insights into this problem will be useful.
|
|
|
|
|
Hi,
Below is my question on a similar problem and no one has responded since the last 3 days and I have posted it twice.
Anyhow, I am started to think it has something to delegates or events--just an assumption, as I have a similar design and it causes exception.
My problem is below somewhere if you want to have a look. I am searching and if I find anything I will let you know and if you find anything, I'd appreciate the same.
|
|
|
|
|
Hi!
How is your server object instantiated? Singleton? Single Call? Published directly?
It seems there's a problem on the server side either with object creation or event registration.
Could you post the server's constructor and more details regarding the server and client remoting configuration (TypeFilterLevel etc.)?
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
In MDIParent Form, I am using tableLayoutPanel control with two colomns and I want to open a child form in second column of tableLayoutPanel at runtime. Is this possible? Please reply as soon as possible.
|
|
|
|
|
Dear All,
I need to administrator the Indexing Service via the Web Application,
I did find a component that i good for desktop but not for web application.
Any suggestion would be highly appericated.
Thank you!
Nauman
"Mess with the Best, Die like the rest"
|
|
|
|
|
How do i create a program using c# to block unwanted access to certain website such as playboy.com?
|
|
|
|
|
If you are creating your own browser, then you could parse the urls/links for for words or sites in a dictionary. When a match occurs you could immediately redirect to another webpage.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
using system.ole
Hussaingreat
|
|
|
|
|
Listen ..
We're more than keen on helping you out, but this is absolutely too little information.
Or maybe I should just anwser just as thoughfully as you asked your question.
try this :
for (int i=1;i < 500; i++)<br />
{<br />
Console.WriteLine(i.ToString() + " : I need to give more information");<br />
}
|
|
|
|
|
Is there any build-in method to compare byte array or do I have to do it manualy ?
|
|
|
|
|
I don't believe there's a built in function, and I've seen some pretty *interesting* ways people have done it, but bytewise comparison is simple and fast unless you're talking GBs of data.
static bool compareByteArrays(byte[] arr1, byte[] arr2) {
int len, i;
for(i = 0, len = arr1.Length; i < len && arr1[i] == arr2[i]; i++);
return i == len;
}
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Hey
try this :
public static bool ArraysEqual(byte[] by1, byte[] by2)<br />
{<br />
if ( by1 == null )<br />
throw new ArgumentNullException("by1");<br />
if ( by2 == null )<br />
throw new ArgumentNullException("by2");<br />
<br />
if ( by1.Length != by2.Length )<br />
return false;<br />
<br />
for(int i=0; i < by1.Length; i++)<br />
{<br />
if ( by1[i] != by2[i] )<br />
return false;<br />
}<br />
return true;<br />
}<br />
Hope this helps
Cheers
|
|
|
|
|
Thank you both
I will so write my own one because I need an equivalent to memcmp, not returning a bool but an integer telling who is greater
|
|
|
|
|
Hello
I need to use a BinaryReader to read strings but I want to know how to prepare string in my file
This is to documentation comment :
Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time
Does it mean that a string can't be longer than 127 bytes (7 bits integer) ??
|
|
|
|
|
I use the following method to read files. Its pretty fast and then you could use regular expressions to find text within the returned string or what ever else you need to do with the content.
<br />
public string DecodeFile(string fullpath)<br />
{<br />
if (File.Exists(fullpath) == false)<br />
throw new FileNotFoundException();<br />
<br />
try<br />
{<br />
FileStream fStream = File.OpenRead(fullpath);<br />
byte[] buffer = new byte[fStream.Length];<br />
int bytesRead;<br />
bytesRead = fStream.Read(buffer, 0, buffer.Length);<br />
fStream.Close();<br />
fStream.Dispose();<br />
<br />
if (bytesRead <= 0)<br />
throw new Exception("Empty file.");<br />
<br />
Decoder decoder = Encoding.Default.GetDecoder();<br />
char[] cBuffer = new char[buffer.Length];<br />
<br />
int bytesConverted, charsConverted;<br />
bool bCompleted;<br />
<br />
decoder.Convert(buffer, 0, buffer.Length, cBuffer, 0, buffer.Length, false, out bytesConverted, out charsConverted, out bCompleted);<br />
return new String(cBuffer, 0, bytesConverted);<br />
}<br />
catch (Exception ex)<br />
{<br />
throw new Exception(ex.Message);<br />
}<br />
<br />
}<br />
Google search lead me to this info
"Well, its not quite that simple. int.MaxValue is the most the string class
itself could handle, you are right, but since characters take up two bytes,
that many characters would go way beyond the max possible allocation. The
best theoretical high value is 2^31(or 2147483648) characters, since that is
exactly how many would fit in memory. Practially it'd be much, much smaller."
http://bytes.com/forum/thread481655.html[^]
Just because we can; does not mean we should.
|
|
|
|
|
Hello
This can be good for little file but if you have to manage a few very big files it does not seems to be a good approach
And it does not give me the answer to my question : what is 7 bits encoded integer. Does it limit string lenght to 127 bytes ?
|
|
|
|
|
Take a look at the BinaryReader.Read7BitEncodedInt, BinaryWriter.Write7BitEncodedInt.
The 7 bits integer means that a 32 or 64 bit int can be written in a single byte if the value of the int does not exceeds 7bit (127 decimal). This is done to save space, i.e. an int instead of 4 or 8 bytes may be saved in a single byte.
|
|
|
|
|
Thank you
Finaly thank to you I've found on internet how to build an 7 bit encoded integer !
|
|
|
|