Dec 30, 2016 08:40 AM
(This post was last modified: Jan 11, 2017 01:44 AM by Malum™.)
Was dissembling someone's program and noticed there HWID method and was severely disappointed. Lol. So I Google'd around and found this. Which works just fine but jesus fucking christ was it slow. So I re-coded it and organized it just a tad bit more. I haven't tested it on multiple computers, just my own.
Notes: - Make sure to Add Reference System.Management
- Because I used a translator from C# to VB.NET. They output different HWID. EX: C# 1234-4321 / VB 4321-1234
- Benchmarked at 100ms for VB.NET and 0ms for C#.
- Added Using Statements to properly Dispose of ManagementObjects.
- Increased speed using ManagementObjectSearcher
- Properly disposed of objects thanks to Ch@rLi3 (3D۞tD3v)
- Fixed ManagementObjectSearcher error. Stupid error. My bad.
- Think I optimized the WMI usage a little more. 1/9/2017
- Added using statement to SHA1 hash and changed to static class thanks to Ninja. 1/9/2017
- aneeshkollam5 found a bug with External Hard Drives and possibly USB devices. This looks promising. 1/11/2017
Code Console.WriteLine(HardwareID.Generate())
C# PasteBin Link
VB.NET PasteBin Link
Benchmark (C#)
![[Image: db4693650c.png]](https://puu.sh/t7yJ6/db4693650c.png)
Please give me suggestions on how to make it faster or better! Politely please. :)
Nice & simple.. Just how I like it!
DO NOT DEAL WITH THIS MEMBER
You could make a static class that returns a struct with properties (like each segment) and different ToString functions similar to the GUID class.
(Dec 30, 2016 10:08 AM)Ninja Wrote: You could make a static class that returns a struct with properties (like each segment) and different ToString functions similar to the GUID class.
That's a decent idea. I don't know about the ToString functions but returning a struct with each bit of info would be nice. If that is what you mean.
DO NOT DEAL WITH THIS MEMBER
(Dec 30, 2016 10:23 AM)Malum™ Wrote: That's a decent idea. I don't know about the ToString functions but returning a struct with each bit of info would be nice. If that is what you mean.
ToString can return different formats such as hyphens, no hyphens, encapsulated by curly brackets, etc. Look into the GUID ToString functions.
Good job! Adding this to my bookmarks 🤝
(Dec 30, 2016 10:33 AM)Ninja Wrote: ToString can return different formats such as hyphens, no hyphens, encapsulated by curly brackets, etc. Look into the GUID ToString functions.
Oh, gotcha, I'll play with it later and eventually update the thread by tonight with those kind of features.
Dec 30, 2016 12:34 PM
(This post was last modified: Dec 30, 2016 12:38 PM by +Haze.)
You should really work on the meaningfulness of your code. What I mean is that some of your methods and variables names are not so descriptive in the context they're used in.
Other than that good job on the release
Pro-tip:
Not in your code, but try to avoid using With ... End With
Why?
Because this:
When debuging, VS intellisense can not show you the value inside With block, but the intellisense works fine outside With block.
Seems a nonsense, but is really helpful when you are debuging and don't need switching to watch-list window.
The code provided is an example, not a real world imba algorithm, but hope you get the idea
Dec 30, 2016 12:55 PM
(This post was last modified: Dec 30, 2016 12:56 PM by Malum™.)
(Dec 30, 2016 12:34 PM)+Haze Wrote: You should really work on the meaningfulness of your code. What I mean is that some of your methods and variables names are not so descriptive in the context they're used in.
Other than that good job on the release
As in commenting the code or what? Give me some examples if you would.
(Dec 30, 2016 12:50 PM)Zilog80 Wrote: Pro-tip:
Not in your code, but try to avoid using With ... End With
I already knew that. I just took advantage of the feature when I used VB.NET otherwise never touch it. Thank you for the warning though!
Ohhh Damn...... don't forget to dispose objects......
Code using (ManagementObjectCollection moc = new ManagementClass(wclass).GetInstances()) {
//......
//.........
}
but ... nice try. ;)
Dec 30, 2016 08:52 PM
(This post was last modified: Dec 30, 2016 08:56 PM by Malum™.)
(Dec 30, 2016 03:38 PM)sh@rp Wrote: Ohhh Damn...... don't forget to dispose objects......
Code using (ManagementObjectCollection moc = new ManagementClass(wclass).GetInstances()) {
//......
//.........
}
but ... nice try. ;)
"The using statement ensures that Dispose is called even if an exception occurs while you are calling methods on the object." - MSDN
Unless you have other reasoning?
EDIT: Oh! I see what I missed. Hopefully GC will have my back. Haha. I'll fix it when I get home.
(Dec 30, 2016 08:40 AM)Malum™ Wrote: Please give me suggestions on how to make it faster or better! Politely please. :)
If you want to speed it up then don't use WMI.
Dec 31, 2016 09:48 AM
(This post was last modified: Dec 31, 2016 10:45 AM by sh@rp.)
(Dec 30, 2016 08:52 PM)Malum™ Wrote: Unless you have other reasoning?
EDIT: Oh! I see what I missed. Hopefully GC will have my back. Haha. I'll fix it when I get home.
If you want to give advices and lessons please reads properly MSDN :
Quote:As a rule, when you use an IDisposable object, you should declare and instantiate it in a using statement. The using statement calls the Dispose method on the object in the correct way, and (when you use it as shown earlier) it also causes the object itself to go out of scope as soon as Dispose is called. Within the using block, the object is read-only and cannot be modified or reassigned.
Does your "moc" object isn't disposable and also does your instance is used outside of your GetHardwareProperty method ......
ok ... nstr...
......
Dec 31, 2016 07:10 PM
(This post was last modified: Dec 31, 2016 07:13 PM by Malum™.)
(Dec 31, 2016 09:48 AM)sh@rp Wrote: If you want to give advices and lessons please reads properly MSDN :
Does your "moc" object isn't disposable and also does your instance is used outside of your GetHardwareProperty method ......
No need to be sassy. Lol. I misunderstood and did not read further into it. It was a misunderstanding. Thank you for the information!
(Dec 31, 2016 04:08 AM)ubbelol Wrote: If you want to speed it up then don't use WMI.
Do you know a different alternative? I tried looking into EventLogs but didn't quite understand it.
|