[Visual Basic] Fastest way to check if OS is Activated?

Discussion in 'Mixed Languages' started by TheGreyRaven, Jul 30, 2017.

  1. TheGreyRaven

    TheGreyRaven MDL Novice

    Jul 28, 2017
    13
    53
    0
    #1 TheGreyRaven, Jul 30, 2017
    Last edited: Jul 30, 2017
    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!
     
  2. Michaela Joy

    Michaela Joy MDL Crazy Lady

    Jul 26, 2012
    4,071
    4,651
    150
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Muerto

    Muerto MDL Debugger

    Mar 7, 2012
    1,858
    2,112
    60
    #3 Muerto, Sep 27, 2017
    Last edited: Jan 12, 2021
    ...
     
  4. MugiwaraDono

    MugiwaraDono MDL Novice

    Dec 1, 2017
    1
    0
    0
    I am surprised people are still coding in VB.net nowadays. You should do something like C# or Java.
     
  5. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    6,222
    22,280
    210

    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");