├── .gitignore
├── .travis.yml
├── Demo
├── Demo.csproj
├── Form1.Designer.cs
├── Form1.cs
├── Form1.resx
├── Program.cs
└── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── LICENSE
├── README.md
├── UHWID
├── CpuId.cs
├── DiskId.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── UHWID.csproj
├── UHWIDEngine.cs
└── WindowsId.cs
└── UHWID_&_Demo.sln
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # MSTest test Results
33 | [Tt]est[Rr]esult*/
34 | [Bb]uild[Ll]og.*
35 |
36 | # NUNIT
37 | *.VisualState.xml
38 | TestResult.xml
39 |
40 | # Build Results of an ATL Project
41 | [Dd]ebugPS/
42 | [Rr]eleasePS/
43 | dlldata.c
44 |
45 | # Benchmark Results
46 | BenchmarkDotNet.Artifacts/
47 |
48 | # .NET Core
49 | project.lock.json
50 | project.fragment.lock.json
51 | artifacts/
52 | **/Properties/launchSettings.json
53 |
54 | *_i.c
55 | *_p.c
56 | *_i.h
57 | *.ilk
58 | *.meta
59 | *.obj
60 | *.pch
61 | *.pdb
62 | *.pgc
63 | *.pgd
64 | *.rsp
65 | *.sbr
66 | *.tlb
67 | *.tli
68 | *.tlh
69 | *.tmp
70 | *.tmp_proj
71 | *.log
72 | *.vspscc
73 | *.vssscc
74 | .builds
75 | *.pidb
76 | *.svclog
77 | *.scc
78 |
79 | # Chutzpah Test files
80 | _Chutzpah*
81 |
82 | # Visual C++ cache files
83 | ipch/
84 | *.aps
85 | *.ncb
86 | *.opendb
87 | *.opensdf
88 | *.sdf
89 | *.cachefile
90 | *.VC.db
91 | *.VC.VC.opendb
92 |
93 | # Visual Studio profiler
94 | *.psess
95 | *.vsp
96 | *.vspx
97 | *.sap
98 |
99 | # Visual Studio Trace Files
100 | *.e2e
101 |
102 | # TFS 2012 Local Workspace
103 | $tf/
104 |
105 | # Guidance Automation Toolkit
106 | *.gpState
107 |
108 | # ReSharper is a .NET coding add-in
109 | _ReSharper*/
110 | *.[Rr]e[Ss]harper
111 | *.DotSettings.user
112 |
113 | # JustCode is a .NET coding add-in
114 | .JustCode
115 |
116 | # TeamCity is a build add-in
117 | _TeamCity*
118 |
119 | # DotCover is a Code Coverage Tool
120 | *.dotCover
121 |
122 | # AxoCover is a Code Coverage Tool
123 | .axoCover/*
124 | !.axoCover/settings.json
125 |
126 | # Visual Studio code coverage results
127 | *.coverage
128 | *.coveragexml
129 |
130 | # NCrunch
131 | _NCrunch_*
132 | .*crunch*.local.xml
133 | nCrunchTemp_*
134 |
135 | # MightyMoose
136 | *.mm.*
137 | AutoTest.Net/
138 |
139 | # Web workbench (sass)
140 | .sass-cache/
141 |
142 | # Installshield output folder
143 | [Ee]xpress/
144 |
145 | # DocProject is a documentation generator add-in
146 | DocProject/buildhelp/
147 | DocProject/Help/*.HxT
148 | DocProject/Help/*.HxC
149 | DocProject/Help/*.hhc
150 | DocProject/Help/*.hhk
151 | DocProject/Help/*.hhp
152 | DocProject/Help/Html2
153 | DocProject/Help/html
154 |
155 | # Click-Once directory
156 | publish/
157 |
158 | # Publish Web Output
159 | *.[Pp]ublish.xml
160 | *.azurePubxml
161 | # Note: Comment the next line if you want to checkin your web deploy settings,
162 | # but database connection strings (with potential passwords) will be unencrypted
163 | *.pubxml
164 | *.publishproj
165 |
166 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
167 | # checkin your Azure Web App publish settings, but sensitive information contained
168 | # in these scripts will be unencrypted
169 | PublishScripts/
170 |
171 | # NuGet Packages
172 | *.nupkg
173 | # The packages folder can be ignored because of Package Restore
174 | **/packages/*
175 | # except build/, which is used as an MSBuild target.
176 | !**/packages/build/
177 | # Uncomment if necessary however generally it will be regenerated when needed
178 | #!**/packages/repositories.config
179 | # NuGet v3's project.json files produces more ignorable files
180 | *.nuget.props
181 | *.nuget.targets
182 |
183 | # Microsoft Azure Build Output
184 | csx/
185 | *.build.csdef
186 |
187 | # Microsoft Azure Emulator
188 | ecf/
189 | rcf/
190 |
191 | # Windows Store app package directories and files
192 | AppPackages/
193 | BundleArtifacts/
194 | Package.StoreAssociation.xml
195 | _pkginfo.txt
196 | *.appx
197 |
198 | # Visual Studio cache files
199 | # files ending in .cache can be ignored
200 | *.[Cc]ache
201 | # but keep track of directories ending in .cache
202 | !*.[Cc]ache/
203 |
204 | # Others
205 | ClientBin/
206 | ~$*
207 | *~
208 | *.dbmdl
209 | *.dbproj.schemaview
210 | *.jfm
211 | *.pfx
212 | *.publishsettings
213 | orleans.codegen.cs
214 |
215 | # Since there are multiple workflows, uncomment next line to ignore bower_components
216 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
217 | #bower_components/
218 |
219 | # RIA/Silverlight projects
220 | Generated_Code/
221 |
222 | # Backup & report files from converting an old project file
223 | # to a newer Visual Studio version. Backup files are not needed,
224 | # because we have git ;-)
225 | _UpgradeReport_Files/
226 | Backup*/
227 | UpgradeLog*.XML
228 | UpgradeLog*.htm
229 |
230 | # SQL Server files
231 | *.mdf
232 | *.ldf
233 | *.ndf
234 |
235 | # Business Intelligence projects
236 | *.rdl.data
237 | *.bim.layout
238 | *.bim_*.settings
239 |
240 | # Microsoft Fakes
241 | FakesAssemblies/
242 |
243 | # GhostDoc plugin setting file
244 | *.GhostDoc.xml
245 |
246 | # Node.js Tools for Visual Studio
247 | .ntvs_analysis.dat
248 | node_modules/
249 |
250 | # Typescript v1 declaration files
251 | typings/
252 |
253 | # Visual Studio 6 build log
254 | *.plg
255 |
256 | # Visual Studio 6 workspace options file
257 | *.opt
258 |
259 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
260 | *.vbw
261 |
262 | # Visual Studio LightSwitch build output
263 | **/*.HTMLClient/GeneratedArtifacts
264 | **/*.DesktopClient/GeneratedArtifacts
265 | **/*.DesktopClient/ModelManifest.xml
266 | **/*.Server/GeneratedArtifacts
267 | **/*.Server/ModelManifest.xml
268 | _Pvt_Extensions
269 |
270 | # Paket dependency manager
271 | .paket/paket.exe
272 | paket-files/
273 |
274 | # FAKE - F# Make
275 | .fake/
276 |
277 | # JetBrains Rider
278 | .idea/
279 | *.sln.iml
280 |
281 | # CodeRush
282 | .cr/
283 |
284 | # Python Tools for Visual Studio (PTVS)
285 | __pycache__/
286 | *.pyc
287 |
288 | # Cake - Uncomment if you are using it
289 | # tools/**
290 | # !tools/packages.config
291 |
292 | # Tabs Studio
293 | *.tss
294 |
295 | # Telerik's JustMock configuration file
296 | *.jmconfig
297 |
298 | # BizTalk build output
299 | *.btp.cs
300 | *.btm.cs
301 | *.odx.cs
302 | *.xsd.cs
303 |
304 | # OpenCover UI analysis results
305 | OpenCover/
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: csharp
2 | solution: UHWID_&_Demo.sln
3 |
--------------------------------------------------------------------------------
/Demo/Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Demo.Program
5 | publish\
6 | true
7 | Disk
8 | false
9 | Foreground
10 | 7
11 | Days
12 | false
13 | false
14 | true
15 | 0
16 | 1.0.0.%2a
17 | false
18 | false
19 | true
20 |
21 |
22 |
23 | Debug
24 | AnyCPU
25 | {6DDB292C-8C45-44DB-9933-D50B03A67256}
26 | WinExe
27 | Properties
28 | Demo
29 | Demo
30 | v2.0
31 | 512
32 |
33 |
34 | x86
35 | true
36 | full
37 | false
38 | bin\Debug\
39 | DEBUG;TRACE
40 | prompt
41 | 4
42 | Auto
43 |
44 |
45 | AnyCPU
46 | pdbonly
47 | true
48 | bin\Release\
49 | TRACE
50 | prompt
51 | 4
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | Form
64 |
65 |
66 | Form1.cs
67 |
68 |
69 |
70 |
71 | Form1.cs
72 |
73 |
74 | ResXFileCodeGenerator
75 | Resources.Designer.cs
76 | Designer
77 |
78 |
79 | True
80 | Resources.resx
81 |
82 |
83 | SettingsSingleFileGenerator
84 | Settings.Designer.cs
85 |
86 |
87 | True
88 | Settings.settings
89 | True
90 |
91 |
92 |
93 |
94 | {5f4b5d3c-4558-4062-9a43-b8024139bf19}
95 | HardwareID
96 |
97 |
98 |
99 |
100 | False
101 | .NET Framework 3.5 SP1 Client Profile
102 | false
103 |
104 |
105 | False
106 | .NET Framework 3.5 SP1
107 | true
108 |
109 |
110 | False
111 | Windows Installer 3.1
112 | true
113 |
114 |
115 |
116 |
123 |
--------------------------------------------------------------------------------
/Demo/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Demo
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.textBox1 = new System.Windows.Forms.TextBox();
32 | this.button1 = new System.Windows.Forms.Button();
33 | this.textBox2 = new System.Windows.Forms.TextBox();
34 | this.label1 = new System.Windows.Forms.Label();
35 | this.label2 = new System.Windows.Forms.Label();
36 | this.SuspendLayout();
37 | //
38 | // textBox1
39 | //
40 | this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
41 | this.textBox1.Location = new System.Drawing.Point(12, 92);
42 | this.textBox1.Name = "textBox1";
43 | this.textBox1.Size = new System.Drawing.Size(618, 26);
44 | this.textBox1.TabIndex = 0;
45 | //
46 | // button1
47 | //
48 | this.button1.Location = new System.Drawing.Point(374, 12);
49 | this.button1.Name = "button1";
50 | this.button1.Size = new System.Drawing.Size(256, 49);
51 | this.button1.TabIndex = 3;
52 | this.button1.Text = "Get Unique Hardware IDs";
53 | this.button1.UseVisualStyleBackColor = true;
54 | this.button1.Click += new System.EventHandler(this.button1_Click_1);
55 | //
56 | // textBox2
57 | //
58 | this.textBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
59 | this.textBox2.Location = new System.Drawing.Point(12, 35);
60 | this.textBox2.Name = "textBox2";
61 | this.textBox2.Size = new System.Drawing.Size(343, 26);
62 | this.textBox2.TabIndex = 4;
63 | //
64 | // label1
65 | //
66 | this.label1.AutoSize = true;
67 | this.label1.Location = new System.Drawing.Point(12, 12);
68 | this.label1.Name = "label1";
69 | this.label1.Size = new System.Drawing.Size(210, 13);
70 | this.label1.TabIndex = 5;
71 | this.label1.Text = "SimpleUID (First drive ID and Processor ID)";
72 | //
73 | // label2
74 | //
75 | this.label2.AutoSize = true;
76 | this.label2.Location = new System.Drawing.Point(12, 70);
77 | this.label2.Name = "label2";
78 | this.label2.Size = new System.Drawing.Size(292, 13);
79 | this.label2.TabIndex = 6;
80 | this.label2.Text = "AdvancedUID (SimpleUID plus Windows version MD5 hash)";
81 | //
82 | // Form1
83 | //
84 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
85 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
86 | this.ClientSize = new System.Drawing.Size(648, 137);
87 | this.Controls.Add(this.label2);
88 | this.Controls.Add(this.label1);
89 | this.Controls.Add(this.textBox2);
90 | this.Controls.Add(this.button1);
91 | this.Controls.Add(this.textBox1);
92 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
93 | this.MaximizeBox = false;
94 | this.Name = "Form1";
95 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
96 | this.Text = "UHWID Demo";
97 | this.ResumeLayout(false);
98 | this.PerformLayout();
99 |
100 | }
101 |
102 | #endregion
103 |
104 | private System.Windows.Forms.TextBox textBox1;
105 | private System.Windows.Forms.Button button1;
106 | private System.Windows.Forms.TextBox textBox2;
107 | private System.Windows.Forms.Label label1;
108 | private System.Windows.Forms.Label label2;
109 | }
110 | }
111 |
112 |
--------------------------------------------------------------------------------
/Demo/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using UHWID;
4 |
5 | namespace Demo
6 | {
7 | public partial class Form1 : Form
8 | {
9 | public Form1()
10 | {
11 | InitializeComponent();
12 | }
13 |
14 | private void button1_Click_1(object sender, EventArgs e)
15 | {
16 | textBox2.Text = UHWIDEngine.SimpleUid;
17 | textBox1.Text = UHWIDEngine.AdvancedUid;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Demo/Form1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/Demo/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | namespace Demo
6 | {
7 | static class Program
8 | {
9 | ///
10 | /// The main entry point for the application.
11 | ///
12 | [STAThread]
13 | static void Main()
14 | {
15 | Application.EnableVisualStyles();
16 | Application.SetCompatibleTextRenderingDefault(false);
17 | Application.Run(new Form1());
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Demo/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Demo for UHWID.dll")]
9 | [assembly: AssemblyDescription("David Castillo ")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("David Castillo ")]
12 | [assembly: AssemblyProduct("Demo for UHWID.dll")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("David Castillo ")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("84b9b145-a9d2-46f6-ad65-6abd8f4faac8")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Demo/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Demo.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Demo.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Demo/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/Demo/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Demo.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Demo/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 David Castillo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | C# Unique Hardware ID
2 | ============
3 |
4 | [](https://travis-ci.org/davcs86/csharp-uhwid)
5 |
6 | C# class to generate an Unique Hardware ID.
7 |
8 | Sometimes is required create unique identifiers for PCs. There are different approaches for doing that, the most basic among these is to use hardware IDs since they're constant (at most of time).
9 |
10 | The most popular are the First Drive Volume ID and the processor ID, using the Windows Management Instrumentation (WMI) infrastructure.
11 |
12 | This simple class (about 8kb) generates two unique IDs.
13 |
14 | 1. SimpleUID, a concatenation of the First Drive Volume ID and the processor ID.
15 | 2. AdvancedUID, the simpleUID plus a MD5 hash of the Windows build version.
16 |
17 | #### Notes:
18 |
19 | * In Virtualized environments (eg. VirtualBox, VMware, etc) the processor is not available through the WMI. Thus, the class implements an inline Assembly solution (credits to: ).
20 | * The MD5 hash is generated using the Windows codename and the build number in order to avoid repetition when the build number is the same for 2 or more different operating systems. E.g. Windows 7 & Windows Server 2008 had the same build number. You can check out an approximate list of the Windows Version Numbers on .
21 | * The project files and the solution files were intentionally made in Visual C# 2010 Express for convenience of users, and targets to .NET Framework 2.0 x86 with compatibility purposes.
22 |
23 | #### CONSIDERATIONS
24 |
25 | * **DO NOT** use any of the generated UIDs for production environments, since the code is public, anyone can replicate the UID. It's **STRONGLY RECOMMENDED** to scramble/encrypt the generated UID with a application specific algorithm.
26 | * **AVOID** use external libraries (like this) to generate & validate licenses, due to anybody could patch the dll file to break your licensing system.
27 |
28 | ## Links
29 |
30 | * Source:
31 | * Bugs:
32 |
33 | ## Requirements:
34 |
35 | 1. .NET Framework 2.0+
36 | 2. Visual C# 2010 Express (and later).
37 |
38 | ## Download:
39 |
40 | * As zip from this repository:
41 |
42 | * With git from a terminal:
43 |
44 | ```sh
45 | git clone https://github.com/davcs86/csharp-uhwid.git
46 | ```
47 |
48 | ## How to Use:
49 |
50 | 1. a) Compile the downloaded code and reference the DLL in your project, or
51 |
52 | 1. b) Add the file **/UHWID/UHWID.cs** to your project.
53 |
54 | 2. Add the namespace **UHWID** where you'll use the class.
55 |
56 | ```c#
57 | using UHWID;
58 | ```
59 | 3. Get any of the UIDs
60 |
61 | ```c#
62 | String SimpleUID = UHWIDEngine.SimpleUID;
63 | String AdvancedUID = UHWIDEngine.AdvancedUID;
64 | ```
65 |
66 | ## Support
67 |
68 | Drop me line on: davcs86@gmail.com
69 |
70 | ## Donations
71 |
72 | Did this project help you to save (or earn) some money?
73 | Please, support to the author by making a small donation.
74 |
75 |
76 |
--------------------------------------------------------------------------------
/UHWID/CpuId.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace UHWID
5 | {
6 | internal static class CpuId
7 | {
8 |
9 | [DllImport("user32", EntryPoint = "CallWindowProcW", CharSet = CharSet.Unicode, SetLastError = true,
10 | ExactSpelling = true)]
11 | private static extern IntPtr CallWindowProcW([In] byte[] bytes, IntPtr hWnd, int msg, [In, Out] byte[] wParam,
12 | IntPtr lParam);
13 |
14 | [return: MarshalAs(UnmanagedType.Bool)]
15 | [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
16 | public static extern bool VirtualProtect([In] byte[] bytes, IntPtr size, int newProtect, out int oldProtect);
17 |
18 | const int PAGE_EXECUTE_READWRITE = 0x40;
19 |
20 | public static string GetCpuId()
21 | {
22 | var sn = new byte[8];
23 |
24 | return !ExecuteCode(ref sn) ? "ND" : string.Format("{0:X8}{1:X8}", BitConverter.ToUInt32(sn, 4), BitConverter.ToUInt32(sn, 0));
25 | }
26 |
27 | private static bool ExecuteCode(ref byte[] result)
28 | {
29 | /* The opcodes below implement a C function with the signature:
30 | * __stdcall CpuIdWindowProc(hWnd, Msg, wParam, lParam);
31 | * with wParam interpreted as an 8 byte unsigned character buffer.
32 | * */
33 |
34 | var isX64Process = IntPtr.Size == 8;
35 | byte[] code;
36 |
37 | if (isX64Process)
38 | {
39 | code = new byte[]
40 | {
41 | 0x53, /* push rbx */
42 | 0x48, 0xc7, 0xc0, 0x01, 0x00, 0x00, 0x00, /* mov rax, 0x1 */
43 | 0x0f, 0xa2, /* cpuid */
44 | 0x41, 0x89, 0x00, /* mov [r8], eax */
45 | 0x41, 0x89, 0x50, 0x04, /* mov [r8+0x4], edx */
46 | 0x5b, /* pop rbx */
47 | 0xc3, /* ret */
48 | };
49 | }
50 | else
51 | {
52 | code = new byte[]
53 | {
54 | 0x55, /* push ebp */
55 | 0x89, 0xe5, /* mov ebp, esp */
56 | 0x57, /* push edi */
57 | 0x8b, 0x7d, 0x10, /* mov edi, [ebp+0x10] */
58 | 0x6a, 0x01, /* push 0x1 */
59 | 0x58, /* pop eax */
60 | 0x53, /* push ebx */
61 | 0x0f, 0xa2, /* cpuid */
62 | 0x89, 0x07, /* mov [edi], eax */
63 | 0x89, 0x57, 0x04, /* mov [edi+0x4], edx */
64 | 0x5b, /* pop ebx */
65 | 0x5f, /* pop edi */
66 | 0x89, 0xec, /* mov esp, ebp */
67 | 0x5d, /* pop ebp */
68 | 0xc2, 0x10, 0x00, /* ret 0x10 */
69 | };
70 | }
71 |
72 | var ptr = new IntPtr(code.Length);
73 |
74 | if (!VirtualProtect(code, ptr, PAGE_EXECUTE_READWRITE, out _))
75 | Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
76 |
77 | ptr = new IntPtr(result.Length);
78 | return CallWindowProcW(code, IntPtr.Zero, 0, result, ptr) != IntPtr.Zero;
79 |
80 | }
81 | }
82 | }
--------------------------------------------------------------------------------
/UHWID/DiskId.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Management;
3 |
4 | namespace UHWID
5 | {
6 | internal class DiskId
7 | {
8 | public static string GetDiskId()
9 | {
10 | return GetDiskId("");
11 | }
12 | private static string GetDiskId(string diskLetter)
13 | {
14 | //Find first drive
15 | if (string.IsNullOrEmpty(diskLetter))
16 | {
17 | foreach (var compDrive in DriveInfo.GetDrives())
18 | {
19 | if (compDrive.IsReady)
20 | {
21 | diskLetter = compDrive.RootDirectory.ToString();
22 | break;
23 | }
24 | }
25 | }
26 | if (!string.IsNullOrEmpty(diskLetter) && diskLetter.EndsWith(":\\"))
27 | {
28 | //C:\ -> C
29 | diskLetter = diskLetter.Substring(0, diskLetter.Length - 2);
30 | }
31 | var disk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + diskLetter + @":""");
32 | disk.Get();
33 |
34 | var volumeSerial = disk["VolumeSerialNumber"].ToString();
35 | disk.Dispose();
36 |
37 | return volumeSerial;
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/UHWID/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("UHWID")]
9 | [assembly: AssemblyDescription("C# library to get an Unique Hardware ID.")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("David Castillo ")]
12 | [assembly: AssemblyProduct("C# library to get an Unique Hardware ID.")]
13 | [assembly: AssemblyCopyright("David Castillo ")]
14 | [assembly: AssemblyTrademark("David Castillo ")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("561a684d-5931-4c37-a408-052714c20cd9")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | [assembly: AssemblyVersion("1.0.1.0")]
33 | [assembly: AssemblyFileVersion("1.0.1.0")]
34 |
--------------------------------------------------------------------------------
/UHWID/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Este código fue generado por una herramienta.
4 | // Versión de runtime:4.0.30319.18444
5 | //
6 | // Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si
7 | // se vuelve a generar el código.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace UHWID.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// Clase de recurso con establecimiento inflexible de tipos, para buscar cadenas traducidas, etc.
17 | ///
18 | // StronglyTypedResourceBuilder generó automáticamente esta clase
19 | // a través de una herramienta como ResGen o Visual Studio.
20 | // Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen
21 | // con la opción /str o vuelva a generar su proyecto de VS.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Devuelve la instancia de ResourceManager almacenada en caché utilizada por esta clase.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("UHWID.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Reemplaza la propiedad CurrentUICulture del subproceso actual para todas las
51 | /// búsquedas de recursos mediante esta clase de recurso con establecimiento inflexible de tipos.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/UHWID/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/UHWID/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Este código fue generado por una herramienta.
4 | // Versión de runtime:4.0.30319.18444
5 | //
6 | // Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si
7 | // se vuelve a generar el código.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace UHWID.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/UHWID/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/UHWID/UHWID.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.50727
7 | 2.0
8 | {5F4B5D3C-4558-4062-9A43-B8024139BF19}
9 | Library
10 | Properties
11 | UHWID
12 | UHWID
13 | v2.0
14 |
15 |
16 |
17 |
18 | 2.0
19 | publish\
20 | true
21 | Disk
22 | false
23 | Foreground
24 | 7
25 | Days
26 | false
27 | false
28 | true
29 | 0
30 | 1.0.0.%2a
31 | false
32 | false
33 | true
34 |
35 |
36 | true
37 | full
38 | false
39 | bin\Debug\
40 | DEBUG;TRACE
41 | prompt
42 | 4
43 | x86
44 |
45 |
46 | pdbonly
47 | true
48 | bin\Release\
49 | TRACE
50 | prompt
51 | 4
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | ResXFileCodeGenerator
73 | Resources.Designer.cs
74 | Designer
75 |
76 |
77 | True
78 | Resources.resx
79 | True
80 |
81 |
82 | SettingsSingleFileGenerator
83 | Settings.Designer.cs
84 |
85 |
86 | True
87 | Settings.settings
88 | True
89 |
90 |
91 |
92 |
93 | False
94 | .NET Framework 3.5 SP1 Client Profile
95 | false
96 |
97 |
98 | False
99 | .NET Framework 3.5 SP1
100 | true
101 |
102 |
103 |
104 |
111 |
--------------------------------------------------------------------------------
/UHWID/UHWIDEngine.cs:
--------------------------------------------------------------------------------
1 | namespace UHWID
2 | {
3 | public static class UHWIDEngine
4 | {
5 | public static string SimpleUid { get; private set; }
6 |
7 | public static string AdvancedUid { get; private set; }
8 |
9 | static UHWIDEngine()
10 | {
11 | var volumeSerial = DiskId.GetDiskId();
12 | var cpuId = CpuId.GetCpuId();
13 | var windowsId = WindowsId.GetWindowsId();
14 | SimpleUid = volumeSerial + cpuId;
15 | AdvancedUid = SimpleUid + windowsId;
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/UHWID/WindowsId.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Management;
3 | using System.Security.Cryptography;
4 | using System.Text;
5 |
6 | namespace UHWID
7 | {
8 | internal class WindowsId
9 | {
10 | public static string GetWindowsId()
11 | {
12 | var windowsInfo = "";
13 | var managClass = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem");
14 |
15 | var managCollec = managClass.Get();
16 |
17 | var is64Bits = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"));
18 |
19 | foreach (var o in managCollec)
20 | {
21 | var managObj = (ManagementObject) o;
22 | windowsInfo = managObj.Properties["Caption"].Value + Environment.UserName + (string) managObj.Properties["Version"].Value;
23 | break;
24 | }
25 | windowsInfo = windowsInfo.Replace(" ", "");
26 | windowsInfo = windowsInfo.Replace("Windows", "");
27 | windowsInfo = windowsInfo.Replace("windows", "");
28 | windowsInfo += (is64Bits) ? " 64bit" : " 32bit";
29 |
30 | //md5 hash of the windows version
31 | var md5Hasher = MD5.Create();
32 | var wi = md5Hasher.ComputeHash(Encoding.Default.GetBytes(windowsInfo));
33 | var wiHex = BitConverter.ToString(wi).Replace("-", "");
34 | return wiHex;
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/UHWID_&_Demo.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual C# Express 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UHWID", "UHWID\UHWID.csproj", "{5F4B5D3C-4558-4062-9A43-B8024139BF19}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo", "Demo\Demo.csproj", "{6DDB292C-8C45-44DB-9933-D50B03A67256}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {5F4B5D3C-4558-4062-9A43-B8024139BF19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {5F4B5D3C-4558-4062-9A43-B8024139BF19}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {5F4B5D3C-4558-4062-9A43-B8024139BF19}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {5F4B5D3C-4558-4062-9A43-B8024139BF19}.Release|Any CPU.Build.0 = Release|Any CPU
18 | {6DDB292C-8C45-44DB-9933-D50B03A67256}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {6DDB292C-8C45-44DB-9933-D50B03A67256}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {6DDB292C-8C45-44DB-9933-D50B03A67256}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {6DDB292C-8C45-44DB-9933-D50B03A67256}.Release|Any CPU.Build.0 = Release|Any CPU
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------