[C] Checking license status

Discussion in 'Mixed Languages' started by Pr3acher, Nov 11, 2012.

  1. Pr3acher

    Pr3acher MDL Member

    Aug 24, 2012
    142
    48
    10
    Hi, i want to check the license status on Windows 8/7, i found a way but it's not very safe, i mean it could trigger errors.
    So anyone knows a way to retrieve the license status on Windows 87 ? Maybe using the registry ?
     
  2. woot332

    woot332 MDL Senior Member

    Feb 18, 2011
    390
    808
    10
    slc.dll

    SLIsWindowsGenuineLocal
    ptr to dword size buffer

    0= genuine
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Pr3acher

    Pr3acher MDL Member

    Aug 24, 2012
    142
    48
    10
    #3 Pr3acher, Nov 11, 2012
    Last edited: Nov 11, 2012
    (OP)
    Thanks, but can you give more details please? If "SLIsWindowsGenuineLocal" is a function, then i don't find it on the net or msdn.

    Edit: After deep search i found the function but i need an example or more details on it, but i'll try thanks...
     
  4. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,485
    1,321
    60
    #4 QuantumBug, Nov 11, 2012
    Last edited by a moderator: Apr 20, 2017
    What to see if the OS is activated?

    Code:
        Private Sub bgwls(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwls.DoWork
            Try
                Dim status As String
                status = String.Empty
                Dim objMgmt As System.Management.ManagementObject
                Dim LicenseStatus As New System.Management.ManagementObjectSearcher("root\CIMV2", "SELECT LicenseStatus FROM SoftwareLicensingProduct")
                For Each objMgmt In LicenseStatus.Get
                    If objMgmt("LicenseStatus") = "1" Then
                        status = "Licensed"
                        Exit For
                    Else
                        status = "Unlicensed"
                    End If
                Next
                e.Result = status
            Catch ex As Exception
                'Your error code
            End Try
        End Sub
        Private Sub bgwls_Completed(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgwls.RunWorkerCompleted
            Try
                status = e.Result
                Label1.Text = status
            Catch ex As Exception
                'Your error code
            End Try
        End Sub
    bgwls is simply a background worker. This can easily be converted.
     
  5. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,106
    120
    Just import the slc.dll from 'C:\Windows\System32' and call the function SLIsWindowsGenuineLocal() that's IntPtr and convert to DWORD in code.

    I've no extensive experience with C, but I participated in some projects on my life...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,803
    45,238
    150
    If you can call WMI from C I would go that route. I make heavy use of it in MTK.

    There is a lot more accessible, if you need more than the IsGenuineLocal.

    A lot of apps do WMI so it may be easier to look at any open source apps here that use it.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. Pr3acher

    Pr3acher MDL Member

    Aug 24, 2012
    142
    48
    10
    Thanks for all you replies CODY, Josh & The Dev, will have a look at all this when i'ill have time :)
     
  8. Smorgan

    Smorgan Glitcher

    Mar 25, 2010
    1,854
    1,034
    60
    I feel you guys have not fully explained what the slc part does.

    SLIsWindowsGenuineLocal

    This is just the Software Licensing Client (SLC). SPPCEXT.dll is the file which actually activates the copy of Windows regardless of the Version from Vista - Windows 8 last I checked. IF my memory serves me correctly Microsoft created a License checking tool which was called the Microsoft Genuine Diagnostic Tool which was released again I believe in response to WAT which went after the permissions on one of the spp files. I would start with that diagnostic tool instead of the Software Licensing Client file.

    http://download.microsoft.com/download/9/F/3/9F3DED28-A521-4352-B8A4-20368D0CC1AA/MGADiag.exe
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. Pr3acher

    Pr3acher MDL Member

    Aug 24, 2012
    142
    48
    10
    Yep thank you but i wanna implement this in my own project, in a program i'm writting
     
  10. woot332

    woot332 MDL Senior Member

    Feb 18, 2011
    390
    808
    10
    #10 woot332, Nov 12, 2012
    Last edited: Nov 12, 2012
    Windows 8 ships with it's own diagnostic tool Licensingdiag.exe, sure there's other apis
    available but SLIsWindowsGenuineLocal is simple to use and its invoked when you check activation
    status in control panel and also used by the metro ui.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,803
    45,238
    150
    Speaking of which, Windows 8 control panel can lag considerably. I can be activated and it take a reboot for it to accept it is activated, but WMI never lies/lags about the state, but WMI is more complex to check the license state than that function.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. Pr3acher

    Pr3acher MDL Member

    Aug 24, 2012
    142
    48
    10
    Well i looked for WMI and heard it was lagging, not fast comparing to API, + i didn't manage to use SLIsGenuineLocal() in C, C# syntax is very different from C one i think
     
  13. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,803
    45,238
    150
    By lag I mean you can be activated and the control panel says it isn't. It can take some time to load all license state using WMI, so SLIsGenuineLocal() is faster in terms of how long it takes.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,485
    1,321
    60
    #14 QuantumBug, Nov 12, 2012
    Last edited: Nov 12, 2012
    If you get stuck I can always whip up a project for you. Just let me know what language and IDE.

    Also, if you use WMI and code it correctly it will load instantly. People would usually put 'Select * From' when using WMI, that makes it cycle through everything in that instance instead of selecting what you want.
     
  15. Pr3acher

    Pr3acher MDL Member

    Aug 24, 2012
    142
    48
    10
    Well very nice from you The Dev, i'm using Visual Studio Ultimate with C (WinApi), and yes i'm somehow blocked since i can't use SLIsGenuineLocal(), so if you can do something, would appreciate thanks :)
     
  16. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
  17. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,485
    1,321
    60
    Oh, C++. Over my head dude. VB or C# for me. I can do either one of those.
     
  18. Pr3acher

    Pr3acher MDL Member

    Aug 24, 2012
    142
    48
    10
    Ok no problem. Anyway, i dont need it right now since i'm really busy by school, but i'll still have a look to WMI or other stuff, maybe this week-end
     
  19. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    419
    60
    you could also use cscript and start the slmgr.vbs process and take the output and use that data to your liking
     
  20. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,106
    120
    WMIC also, then manage the return code...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...