Reputation: 93
I have been looking online for a solution to make my program check if my windows is activated or not.
The same way you can check your System Properties at the bottom, and it says xx days remaining, click here to activate. This way i know it's not activated.
The problem is i used the following code:
Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices
Imports SLID = System.Guid
Module Genuine_Check
Public Enum SL_GENUINE_STATE
SL_GEN_STATE_IS_GENUINE = 0
SL_GEN_STATE_INVALID_LICENSE = 1
SL_GEN_STATE_TAMPERED = 2
SL_GEN_STATE_LAST = 3
End Enum
<DllImportAttribute("Slwga.dll", EntryPoint:="SLIsGenuineLocal", CharSet:=CharSet.None, ExactSpelling:=False, SetLastError:=False, PreserveSig:=True, CallingConvention:=CallingConvention.Winapi, _
BestFitMapping:=False, ThrowOnUnmappableChar:=False)> _
<PreserveSigAttribute()> _
Friend Function SLIsGenuineLocal(ByRef slid As SLID, <[In](), Out()> ByRef genuineState As SL_GENUINE_STATE, ByVal val3 As IntPtr) As UInteger
End Function
Public Function IsGenuineWindows() As Boolean
Dim _IsGenuineWindows As Boolean = False
Dim ApplicationID As New Guid("55c92734-d682-4d71-983e-d6ec3f16059f")
'Application ID GUID http://technet.microsoft.com/en-us/library/dd772270.aspx
Dim windowsSlid As SLID = CType(ApplicationID, Guid)
Try
Dim genuineState As SL_GENUINE_STATE = SL_GENUINE_STATE.SL_GEN_STATE_LAST
Dim ResultInt As UInteger = SLIsGenuineLocal(windowsSlid, genuineState, IntPtr.Zero)
If ResultInt = 0 Then
_IsGenuineWindows = (genuineState = SL_GENUINE_STATE.SL_GEN_STATE_IS_GENUINE)
Else
MsgBox("Error getting information {0}", ResultInt.ToString())
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return _IsGenuineWindows
End Function
Public Function CheckGenuine()
If Environment.OSVersion.Version.Major >= 6 Then
'Version 6 can be Windows Vista, Windows Server 2008, or Windows 7
If IsGenuineWindows() Then
MsgBox("Original Windows")
Form1.Button8.BackColor = Color.LawnGreen
Else
MsgBox("Not Original Windows")
Form1.Button8.BackColor = Color.Red
End If
Else
MsgBox("OS Not supported")
End If
End Function
End Module
Then i run the following:
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Try
CheckGenuine()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
End Try
But this shows me the message: 'Original Windows' on both a system with key and activated a clean install without a key installed.
So my question is not to see if my windows is Original, but if it still needs to be activated.
Is there someway to get this done? Or any tips on how to make this work?
Upvotes: 0
Views: 2029
Reputation: 93
I managed to fix the problem, with a completely different solution, as stated above, i was looking at the wrong solutions and code.
Below is the solution if anybody is interested.
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
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
MsgBox("Windows is not activated")
Button8.BackColor = Color.Red
searcher.Dispose()
Else
For Each myObject In myCollection
MsgBox("Windows is activated")
Button8.BackColor = Color.LawnGreen
searcher.Dispose()
Next
End If
searcher.Dispose()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
End Try
Upvotes: 2