A test with the method used by Windows =>
(add a Button for the click)
Public Class Form1
Public Enum HRESULT As Integer
S_OK = 0
S_FALSE = 1
E_NOINTERFACE = &H80004002
E_NOTIMPL = &H80004001
E_FAIL = &H80004005
E_UNEXPECTED = &H8000FFFF
E_OUTOFMEMORY = &H8007000E
End Enum
<DllImport("Slc.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function SLOpen(ByRef phSLC As IntPtr) As HRESULT
End Function
<DllImport("Slc.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function SLClose(phSLC As IntPtr) As HRESULT
End Function
<DllImport("Slc.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function SLGetLicensingStatusInformation(hSLC As IntPtr, pAppID As IntPtr, pProductSkuId As IntPtr, pwszRightName As String,
ByRef pnStatusCount As UInteger, ByRef ppLicensingStatus As IntPtr) As HRESULT
End Function
<StructLayout(LayoutKind.Sequential)>
Public Structure SL_LICENSING_STATUS
Public SkuId As Guid ' SKU id
Public eStatus As SLLICENSINGSTATUS ' licensing status, see SLLICENSINGSTATUS
Public dwGraceTime As UInteger ' grace time In minute
Public dwTotalGraceDays As UInteger ' pre-defined grace days In license
Public hrReason As HRESULT ' the Error Of unlicensed status
Public qwValidityExpiration As UInt64 ' Validity expiration day
End Structure
Public Enum SLLICENSINGSTATUS
SL_LICENSING_STATUS_UNLICENSED
SL_LICENSING_STATUS_LICENSED
SL_LICENSING_STATUS_IN_GRACE_PERIOD
SL_LICENSING_STATUS_NOTIFICATION
SL_LICENSING_STATUS_LAST
End Enum
<DllImport("Slc.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Public Shared Function SLGetInstalledProductKeyIds(hSLC As IntPtr, ByRef pProductSkuId As Guid, ByRef pnProductKeyIds As UInteger, ByRef ppProductKeyIds As IntPtr) As HRESULT
End Function
Public WINDOWS_SLID As New Guid("55C92734-D682-4D71-983E-D6EC3F16059F")
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim hr As HRESULT = CheckWindowsActivation()
If (hr = HRESULT.S_OK) Then
MessageBox.Show("Windows is activated", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Windows is not activated", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Function CheckWindowsActivation() As HRESULT
Dim hSLC As IntPtr = IntPtr.Zero
Dim hr As HRESULT = SLOpen(hSLC)
If (hr = HRESULT.S_OK) Then
Dim nStatusCount As UInteger = 0
Dim pSL_LICENSING_STATUS As IntPtr = IntPtr.Zero
Dim pLastStatus As SL_LICENSING_STATUS = New SL_LICENSING_STATUS()
Dim pGuid As IntPtr = IntPtr.Zero
pGuid = Marshal.AllocHGlobal(Marshal.SizeOf(WINDOWS_SLID))
Marshal.StructureToPtr(WINDOWS_SLID, pGuid, False)
hr = SLGetLicensingStatusInformation(hSLC, pGuid, IntPtr.Zero, Nothing, nStatusCount, pSL_LICENSING_STATUS)
' hr = &HC004F015 SL_E_PRODUCT_SKU_NOT_INSTALLED
If (hr = HRESULT.S_OK) Then
Dim nStructSize As Integer = Marshal.SizeOf(GetType(SL_LICENSING_STATUS))
Dim lStatus(nStatusCount) As SL_LICENSING_STATUS
For i As Integer = 0 To nStatusCount - 1
lStatus(i) = Marshal.PtrToStructure(New IntPtr(pSL_LICENSING_STATUS.ToInt32() + (nStructSize * i)), GetType(SL_LICENSING_STATUS))
Dim nPKeyIds As UInteger = 0
Dim pPKeyIds As IntPtr = IntPtr.Zero
hr = SLGetInstalledProductKeyIds(hSLC, lStatus(i).SkuId, nPKeyIds, pPKeyIds)
If (hr = HRESULT.S_OK And nPKeyIds <> 0) Then
' {E0C42288-980C-4788-A014-C080D2E1926E} Windows 10 Education
pLastStatus = lStatus(i)
End If
Next
If (pLastStatus.eStatus = SLLICENSINGSTATUS.SL_LICENSING_STATUS_LICENSED) Then
hr = HRESULT.S_OK
Else
hr = HRESULT.S_FALSE
End If
End If
Marshal.FreeHGlobal(pGuid)
SLClose(hSLC)
End If
Return hr
End Function
End Class