0

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?

Mr-HaXx
  • 93
  • 1
  • 9
  • You can use the `SoftwareLicensingProduct` class from `WMI` to get the license status, grace period etc. But, why do you care - apps do not usually get involved with the OS license status. BTW, I am not sure why this is DVed - seems clear enough to me. – Ňɏssa Pøngjǣrdenlarp May 15 '15 at 22:35
  • I am writing a small piece of software for our interns to run a checklist on sysprep for laptops and desktops we build. This way i can check if they have done everything on the list as each action requires a push of a button. Like set wallpaper, change system informstion to contain our phone etc. All with a simple program. But the license seems to give me a genuine results on any machine, activated or not. Also i dont see the point of downvoting when i am clearly just asking a normal question. – Mr-HaXx May 16 '15 at 09:23
  • There is always the chance that you implemented that code wrong, so rather than a link, the actual code might have prevented it from being closed. I am not sure that is the right way to get the license status though: there is a difference between a Genuine install and the activation status of an install. – Ňɏssa Pøngjǣrdenlarp May 16 '15 at 10:56
  • i will post my code when i get home. Also, the activationstatus is what i am trying to get. – Mr-HaXx May 16 '15 at 13:30
  • I am not sure it matters at this point. The link is provides for an `IsGenuine()` test where you want something else. The answer you want is in my first comment. – Ňɏssa Pøngjǣrdenlarp May 16 '15 at 13:39

1 Answers1

2

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
Mr-HaXx
  • 93
  • 1
  • 9