Hi! So I'm currently working on a tool called WinTool, I have ran into a problem. I am checking if Windows is activated using this code: Here is a GIF of it freezing when I load the form where I run the "check" code: gyazo.com/572aa9579cfc7d206fe9046ce12fe94b Code: Public Function WindowsStatus() As String Try Dim searcher As New ManagementObjectSearcher( "root\CIMV2", "SELECT * FROM SoftwareLicensingProduct WHERE LicenseStatus = 1") Dim myCollection As ManagementObjectCollection Dim myObject As ManagementObject myCollection = searcher.Get() If myCollection.Count = 0 Then Return ("Windows Is Not Activated") searcher.Dispose() Else For Each myObject In myCollection Return ("Windows Is Activated") searcher.Dispose() Next End If searcher.Dispose() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly) End Try End Function It does the job, but there is an issue and that is that the program freezes for a short while (like 1 or 2 seconds). Is there a faster way to check if Windows is activated without freezing? Note: I'm trying to learn VB.Net so feel free to leave reference to where you can find a solution to the problem so I can check them out! Thank you! EDIT: I solved it, I just made a splash screen and loaded all info into there!
Glad you got it sorted. I thought I'd post these anyway, just because there are some good thoughts there about checking for Windows activation. https://stackoverflow.com/questions/1552392/determine-genuine-windows-installation-in-c-sharp and https://stackoverflow.com/questions/18717389/detect-with-c-sharp-if-windows-os-has-invalid-license Hopefully, they will help.
Code: public bool IsLicensed(bool Licensed = false) { try { foreach (ManagementObject Obj in new ManagementObjectSearcher("root\\CIMV2", "SELECT LicenseStatus FROM SoftwareLicensingProduct WHERE LicenseStatus = 1").Get()) { Licensed = true; } } catch (ManagementException) { Licensed = false; } return Licensed; } Usage: Code: if(IsLicenced()) MessageBox.Show("Windows is Licensed");